Skip to content

Commit 884dfdb

Browse files
authored
fix: Fixed the intermittent failure issue in testOnMessageStreamNewMessageSendPushNotificationSuccess (#161)
The reason for its intermittent failure, I believe, is as follows: We initially set up the `CountDownLatch` with a count of 6, and we will call `latch.countDown()` at the following three locations: - A. in `onSubscribe` - B. in the `finally` block of the `post` method in `HttpClient` - C. in `onNext` Ideally, when the test method runs, the sequence of `countDown()` calls should be like this: **A B C B C B C** The `countDown()` function was called a total of 7 times! This explains why we sometimes see only **2 elements** in `results` when we do `assertEquals(3, results.size())`. It's because the last `onNext` may not have completed execution yet. **What this PR does:** We could fix this by initializing the `CountDownLatch` to 7. However, considering the purpose of this test method, I chose instead to keep the count at 6 and **remove the `latch.countDown()` call in `onSubscribe`**. Fixes #140 Signed-off-by: Sun Yuhan <[email protected]> Co-authored-by: Sun Yuhan <[email protected]>
1 parent b6712e8 commit 884dfdb

File tree

1 file changed

+0
-11
lines changed

1 file changed

+0
-11
lines changed

sdk-server-common/src/test/java/io/a2a/server/requesthandlers/JSONRPCHandlerTest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,6 @@ public void testOnMessageStreamNewMessageSendPushNotificationSuccess() throws Ex
700700
public void onSubscribe(Flow.Subscription subscription) {
701701
subscriptionRef.set(subscription);
702702
subscription.request(1);
703-
latch.countDown();
704703
}
705704

706705
@Override
@@ -726,16 +725,6 @@ public void onComplete() {
726725

727726
assertTrue(latch.await(5, TimeUnit.SECONDS));
728727
subscriptionRef.get().cancel();
729-
if (results.size() != 3) {
730-
// TODO - this is very strange. The results array is synchronized, and the latch is counted down
731-
// AFTER adding items to the list. Still, I am seeing intermittently, but frequently that
732-
// the results list only has two items.
733-
// Remove System.out.printlns in this test when done.
734-
long end = System.currentTimeMillis() + 5000;
735-
while (results.size() != 3 && System.currentTimeMillis() < end) {
736-
Thread.sleep(1000);
737-
}
738-
}
739728
assertEquals(3, results.size());
740729
assertEquals(3, httpClient.tasks.size());
741730

0 commit comments

Comments
 (0)