From bc39354db3923b2aedd13c15d92f51d2038b3489 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 11 Jun 2024 11:45:35 -0700 Subject: [PATCH] Fix flaky test IndicesRequestCacheIT.testDeleteAndCreateSameIndexShardOnSameNode (#14090) (#14124) Signed-off-by: kkewwei kkewwei@163.com Signed-off-by: kkewwei kkewwei@163.com (cherry picked from commit c639e9a42e4bf20ee05d0511ad8bfc8af9ecc0f9) Signed-off-by: kkewwei kkewwei@163.com Signed-off-by: kkewwei Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../indices/IndicesRequestCacheIT.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java index 306a5e48d521f..47cc4b1597d4f 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java @@ -1287,8 +1287,8 @@ public void testDeleteAndCreateSameIndexShardOnSameNode() throws Exception { final Index index = state.metadata().index(indexName).getIndex(); assertBusy(() -> { - assertThat(Files.exists(shardDirectory(node_1, index, 0)), equalTo(false)); - assertThat(Files.exists(shardDirectory(node_2, index, 0)), equalTo(true)); + assertFalse(Arrays.stream(shardDirectory(node_1, index, 0)).anyMatch(Files::exists)); + assertEquals(1, Arrays.stream(shardDirectory(node_2, index, 0)).filter(Files::exists).count()); }); 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 { .setWaitForNoInitializingShards(true) .get(); assertThat(clusterHealth.isTimedOut(), equalTo(false)); - assertThat(Files.exists(shardDirectory(node_1, index, 0)), equalTo(true)); assertBusy(() -> { - assertThat(Files.exists(shardDirectory(node_1, index, 0)), equalTo(true)); - assertThat(Files.exists(shardDirectory(node_2, index, 0)), equalTo(false)); + assertEquals(1, Arrays.stream(shardDirectory(node_1, index, 0)).filter(Files::exists).count()); + assertFalse(Arrays.stream(shardDirectory(node_2, index, 0)).anyMatch(Files::exists)); }); 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 { assertTrue(stats.getMemorySizeInBytes() == 0); } - private Path shardDirectory(String server, Index index, int shard) { + private Path[] shardDirectory(String server, Index index, int shard) { NodeEnvironment env = internalCluster().getInstance(NodeEnvironment.class, server); final Path[] paths = env.availableShardPaths(new ShardId(index, shard)); - assert paths.length == 1; - return paths[0]; + // the available paths of the shard may be bigger than the 1, + // it depends on `InternalTestCluster.numDataPaths`. + return paths; } private void setupIndex(Client client, String index) throws Exception {