Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests #833

Open
joanhey opened this issue Oct 20, 2022 · 8 comments
Open

Add tests #833

joanhey opened this issue Oct 20, 2022 · 8 comments

Comments

@joanhey
Copy link
Contributor

joanhey commented Oct 20, 2022

Hi Walkor,

If we have tests, will be faster to develop.

Unit tests

Will be very beneficial but a lot of work, with the release versions (3, 4, 5).

Functional and E2E tests

Will be easier and faster. Not necessarily with PHP.
And will work with all the versions.
We can chose a system, to all align in the efforts.

PHP static analysers

This is really fast to use it.
We don't have test, but the static code analysers can help a lot with the code.
(phpstan, psalm, ...)

And all installed with Github actions.

Talk later !

@joanhey joanhey changed the title Add test Add tests Oct 20, 2022
@walkor
Copy link
Owner

walkor commented Oct 21, 2022

Adding tests to workerman is what I have always wanted to do. But I don't have much experience in tests It would be great if you could send a PR and provide a sample template.

@joanhey
Copy link
Contributor Author

joanhey commented Nov 16, 2022

In the TechEmpower benchmark, I'm using the master branch.
And if appear a fail or a performance regresion, I'll inform you. Every 6 days finish a run.

Now tested with PHP 8.2 RC5, without any problem.
TechEmpower/FrameworkBenchmarks#7704
image

@joanhey
Copy link
Contributor Author

joanhey commented Nov 16, 2022

Webman also working with PHP 8.2 RC5
image
I think that Webman, would show the version too.

@joanhey
Copy link
Contributor Author

joanhey commented Nov 16, 2022

After thinking about which E2E test system to use.
We can do it easily with Workerman.

So I started an sketch code for create it, with the same style as Postman, Insomnia, ...
When I have more code I'll send the repo for help.

@walkor
Copy link
Owner

walkor commented Nov 17, 2022

Many thanks.

@joanhey joanhey mentioned this issue Apr 15, 2023
@joanhey
Copy link
Contributor Author

joanhey commented Apr 15, 2023

Yes, we need tests. And I really like to use Pest.

But we don't need too many unit tests, only for some classes.
Because unit tests are tied to code and classes. And with any refactor, than it will be more, we need to change the unit tests.
Webman really need a lot of unit tests, but not Workerman.

We need more URGENT to have functional tests.

It's better to test the behavior than the code in Workerman.
So we can test any version, without touch the tests. And refactor the code freely.
Also they can be used in other projects: Adapterman, Amp, ReactPHP, ... that will feedback with more tests.

Apache and Nginx use functional tests

Apache:

Nginx:

Also Ngx-php use the functional test from Nginx: https://github.com/rryqszq4/ngx-php/blob/master/t/001-hello.t

Both use perl, because are veterans projects, and at that time is what they have at hand.

PHP use functional tests

A better example, is the same PHP.

We need an slight modified .phpt tests. And try to be language agnostic.
They are easier to create, than unit test. They don't need to know the code or the test system. And more people will help creating tests.
And will be in the same GIT repo.

And I think more in have an echo server in some parts, like in https://httpbin.org

Other options

We can start fast and use ready made solutions, but they have disadvantages too.

Thunder Client
https://www.thunderclient.com/
Easy, with GUI, anybody can create and test in the same Vscode. Can import collections from Postman, Insomnia, ...
With an easy tests system and can save the files in GIT too.

Negative:

  • Use json files, and with a lot of tests, are very large
  • Difficult to manage commit changes with these large json
  • We need another languaje: js and nodejs.

Rest client
https://marketplace.visualstudio.com/items?itemName=humao.rest-client

Easy to create, and with autocomplete in IDEs of .rest and .http files (both have RFCs)
image

Very good way, perhaps better than .phpt for Workeman. Also separated in dirs and easy to review changes in commits.
And I did some preliminary tests, and we can mix .rest with .phpt. We can use .rest files with --EXPECT--, --EXPECTHEADERS--, ...

Negative:

  • Don't have tests

What is better to use?
Any feedback is welcome.

Link to PR #904

@joanhey
Copy link
Contributor Author

joanhey commented Jul 4, 2023

I'm creating an HTTP protocol test in Adapterman, to be added later to Workerman.

But as the tests can be used also with: swoole, amp, reatchphp, ngx-php, .... and also symfony HTTP kernel and variants. It'll be a nightmare to synchronize in 2, 3 or n different repositories.

So I'll try to move the test to a repo, and it can be run locally or in GH actions only including it in composer. And we can receive feedback PRs from the others.

Locally I have +500 assertions, and working with Adapterman, Workerman, Php cli server and Nginx for now.
And testing in the Adapterman GH workflow with Adapterman and Workerman 4.1. The fail is not in Workerman, I'm polishing the tests. When we tests more than one app server, we can have better tests.

image

When it's ready the new tests repo, I'll add to Workerman in local and GH actions to be tested with all event loops.
In the meantime adding fixes to Workerman when necessary.
And later, try to help with adding tests for other protocols.

Anybody is invited to help with these tests sending PRs !! https://github.com/joanhey/AdapterMan/tree/master/tests

PD: the first gain is that we can make fast changes to the HTTP protocol and underlying architecture without errors

@joanhey
Copy link
Contributor Author

joanhey commented Jul 4, 2023

I'll try to make it agnostic of the Http-client.
But I want to try the Workerman client, to try not Http protocols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants