Skip to content

Commit 5358bba

Browse files
authored
Fix flaky RemoteRoutingTableServiceTests.testGetAsyncIndexRoutingTableDiffReadAction (#20618)
The test was failing intermittently with CorruptStateException due to the mock returning the same stateful InputStream instance in a loop in a test case. Changed the mock from thenReturn() to thenAnswer() to generate a fresh input stream for each invocation. Similarly, a CountdownLatch was being reused within the loop, but would have been blocking only on the first iteration. Moved the latch to be initialized inside each loop iteration. Signed-off-by: Andrew Ross <andrross@amazon.com>
1 parent 2c1cb01 commit 5358bba

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

server/src/test/java/org/opensearch/cluster/routing/remote/RemoteRoutingTableServiceTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -611,14 +611,14 @@ public void testGetAsyncIndexRoutingTableDiffReadAction() throws Exception {
611611
compressor,
612612
Version.CURRENT
613613
);
614-
when(blobContainer.readBlob(indexName)).thenReturn(
615-
remoteRoutingTableDiff.remoteRoutingTableDiffFormat.serialize(diff, uploadedFileName, compressor).streamInput()
614+
when(blobContainer.readBlob(indexName)).thenAnswer(
615+
invocation -> remoteRoutingTableDiff.remoteRoutingTableDiffFormat.serialize(diff, uploadedFileName, compressor).streamInput()
616616
);
617617

618-
TestCapturingListener<Diff<RoutingTable>> listener = new TestCapturingListener<>();
619-
CountDownLatch latch = new CountDownLatch(1);
620-
621618
for (Version version : List.of(Version.CURRENT, Version.V_3_1_0, Version.V_3_2_0)) {
619+
TestCapturingListener<Diff<RoutingTable>> listener = new TestCapturingListener<>();
620+
CountDownLatch latch = new CountDownLatch(1);
621+
622622
remoteRoutingTableService.getAsyncIndexRoutingTableDiffReadAction(
623623
"cluster-uuid",
624624
uploadedFileName,

0 commit comments

Comments
 (0)