RFR: 8268428: Test java/foreign/TestResourceScope.java fails: expected [M] but found [N]

Daniel Fuchs dfuchs at openjdk.java.net
Wed Jun 9 11:03:12 UTC 2021


On Wed, 9 Jun 2021 10:33:34 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This tests fails intermittently but very rarely, on Windows it seems. The subtest in question is `testLockSharedMultiThread`. This test is spawning a number of threads, each of which:
> 
> * increments a counter atomically
> * acquire scope
> * waits some time
> * release scope
> * decrement counter (in finally block)
> 
> The main test thread tries (while the counter value is > 0) to repeatedly close the scope, and asserts that if the scope closes successfully, then the counter value should be exactly zero.
> 
> Looking at the test closely, I realized there's an issue: the order in which counter is incremented and scope is acquired is wrong. As such it is possible for counter to be increased, but then for subsequent acquire to fail (e.g. if segment is already closed). This would lead to the main test thread to fail, as it would appear as if the segment has been closed successfully, but the counter value is not zero.
> 
> The fix is to only increment the counter after a successful acquire. I have also tweaked the test so that it keeps trying closing the scope, even if the counter value reaches zero permanently (e.g. all other threads have completed).

I agree with the analysis and test code changes. Trivially you should also update the copyright years on this file.

-------------

Marked as reviewed by dfuchs (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/4427


More information about the core-libs-dev mailing list