echonesis commented on code in PR #10680:
URL: https://github.com/apache/ozone/pull/10680#discussion_r3534445954


##########
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/lock/TestOzoneManagerLock.java:
##########
@@ -453,24 +452,34 @@ void testMultiLockResourceParallel() throws Exception {
     lock.acquireMultiUserLock("user2", "user1");
 
     AtomicBoolean gotLock = new AtomicBoolean(false);
-    new Thread(() -> {
+    Thread thread = new Thread(() -> {
       lock.acquireMultiUserLock("user1", "user2");
       gotLock.set(true);
       lock.releaseMultiUserLock("user1", "user2");
-    }).start();
-    // Let's give some time for the new thread to run
-    Thread.sleep(100);
+    });
+    thread.start();
+    waitForBlockedThread(thread);
     // Since the new thread is trying to get lock on same resource, it will
     // wait.
     assertFalse(gotLock.get());
     lock.releaseMultiUserLock("user2", "user1");
     // Since we have released the lock, the new thread should have the lock
     // now.
-    // Let's give some time for the new thread to run
-    Thread.sleep(100);
+    waitForThread(thread);
     assertTrue(gotLock.get());
   }
 
+  private static void waitForBlockedThread(Thread thread) throws Exception {
+    GenericTestUtils.waitFor(() -> thread.getState() == Thread.State.BLOCKED ||
+        thread.getState() == Thread.State.WAITING ||
+        thread.getState() == Thread.State.TIMED_WAITING, 10, 10000);
+  }
+
+  private static void waitForThread(Thread thread) throws InterruptedException 
{
+    thread.join(TimeUnit.SECONDS.toMillis(10));
+    assertFalse(thread.isAlive(), "Timed out waiting for lock thread to 
finish");

Review Comment:
   Good point.
   I agree the current name is vague. 
   I’ll rename it to `waitForThreadToFinish` so it is clear that the helper 
waits for the worker thread to complete.
   What do you think?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to