amphp / phpunit-util

Helper package to ease testing with PHPUnit.
MIT License
21 stars 8 forks source link

Loop runs forever #12

Closed prolic closed 3 years ago

prolic commented 4 years ago

I have a TCP connection running in the event loop. This TCP connection has always something to do, like handling heart beats. I need to explicitly close the connection, otherwise the loop will run forever and never stop.

I used wait(call(...)) before and there wasn't this problem. Using phpunit-util, I need to close the connection manually and add that line of code more than 400 test cases. Is there a way around this that can be incorporated into this lib?

trowski commented 4 years ago

A combination of TestCase::setup() and TestCase::tearDown() can probably solve your issues without having to modify every test.

prolic commented 4 years ago

I tried that, but tearDown() never gets called, because the test hangs in the test-method itself, because the loop won't stop running.

prolic commented 4 years ago

Well, if there is nothing that can be done about it, I think I need to go and change a couple hundred of tests. Thanks anyway! You helped me again.

trowski commented 4 years ago

Hmm… yes, I didn't think about tearDown() not being reached.

An afterResolve() method could be added that is executed after the returned promise is resolved but before the loop exits.

kelunik commented 4 years ago

I guess the proper solution is to unreference the connection as long as it's idle, only doing heartbeats.

prolic commented 4 years ago

Should I reference back again when a new operation is executed and unreference as soon as the operation is done?

On Wed, Feb 19, 2020, 16:55 Niklas Keller notifications@github.com wrote:

I guess the proper solution is to unreference the connection as long as it's idle, only doing heartbeats.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/amphp/phpunit-util/issues/12?email_source=notifications&email_token=AADAJPE5MLVLEGT4RXPETWLRDWFCLA5CNFSM4KX5R22KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEMJIW7I#issuecomment-588417917, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADAJPBRMEMQKGWZQ4S347LRDWFCLANCNFSM4KX5R22A .

kelunik commented 4 years ago

Yup.

prolic commented 4 years ago

Thanks, I'll give a try.