Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LockAssert.makeAllAssertsPass(true) can start more than one test lock #1640

Closed
fabianlinz opened this issue Dec 7, 2023 · 1 comment
Closed

Comments

@fabianlinz
Copy link
Contributor

When migrating to the latest version, we noticed (in addition to #1635) that since 5.7.0 multiple calls to LockAssert.TestHelper.makeAllAssertsPass(true) result in multiple test locks (net.javacrumbs.shedlock.core.test-lock).

In previous version one call to LockAssert.TestHelper.makeAllAssertsPass(false) was sufficient to reset the behaviour for the test configuration. Now a LockAssert.TestHelper.makeAllAssertsPass(false) is required for each LockAssert.TestHelper.makeAllAssertsPass(true).

While this can easily be solved in tests by e.g. using a try.. finally or a @BeforeEach + @AfterEach the old behaviour is preferable from our point of view (or alternatively a reset method that clears the ThreadLocal in LockAssert) .

Expected behavior

LockAssert.TestHelper.makeAllAssertsPass(true);
LockAssert.TestHelper.makeAllAssertsPass(true);

LockAssert.TestHelper.makeAllAssertsPass(false);

assertThatThrownBy(LockAssert::assertLocked).isInstanceOf(IllegalStateException.class);

Actual behavior

LockAssert.TestHelper.makeAllAssertsPass(true);
LockAssert.TestHelper.makeAllAssertsPass(true);

LockAssert.TestHelper.makeAllAssertsPass(false);
LockAssert.assertLocked(); // although makeAllAssertsPass was set to false the assertion still passes

LockAssert.TestHelper.makeAllAssertsPass(false); // only if makeAllAssertsPass is called with false for each previous call with true the assertion fails
assertThatThrownBy(LockAssert::assertLocked).isInstanceOf(IllegalStateException.class);
fabianlinz added a commit to fabianlinz/ShedLock that referenced this issue Dec 7, 2023
fabianlinz added a commit to fabianlinz/ShedLock that referenced this issue Dec 7, 2023
lukas-krecan added a commit that referenced this issue Dec 7, 2023
#1640 Fix LockAssert.makeAllAssertsPass(true) to not start more than once
@fabianlinz
Copy link
Contributor Author

Fixed with 5.10.2. Thanks for the quick release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant