TestCases and forked processes in TestResource don't play well

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

TestCases and forked processes in TestResource don't play well

Erik Stel
Hi,

I'm developing a web application using (amongst others) WebSockets. To
prevent test methods from becoming too big and slow I created a TestCase
with a TestResource containing my web application instance. After the first
test method is run, the WebSocket is closed unexpectedly and automagically.
It turns out that all forked processes are terminated when a TestCase has
executed a test method. What would be the proper way to prevent these forked
processes from terminating after a single test method? Or am I missing
something/doing something wrong?

TestExecutionEnvironment>>#checkForkedProcesses is responsible for
terminating any (non failed) processes. It is executed after
TestExecutionEnvironment>>#runTestCaseSafelly: [sic: this should be
#runTestCaseSafely:]. A possible solution might be to check whether the
Context in which a forked process was created has the #setUp method of a
TestResource of the TestCase (you still with me ;-) in its Context chain. If
that is the case, the process is probably forked for a reason. This forked
process does have to be terminated when all TestCases have finished of
course (when the TestResource does #tearDown).

IFF the forked processes should be kept alive during the execution of all
TestCase methods, does the suggested solution above seem logical or are
there any (better) alternatives?

Regards,
Erik



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply | Threaded
Open this post in threaded view
|

Re: TestCases and forked processes in TestResource don't play well

Denis Kudriashov
Hi Eric.

You can override #runCaseManaged on your test case:
MyTestCase>>runCaseManaged
   self runCase
It will disable all clever logic.

ср, 12 июн. 2019 г. в 20:55, Erik Stel <[hidden email]>:
Hi,

I'm developing a web application using (amongst others) WebSockets. To
prevent test methods from becoming too big and slow I created a TestCase
with a TestResource containing my web application instance. After the first
test method is run, the WebSocket is closed unexpectedly and automagically.
It turns out that all forked processes are terminated when a TestCase has
executed a test method. What would be the proper way to prevent these forked
processes from terminating after a single test method? Or am I missing
something/doing something wrong?

TestExecutionEnvironment>>#checkForkedProcesses is responsible for
terminating any (non failed) processes. It is executed after
TestExecutionEnvironment>>#runTestCaseSafelly: [sic: this should be
#runTestCaseSafely:]. A possible solution might be to check whether the
Context in which a forked process was created has the #setUp method of a
TestResource of the TestCase (you still with me ;-) in its Context chain. If
that is the case, the process is probably forked for a reason. This forked
process does have to be terminated when all TestCases have finished of
course (when the TestResource does #tearDown).

IFF the forked processes should be kept alive during the execution of all
TestCase methods, does the suggested solution above seem logical or are
there any (better) alternatives?

Regards,
Erik



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply | Threaded
Open this post in threaded view
|

Re: TestCases and forked processes in TestResource don't play well

Denis Kudriashov
I think proper fix for this logic would be to disable test environment during startup of resources

ср, 12 июн. 2019 г. в 21:11, Denis Kudriashov <[hidden email]>:
Hi Eric.

You can override #runCaseManaged on your test case:
MyTestCase>>runCaseManaged
   self runCase
It will disable all clever logic.

ср, 12 июн. 2019 г. в 20:55, Erik Stel <[hidden email]>:
Hi,

I'm developing a web application using (amongst others) WebSockets. To
prevent test methods from becoming too big and slow I created a TestCase
with a TestResource containing my web application instance. After the first
test method is run, the WebSocket is closed unexpectedly and automagically.
It turns out that all forked processes are terminated when a TestCase has
executed a test method. What would be the proper way to prevent these forked
processes from terminating after a single test method? Or am I missing
something/doing something wrong?

TestExecutionEnvironment>>#checkForkedProcesses is responsible for
terminating any (non failed) processes. It is executed after
TestExecutionEnvironment>>#runTestCaseSafelly: [sic: this should be
#runTestCaseSafely:]. A possible solution might be to check whether the
Context in which a forked process was created has the #setUp method of a
TestResource of the TestCase (you still with me ;-) in its Context chain. If
that is the case, the process is probably forked for a reason. This forked
process does have to be terminated when all TestCases have finished of
course (when the TestResource does #tearDown).

IFF the forked processes should be kept alive during the execution of all
TestCase methods, does the suggested solution above seem logical or are
there any (better) alternatives?

Regards,
Erik



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply | Threaded
Open this post in threaded view
|

Re: TestCases and forked processes in TestResource don't play well

Erik Stel
Hi Denis,

Thanks for the fast response.

When you say proper fix, do you mean a general fix for all TestResources or
do you mean the fix for my situation?

I can't oversee (yet) what the effect will be of halt/debug code inside the
web application (TestResource) which is the subject of the TestCase.
Normally this gets caught and handled specifically. And proper termination
of those forked processes from the TestResource will need to be handled
specifically (similar to the TestExecutionEnvironment :-) in the resource
#tearDown. Will try it out.

Cheers,
Erik



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Reply | Threaded
Open this post in threaded view
|

Re: TestCases and forked processes in TestResource don't play well

Denis Kudriashov
Hi Eric

чт, 13 июн. 2019 г., 20:31 Erik Stel <[hidden email]>:
Hi Denis,

Thanks for the fast response.

When you say proper fix, do you mean a general fix for all TestResources or
do you mean the fix for my situation?

I mean a general fix for test resources.


I can't oversee (yet) what the effect will be of halt/debug code inside the
web application (TestResource) which is the subject of the TestCase.
Normally this gets caught and handled specifically. And proper termination
of those forked processes from the TestResource will need to be handled
specifically (similar to the TestExecutionEnvironment :-) in the resource
#tearDown. Will try it out.

Cheers,
Erik



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html