system-rules icon indicating copy to clipboard operation
system-rules copied to clipboard

ExpectedSystemExit doesn't work in multi-threading environment

Open akryvtsun opened this issue 9 years ago • 6 comments
trafficstars

In integration testing if a test is executed on the one thread but System.exit(...) is called on another ExpectedSystemExit work unstable. If the test is finished faster then another thread calls System.exit(...) then current ExpectedSystemExit implementation fails the test.

The solution is to delay the test thread till System.exit(...) is called or time out time is finished. It's possible to use java.util.concurrent.CountDownLatch for this but I couldn't find ability to do the latch count down somewhere in NoExitSecurityManager.

P.S. if ExpectedSystemExit work as a Rule in multi-threading environment isn't break any JUnit conventions I can prepare pull request for the fix.

akryvtsun avatar Aug 18 '16 18:08 akryvtsun

@stefanbirkner FYI: I've implemented needed functionality in my code using your ProvideSecurityManager and my custom thread-friendly analog of your internal NoExitSecurityManager class.

akryvtsun avatar Aug 19 '16 17:08 akryvtsun

Could you provide a pull request that fixes the issue? That would be very helpful.

stefanbirkner avatar Sep 01 '16 21:09 stefanbirkner

@stefanbirkner thank you for interest. I'll provide PR.

akryvtsun avatar Sep 06 '16 12:09 akryvtsun

@stefanbirkner pls, review provided PR with the fix https://github.com/stefanbirkner/system-rules/pull/46 All tests are green but some firebug check was failed and I can't clearly understand what exactly.

akryvtsun avatar Sep 29 '16 21:09 akryvtsun

Thanks for the pull request. I cannot review it the next two weeks, but I review it afterwards.

stefanbirkner avatar Sep 30 '16 11:09 stefanbirkner

@stefanbirkner NP. let me know if you will have some notes, remarks etc.

akryvtsun avatar Sep 30 '16 12:09 akryvtsun