From 1cd63d95ec860ae157cc903ad752db1087c8f76f Mon Sep 17 00:00:00 2001 From: jonmv Date: Wed, 18 Oct 2023 18:38:12 +0200 Subject: Wait for first reply to be set, in test thread --- messagebus/src/test/java/com/yahoo/messagebus/SequencerTestCase.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'messagebus/src/test') diff --git a/messagebus/src/test/java/com/yahoo/messagebus/SequencerTestCase.java b/messagebus/src/test/java/com/yahoo/messagebus/SequencerTestCase.java index e13d370fe8c..b077de80467 100644 --- a/messagebus/src/test/java/com/yahoo/messagebus/SequencerTestCase.java +++ b/messagebus/src/test/java/com/yahoo/messagebus/SequencerTestCase.java @@ -116,6 +116,7 @@ public class SequencerTestCase { // This test queues up a lot of replies, and then has them all ready to return at once. int n = 10000; CountDownLatch latch = new CountDownLatch(n); + CountDownLatch started = new CountDownLatch(1); AtomicReference waiting = new AtomicReference<>(); Executor executor = Executors.newSingleThreadExecutor(); MessageHandler sender = message -> { @@ -123,7 +124,8 @@ public class SequencerTestCase { Reply reply = new EmptyReply(); reply.swapState(message); reply.setMessage(message); - if ( ! waiting.compareAndSet(null, reply)) reply.popHandler().handleReply(reply); + if (waiting.compareAndSet(null, reply)) started.countDown(); + else reply.popHandler().handleReply(reply); }; if (Math.random() < 0.5) executor.execute(task); // Usually, RPC thread runs this. else task.run(); // But on, e.g., timeouts, it runs in the caller thread instead. @@ -147,6 +149,7 @@ public class SequencerTestCase { sent.add(message); } + assertTrue(started.await(10, TimeUnit.SECONDS)); waiting.get().popHandler().handleReply(waiting.get()); assertTrue(latch.await(10, TimeUnit.SECONDS), "All messages should obtain a reply within 10s"); assertEquals(Set.copyOf(sent), Set.copyOf(answered)); // Order is not guaranteed at all! -- cgit v1.2.3