@@ -623,13 +623,15 @@ public void testResubscribeExistingTaskSuccess() throws Exception {
623623 // resubscribe to the task, requires the task and its queue to still be active
624624 TaskResubscriptionRequest taskResubscriptionRequest = new TaskResubscriptionRequest ("1" , new TaskIdParams (MINIMAL_TASK .getId ()));
625625
626+ // Count down the latch when the MultiSseSupport on the server has started subscribing
627+ A2AServerRoutes .setStreamingMultiSseSupportSubscribedRunnable (taskResubscriptionRequestSent ::countDown );
628+
626629 CompletableFuture <HttpResponse <Stream <String >>> responseFuture = initialiseStreamingRequest (taskResubscriptionRequest , null );
627630
628- //CountDownLatch latch = new CountDownLatch(1);
629631 AtomicReference <Throwable > errorRef = new AtomicReference <>();
630- taskResubscriptionRequestSent .countDown ();
631632
632633 responseFuture .thenAccept (response -> {
634+
633635 if (response .statusCode () != 200 ) {
634636 //errorRef.set(new IllegalStateException("Status code was " + response.statusCode()));
635637 throw new IllegalStateException ("Status code was " + response .statusCode ());
@@ -660,14 +662,11 @@ public void testResubscribeExistingTaskSuccess() throws Exception {
660662 if (!isStreamClosedError (t )) {
661663 errorRef .set (t );
662664 }
663- //latch.countDown();
664665 return null ;
665666 });
666667
667668 try {
668669 taskResubscriptionRequestSent .await ();
669- // sleep to ensure that the events are sent after the client request is made
670- Thread .sleep (1000 );
671670 List <Event > events = List .of (
672671 new TaskArtifactUpdateEvent .Builder ()
673672 .taskId (MINIMAL_TASK .getId ())
@@ -713,6 +712,7 @@ public void testResubscribeExistingTaskSuccess() throws Exception {
713712 assertEquals (TaskState .COMPLETED , taskStatusUpdateEvent .getStatus ().state ());
714713 assertNotNull (taskStatusUpdateEvent .getStatus ().timestamp ());
715714 } finally {
715+ A2AServerRoutes .setStreamingMultiSseSupportSubscribedRunnable (null );
716716 taskStore .delete (MINIMAL_TASK .getId ());
717717 executorService .shutdown ();
718718 if (!executorService .awaitTermination (10 , TimeUnit .SECONDS )) {
0 commit comments