@@ -293,7 +293,7 @@ public void testDefaultMaxConcurrentSearches() {
293
293
assertThat (result , equalTo (1 ));
294
294
}
295
295
296
- public void testCancellation () {
296
+ public void testCancellation () throws InterruptedException {
297
297
// Initialize dependencies of TransportMultiSearchAction
298
298
Settings settings = Settings .builder ().put ("node.name" , TransportMultiSearchActionTests .class .getSimpleName ()).build ();
299
299
ActionFilters actionFilters = mock (ActionFilters .class );
@@ -385,22 +385,35 @@ public String getLocalNodeId() {
385
385
}
386
386
MultiSearchResponse [] responses = new MultiSearchResponse [1 ];
387
387
Exception [] exceptions = new Exception [1 ];
388
+ CountDownLatch executedLatch = new CountDownLatch (1 );
388
389
parentTask [0 ] = (CancellableTask ) action .execute (multiSearchRequest , new TaskListener <>() {
389
390
@ Override
390
391
public void onResponse (Task task , MultiSearchResponse items ) {
391
392
responses [0 ] = items ;
393
+ executedLatch .countDown ();
392
394
}
393
395
394
396
@ Override
395
397
public void onFailure (Task task , Exception e ) {
396
398
exceptions [0 ] = e ;
399
+ executedLatch .countDown ();
397
400
}
398
401
});
399
402
parentTask [0 ].cancel ("Giving up" );
400
403
canceledLatch .countDown ();
401
404
402
- assertNull (responses [0 ]);
403
- assertNull (exceptions [0 ]);
405
+ if (!executedLatch .await (10 , TimeUnit .SECONDS )) {
406
+ fail ("Latch should have counted down" );
407
+ }
408
+
409
+ boolean cancelled = false ;
410
+ for (MultiSearchResponse .Item item : responses [0 ].getResponses ()) {
411
+ if (item .isFailure () && item .getFailure ().getMessage ().contains ("Parent task was cancelled" )) {
412
+ cancelled = true ;
413
+ break ;
414
+ }
415
+ }
416
+ assertTrue (cancelled );
404
417
} finally {
405
418
assertTrue (OpenSearchTestCase .terminate (threadPool ));
406
419
}
0 commit comments