workerman icon indicating copy to clipboard operation
workerman copied to clipboard

Add tests

Open joanhey opened this issue 1 year ago • 8 comments

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 avatar Oct 20 '22 14:10 joanhey

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.

walkor avatar Oct 21 '22 01:10 walkor

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. https://github.com/TechEmpower/FrameworkBenchmarks/pull/7704 image

joanhey avatar Nov 16 '22 13:11 joanhey

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

joanhey avatar Nov 16 '22 15:11 joanhey

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.

joanhey avatar Nov 16 '22 16:11 joanhey

Many thanks.

walkor avatar Nov 17 '22 03:11 walkor

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:

  • https://github.com/apache/httpd-tests
  • https://metacpan.org/pod/Apache::TestRequest

Nginx:

  • https://github.com/nginx/nginx-tests
  • https://metacpan.org/pod/Nginx::Test

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.

  • https://www.phpinternalsbook.com/tests/overview.html
  • https://qa.php.net/write-test.php
  • https://qa.php.net/phpt_details.php
  • https://github.com/php/php-src/tree/master/tests

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 avatar Apr 15 '23 21:04 joanhey

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 avatar Jul 04 '23 12:07 joanhey

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

joanhey avatar Jul 04 '23 15:07 joanhey