summaryrefslogtreecommitdiffstats
path: root/messagebus
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2023-10-18 18:38:12 +0200
committerjonmv <venstad@gmail.com>2023-10-18 18:38:12 +0200
commit1cd63d95ec860ae157cc903ad752db1087c8f76f (patch)
treed56323a901e1ea59b79aa3b577f3c55a73ce5c85 /messagebus
parentff71bc93baaab4b714ddccd29f5ea9ae31bc918c (diff)
Wait for first reply to be set, in test thread
Diffstat (limited to 'messagebus')
-rw-r--r--messagebus/src/test/java/com/yahoo/messagebus/SequencerTestCase.java5
1 files changed, 4 insertions, 1 deletions
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<Reply> 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!