Skip to content

Commit

Permalink
Fix intermittent failure in BroadcasterExecutorTest
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol committed Jul 25, 2024
1 parent c4adbb3 commit 42dde76
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -152,13 +152,15 @@ private static class CustomClientAsyncExecutor extends ThreadPoolExecutorProvide
@Test
public void test() throws InterruptedException {
final String[] onEventThreadName = {""};
final CountDownLatch onEventLatch = new CountDownLatch(1);
SseEventSource eventSource = SseEventSource
.target(target().path("sse/events"))
.build();

eventSource.register((event) -> {
LOGGER.info("Event: " + event + " from: " + Thread.currentThread().getName());
onEventThreadName[0] = Thread.currentThread().getName();
onEventLatch.countDown();
}
);

Expand All @@ -174,6 +176,7 @@ public void test() throws InterruptedException {
Assertions.assertTrue(sendThreadOk, "send either not invoked at all or from wrong thread");
Assertions.assertTrue(onCompleteThreadOk, "onComplete either not invoked at all or from wrong thread");

Assertions.assertTrue(onEventLatch.await(2_000L, TimeUnit.MILLISECONDS));
Assertions.assertTrue(onEventThreadName[0].startsWith("custom-client-executor"),
"Client event called from wrong thread ( " + onEventThreadName[0] + ")");
}
Expand Down

0 comments on commit 42dde76

Please sign in to comment.