Skip to content

Commit

Permalink
fix flakiness of concurrently_interruptionPropagated()
Browse files Browse the repository at this point in the history
  • Loading branch information
fluentfuture committed Dec 24, 2024
1 parent d412ec2 commit 38e6491
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions mug/src/test/java/com/google/mu/util/concurrent/FanoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,38 @@ public void concurrently_sideEffectsAreSafe() {
@Test
public void concurrently_interruptionPropagated() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
AtomicBoolean operationInterrupted = new AtomicBoolean();
CountDownLatch concurrentOperationInterrupted = new CountDownLatch(1);
AtomicBoolean interruptionSwallowed = new AtomicBoolean();
AtomicBoolean interruptionPropagated = new AtomicBoolean();
Thread thread = new Thread(() -> {
try {
concurrently(
() -> {},
() -> {
try {
latch.await();
} catch (InterruptedException e) {
operationInterrupted.set(true);
}
});
} catch (StructuredConcurrencyInterruptedException e) {
interruptionSwallowed.set(true);
}
try {
latch.await();
} catch (InterruptedException e) {
interruptionPropagated.set(true);
}
});
Thread thread =
new Thread(
() -> {
try {
concurrently(
() -> {},
() -> {
try {
latch.await();
} catch (InterruptedException e) {
concurrentOperationInterrupted.countDown();
}
});
} catch (StructuredConcurrencyInterruptedException e) {
interruptionSwallowed.set(true);
}
try {
latch.await();
} catch (InterruptedException e) {
interruptionPropagated.set(true);
}
});
thread.start();
Thread.sleep(100);
assertThat(thread.isAlive()).isTrue();
assertThat(thread.isInterrupted()).isFalse();
thread.interrupt();
thread.join();
assertThat(operationInterrupted.get()).isTrue();
concurrentOperationInterrupted.await();
assertThat(interruptionSwallowed.get()).isTrue();
assertThat(interruptionPropagated.get()).isTrue();
}
Expand Down

0 comments on commit 38e6491

Please sign in to comment.