-
Notifications
You must be signed in to change notification settings - Fork 902
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
Useing Awaitility for asynchroneous testing. #3392
base: master
Are you sure you want to change the base?
Conversation
@@ -76,7 +78,7 @@ conf, new TestBookieImpl(conf), | |||
|
|||
int secondsToWait = 5; | |||
while (!server.isRunning()) { | |||
Thread.sleep(1000); | |||
await().atMost(1000, TimeUnit.MILLISECONDS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this loop should become
await().atMost(5, SECONDS).until(() -> server.isRunning())
@@ -95,11 +97,11 @@ conf, new TestBookieImpl(conf), | |||
assertNotNull("Send thread not found", sendthread); | |||
|
|||
sendthread.suspend(); | |||
Thread.sleep(2 * conf.getZkTimeout()); | |||
await().atMost(2L * conf.getZkTimeout(), TimeUnit.MILLISECONDS).await(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can leave the sleep here, we are not waiting for a particular condition
sendthread.resume(); | ||
|
||
// allow watcher thread to run | ||
Thread.sleep(3000); | ||
await().atMost(3, TimeUnit.SECONDS).await(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await().atMost(5, SECONDS).until(() -> server.isBookieRunning() && server.isRunning())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx,done
} | ||
Thread.sleep(1000); | ||
} | ||
await().atMost(20, SECONDS).until(()->!main1.auditorElector.isRunning() && !main1.replicationWorker.isRunning() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to keep the same timeout (10 seconds)
Thread.sleep(1000); | ||
} | ||
} | ||
await().atMost(20, SECONDS).until(() -> main1.auditorElector.getAuditor() != null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to keep the same timeout (10 seconds)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks,updated
main.auditorElector.isRunning()); | ||
assertTrue("Replication worker should be running", | ||
main.replicationWorker.isRunning()); | ||
await().atMost(1, SECONDS).untilAsserted(() -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the atMost logic and use the default most await time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default await time is 10s
assertTrue("Replication worker should be running", | ||
main.replicationWorker.isRunning()); | ||
|
||
await().atMost(1, SECONDS).untilAsserted(()-> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
sendthread.resume(); | ||
|
||
// allow watcher thread to run | ||
Thread.sleep(3000); | ||
await().atMost(3, TimeUnit.SECONDS).await(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@CalvinKirs Hi, could you please rebase this PR. Also I think there is a typo in your PR title. |
This branch has conflicts that must be resolved |
ping @CalvinKirs, do you have time to resolve the above comments? |
Hi, I think I've resolved what the comments said, what else do I need to do? Except for dealing with conflicts. |
Thread.sleep(1000); | ||
} | ||
} | ||
await().until(() -> main1.auditorElector.getAuditor() != null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it's different than before? looks like the getCurrentAuditor()
is different than getAuditor()
sendthread.suspend(); | ||
Thread.sleep(2 * conf.getZkTimeout()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is part of the testing. It wants to resume the send thread after 2* zkTimeout to test the bookie should still working even if the zk session is timeout.
fix old workflow,please see #3455 for detail |
@CalvinKirs Hi, thanks for your contribution, I want to move forward this PR. Could you please help rebase the code? :) |
Descriptions of the changes in this PR:
Using Thread.sleep in a test is just generally a bad idea. It creates brittle tests that can fail unpredictably depending on environment ("Passes on my machine!") or load. So I used Awaitility for asynchroneous testing.
Such as:
https://github.com/apache/bookkeeper/runs/7219059790?check_suite_focus=true
https://github.com/apache/bookkeeper/runs/7206535584?check_suite_focus=true
(He may not be a perfect guarantee, but it can improve the stability ratio.)
Motivation
Using
Thread.sleep
in a test is generally a bad idea. It creates brittle tests that can fail unpredictably depending on the environment ("Passes on my machine!") or loadChanges
Useing
Awaitility
for asynchronous testing.Useing
Awaitility
testAutoRecoveryMainTest
Useing
Awaitility
testBookieZKExpireTest