@@ -293,7 +293,7 @@ public void testDefaultMaxConcurrentSearches() {
293293 assertThat (result , equalTo (1 ));
294294 }
295295
296- public void testCancellation () {
296+ public void testCancellation () throws InterruptedException {
297297 // Initialize dependencies of TransportMultiSearchAction
298298 Settings settings = Settings .builder ().put ("node.name" , TransportMultiSearchActionTests .class .getSimpleName ()).build ();
299299 ActionFilters actionFilters = mock (ActionFilters .class );
@@ -385,22 +385,34 @@ public String getLocalNodeId() {
385385 }
386386 MultiSearchResponse [] responses = new MultiSearchResponse [1 ];
387387 Exception [] exceptions = new Exception [1 ];
388+ CountDownLatch executedLatch = new CountDownLatch (1 );
388389 parentTask [0 ] = (CancellableTask ) action .execute (multiSearchRequest , new TaskListener <>() {
389390 @ Override
390391 public void onResponse (Task task , MultiSearchResponse items ) {
391392 responses [0 ] = items ;
393+ executedLatch .countDown ();
392394 }
393395
394396 @ Override
395397 public void onFailure (Task task , Exception e ) {
396398 exceptions [0 ] = e ;
399+ executedLatch .countDown ();
397400 }
398401 });
399402 parentTask [0 ].cancel ("Giving up" );
400403 canceledLatch .countDown ();
401404
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 concalled = false ;
410+ for (MultiSearchResponse .Item item : responses [0 ].getResponses ()) {
411+ if (item .isFailure () && item .getFailure ().getMessage ().contains ("Parent task was cancelled" )) {
412+ concalled = true ;
413+ }
414+ }
415+ assertTrue (concalled );
404416 } finally {
405417 assertTrue (OpenSearchTestCase .terminate (threadPool ));
406418 }
0 commit comments