You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2022/07/07 07:44:14 UTC

[GitHub] [bookkeeper] nicoloboschi commented on a diff in pull request #3392: Useing Awaitility for asynchroneous testing.

nicoloboschi commented on code in PR #3392:
URL: https://github.com/apache/bookkeeper/pull/3392#discussion_r915562366


##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieZKExpireTest.java:
##########
@@ -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();
             sendthread.resume();
 
             // allow watcher thread to run
-            Thread.sleep(3000);
+            await().atMost(3, TimeUnit.SECONDS).await();

Review Comment:
   ```
   await().atMost(5, SECONDS).until(() -> server.isBookieRunning() && server.isRunning())
   ```



##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieZKExpireTest.java:
##########
@@ -76,7 +78,7 @@ conf, new TestBookieImpl(conf),
 
             int secondsToWait = 5;
             while (!server.isRunning()) {
-                Thread.sleep(1000);
+                await().atMost(1000, TimeUnit.MILLISECONDS);

Review Comment:
   this loop should become
   
   ```
   await().atMost(5, SECONDS).until(() -> server.isRunning())
   ```
   



##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookieZKExpireTest.java:
##########
@@ -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();

Review Comment:
   we can leave the sleep here, we are not waiting for a particular condition



##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AutoRecoveryMainTest.java:
##########
@@ -146,20 +132,15 @@ public void testAutoRecoverySessionLoss() throws Exception {
          * wait for some time for all the components of AR1 and AR2 are
          * shutdown.
          */
-        for (int i = 0; i < 10; i++) {
-            if (!main1.auditorElector.isRunning() && !main1.replicationWorker.isRunning()
-                    && !main1.isAutoRecoveryRunning() && !main2.auditorElector.isRunning()
-                    && !main2.replicationWorker.isRunning() && !main2.isAutoRecoveryRunning()) {
-                break;
-            }
-            Thread.sleep(1000);
-        }
+        await().atMost(20, SECONDS).until(()->!main1.auditorElector.isRunning() && !main1.replicationWorker.isRunning()

Review Comment:
   better to keep the same timeout (10 seconds)



##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/AutoRecoveryMainTest.java:
##########
@@ -98,19 +96,7 @@ public void testAutoRecoverySessionLoss() throws Exception {
          */
         ZKMetadataClientDriver zkMetadataClientDriver1 = startAutoRecoveryMain(main1);
         ZooKeeper zk1 = zkMetadataClientDriver1.getZk();
-
-        // Wait until auditor gets elected
-        for (int i = 0; i < 10; i++) {
-            try {
-                if (main1.auditorElector.getCurrentAuditor() != null) {
-                    break;
-                } else {
-                    Thread.sleep(1000);
-                }
-            } catch (IOException e) {
-                Thread.sleep(1000);
-            }
-        }
+        await().atMost(20, SECONDS).until(() -> main1.auditorElector.getAuditor() != null);

Review Comment:
   better to keep the same timeout (10 seconds)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org