Skip to content

Commit bc39354

Browse files
Fix flaky test IndicesRequestCacheIT.testDeleteAndCreateSameIndexShardOnSameNode (opensearch-project#14090) (opensearch-project#14124)
Signed-off-by: kkewwei kkewwei@163.com Signed-off-by: kkewwei kkewwei@163.com (cherry picked from commit c639e9a) Signed-off-by: kkewwei kkewwei@163.com Signed-off-by: kkewwei <kkewwei@163.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 3f136fe commit bc39354

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -1287,8 +1287,8 @@ public void testDeleteAndCreateSameIndexShardOnSameNode() throws Exception {
12871287
final Index index = state.metadata().index(indexName).getIndex();
12881288

12891289
assertBusy(() -> {
1290-
assertThat(Files.exists(shardDirectory(node_1, index, 0)), equalTo(false));
1291-
assertThat(Files.exists(shardDirectory(node_2, index, 0)), equalTo(true));
1290+
assertFalse(Arrays.stream(shardDirectory(node_1, index, 0)).anyMatch(Files::exists));
1291+
assertEquals(1, Arrays.stream(shardDirectory(node_2, index, 0)).filter(Files::exists).count());
12921292
});
12931293

12941294
logger.info("Moving the shard: {} again from node:{} to node:{}", indexName + "#0", node_2, node_1);
@@ -1301,11 +1301,10 @@ public void testDeleteAndCreateSameIndexShardOnSameNode() throws Exception {
13011301
.setWaitForNoInitializingShards(true)
13021302
.get();
13031303
assertThat(clusterHealth.isTimedOut(), equalTo(false));
1304-
assertThat(Files.exists(shardDirectory(node_1, index, 0)), equalTo(true));
13051304

13061305
assertBusy(() -> {
1307-
assertThat(Files.exists(shardDirectory(node_1, index, 0)), equalTo(true));
1308-
assertThat(Files.exists(shardDirectory(node_2, index, 0)), equalTo(false));
1306+
assertEquals(1, Arrays.stream(shardDirectory(node_1, index, 0)).filter(Files::exists).count());
1307+
assertFalse(Arrays.stream(shardDirectory(node_2, index, 0)).anyMatch(Files::exists));
13091308
});
13101309

13111310
logger.info("Clearing the cache for index:{}. And verify the request stats doesn't go negative", indexName);
@@ -1318,11 +1317,12 @@ public void testDeleteAndCreateSameIndexShardOnSameNode() throws Exception {
13181317
assertTrue(stats.getMemorySizeInBytes() == 0);
13191318
}
13201319

1321-
private Path shardDirectory(String server, Index index, int shard) {
1320+
private Path[] shardDirectory(String server, Index index, int shard) {
13221321
NodeEnvironment env = internalCluster().getInstance(NodeEnvironment.class, server);
13231322
final Path[] paths = env.availableShardPaths(new ShardId(index, shard));
1324-
assert paths.length == 1;
1325-
return paths[0];
1323+
// the available paths of the shard may be bigger than the 1,
1324+
// it depends on `InternalTestCluster.numDataPaths`.
1325+
return paths;
13261326
}
13271327

13281328
private void setupIndex(Client client, String index) throws Exception {

0 commit comments

Comments
 (0)