From 209291e702c483892280ec4e066e9b5592c584e8 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 1 Jul 2020 00:36:12 -0400 Subject: [PATCH] Improve the test a little --- .../proxy/util/concurrent/OnceTest.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/proxy/src/test/java/com/velocitypowered/proxy/util/concurrent/OnceTest.java b/proxy/src/test/java/com/velocitypowered/proxy/util/concurrent/OnceTest.java index 0fa9c10da..4cfb07c70 100644 --- a/proxy/src/test/java/com/velocitypowered/proxy/util/concurrent/OnceTest.java +++ b/proxy/src/test/java/com/velocitypowered/proxy/util/concurrent/OnceTest.java @@ -4,9 +4,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.Test; @@ -24,11 +24,15 @@ public class OnceTest { ExecutorService service = Executors.newFixedThreadPool(10); AtomicInteger i = new AtomicInteger(); Once once = new Once(); + CountDownLatch latch = new CountDownLatch(10); for (int i1 = 0; i1 < 10; i1++) { - service.execute(() -> once.run(i::incrementAndGet)); + service.execute(() -> { + once.run(i::incrementAndGet); + latch.countDown(); + }); } + latch.await(); service.shutdown(); - service.awaitTermination(500, TimeUnit.MILLISECONDS); assertEquals(1, i.get(), "Integer is not equal to one"); }