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

Fix test and trace log message #5645

Merged
merged 2 commits into from Jan 16, 2018
Merged

Conversation

karesti
Copy link
Contributor

@karesti karesti commented Dec 15, 2017

@@ -90,13 +90,15 @@ public void testFastLockWithTimeout() throws Throwable {
public void testTryLockWithTimeoutAfterLockWithSmallTimeout() throws Throwable {
assertTrue(await(lock.tryLock()));
CompletableFuture<Boolean> tryLock = lock.tryLock(1, TimeUnit.NANOSECONDS);
TimeUnit.NANOSECONDS.sleep(1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion was to do assertFalse(await(tryLock)); first and await(lock.unlock()); later, without other delays.

Copy link
Contributor Author

@karesti karesti Dec 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But is that case I'm not testing the fact that as the unlock arrives later (without waiting) the request is already done and expired.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the confusion comes becauseI should test isCompleted() true, because it should be completed after 1 nano second and await should not be needed. WDYT ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tryLock() needs a remote call, we can't say exactly how much it will take. In a best case scenario, assuming no big GC pauses, we could wait for only 100ms for tryLock to finish. But we cannot assume that it will finish synchronously.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is happening locally, not remotely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expire the CompletableFuture in the local ClusteredLockImpl after the timeout

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave the example of a remote call because the difference is bigger there, but even locally a thread can easily be taken off the CPU for 10ms: maybe it's blocking to log something (very common with trace logging enabled), maybe a GC has started, or maybe there are just not enough CPU cores for all the test threads that are running at the same time.

IMO we cannot make any assumptions about timings at this resolution, even a sleep(100) is just a recipe for random failures. If you want to check how much tryLock blocked for, you can still do that, but I'd use a margin of at least 500ms. And since a test shouldn't always sleep for 500ms, you should first check that tryLock() failed, then check the time it took, and then unlock the lock (in a finally block).

@galderz
Copy link
Member

galderz commented Jan 12, 2018

Needs rebase

@karesti
Copy link
Contributor Author

karesti commented Jan 12, 2018

@danberindei there are test failures but nothing related I think

@tristantarrant tristantarrant merged commit 4cb6eee into infinispan:master Jan 16, 2018
@tristantarrant
Copy link
Member

Merged, thanks

@danberindei
Copy link
Member

Thanks Tristan ;)

@karesti
Copy link
Contributor Author

karesti commented Jan 16, 2018

@danberindei if you fell guilty, you can merge the other one ! :)

@karesti karesti deleted the ISPN-8581 branch February 6, 2019 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants