Skip to content
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

Add Assertion to the SharedTimerTest #2381

Merged
merged 3 commits into from May 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,14 +5,16 @@
import java.util.ArrayList;
import java.util.concurrent.*;

import static org.junit.jupiter.api.Assertions.assertFalse;

Jeffery-Wasty marked this conversation as resolved.
Show resolved Hide resolved

class SharedTimerTest {

@Test
void getTimer() throws InterruptedException, ExecutionException, TimeoutException {
final int iterations = 500;

ExecutorService executor = Executors.newFixedThreadPool(2);

try {
ArrayList<CompletableFuture<?>> futures = new ArrayList<>(iterations);
for (int i = 0; i < iterations; i++) {
Expand All @@ -22,6 +24,11 @@ void getTimer() throws InterruptedException, ExecutionException, TimeoutExceptio
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get(2, TimeUnit.MINUTES);
} finally {
executor.shutdown();
if (!executor.awaitTermination(800, TimeUnit.MILLISECONDS)) {
executor.shutdownNow();
Jeffery-Wasty marked this conversation as resolved.
Show resolved Hide resolved
}
}

assertFalse(SharedTimer.isRunning(), "SharedTimer should be stopped after all references are removed.");
Jeffery-Wasty marked this conversation as resolved.
Show resolved Hide resolved
}
}