Skip to content

Commit

Permalink
[Flaky test] Wait for deadlocked status to clear before continuing (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
lhotari authored Apr 22, 2022
1 parent 2e5309c commit 5795a56
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.common.collect.Sets;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Phaser;
import java.util.concurrent.locks.Lock;
Expand All @@ -44,6 +45,8 @@
@Slf4j
public class AdminApiHealthCheckTest extends MockedPulsarServiceBaseTest {

private final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

@BeforeMethod
@Override
public void setup() throws Exception {
Expand Down Expand Up @@ -135,6 +138,9 @@ public void testHealthCheckupDetectsDeadlock() throws Exception {
thread2.interrupt();
// wait for deadlock threads to finish
phaser.arriveAndAwaitAdvance();
// wait for deadlocked status to clear before continuing
Awaitility.await().atMost(Duration.ofSeconds(10))
.until(() -> threadBean.findDeadlockedThreads() == null);
}
}

Expand All @@ -157,7 +163,6 @@ private void deadlock(Lock lock1, Lock lock2, long millis) {

@Test(timeOut = 5000L)
public void testDeadlockDetectionOverhead() {
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
for (int i=0; i < 1000; i++) {
long[] threadIds = threadBean.findDeadlockedThreads();
// assert that there's no deadlock
Expand Down

0 comments on commit 5795a56

Please sign in to comment.