donatj / mock-webserver

Simple mock web server in PHP for unit testing.
MIT License
131 stars 21 forks source link

Reduce sleep to make tests more fast #30

Closed vitormattos closed 3 years ago

vitormattos commented 3 years ago

I used microseconds to enable testing at shorter intervals. On the first run there is no sleep. In the second run, sleep is half a second. Repetitions are made for 1 and a half seconds.

donatj commented 3 years ago

You can see from the failed integration tests that isRunning doesn't mean it's ready to accept incoming connections, just that the process id exists.

isRunning will return true at any point after the call to exec on line 79 unless the server otherwise crashes.

Being able to tell when the server is actually able to accept connections is a bigger ask.

I'd love to see a reduction in the time, but it would require a larger more systemic change.

vitormattos commented 3 years ago

Sorry for not checking the continuous integration output, I only tested it on the application I'm using your package.

I added a health check.

With this new approach sleep can even be removed or further reduced and keep the health check in a loop for 1 second. What do you think?

donatj commented 3 years ago

I pushed to your branch what I think is probably a simpler solution. Thoughts?

donatj commented 3 years ago

@vitormattos I just want to say thank you for this!

I just tried it on a big project I personally use mock-webserver on and it knocked phpunit from ~15 seconds down to 1.75 total, so that's a pretty decent win.

donatj commented 3 years ago

This has been tagged in release v2.3.0

vitormattos commented 3 years ago

This is the power of FLOSS projects!