From 5812e6cc62eab9394daa40805a680733a83d20f2 Mon Sep 17 00:00:00 2001 From: Rishikesh1159 Date: Fri, 2 Dec 2022 23:47:46 +0000 Subject: [PATCH 1/4] All conditional check on assertNull to fix flaky tests. Signed-off-by: Rishikesh1159 --- ...dIndexingPressureConcurrentExecutionTests.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java b/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java index faab2f405010a..06813645561bc 100644 --- a/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java +++ b/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java @@ -269,7 +269,13 @@ public void testCoordinatingPrimaryThreadedUpdateToShardLimitsAndRejections() th nodeStats = shardIndexingPressure.stats(); IndexingPressurePerShardStats shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId1); - assertNull(shardStoreStats); + System.out.println("rejection count is: "+rejectionCount.get()); + if(rejectionCount.get() == NUM_THREADS){ + assertEquals(10, shardStoreStats.getCurrentPrimaryAndCoordinatingLimits()); + } + else{ + assertNull(shardStoreStats); + } shardStats = shardIndexingPressure.coldStats(); if (randomBoolean) { assertEquals(rejectionCount.get(), nodeStats.getCoordinatingRejections()); @@ -331,7 +337,12 @@ public void testReplicaThreadedUpdateToShardLimitsAndRejections() throws Excepti assertEquals(0, nodeStats.getCurrentReplicaBytes()); IndexingPressurePerShardStats shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId1); - assertNull(shardStoreStats); + if(rejectionCount.get() == NUM_THREADS){ + assertEquals(15, shardStoreStats.getCurrentReplicaLimits()); + } + else{ + assertNull(shardStoreStats); + } shardStats = shardIndexingPressure.coldStats(); assertEquals(rejectionCount.get(), shardStats.getIndexingPressureShardStats(shardId1).getReplicaNodeLimitsBreachedRejections()); From 46dd09ab9f9fd1d0a00729bf995b168ee79a6b0c Mon Sep 17 00:00:00 2001 From: Rishikesh1159 Date: Fri, 2 Dec 2022 23:59:12 +0000 Subject: [PATCH 2/4] Remove sys log statements. Signed-off-by: Rishikesh1159 --- .../index/ShardIndexingPressureConcurrentExecutionTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java b/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java index 06813645561bc..8e49c17f32e36 100644 --- a/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java +++ b/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java @@ -269,7 +269,6 @@ public void testCoordinatingPrimaryThreadedUpdateToShardLimitsAndRejections() th nodeStats = shardIndexingPressure.stats(); IndexingPressurePerShardStats shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId1); - System.out.println("rejection count is: "+rejectionCount.get()); if(rejectionCount.get() == NUM_THREADS){ assertEquals(10, shardStoreStats.getCurrentPrimaryAndCoordinatingLimits()); } From ae55b27656cdaef3db3bec12344a827f05240512 Mon Sep 17 00:00:00 2001 From: Rishikesh1159 Date: Sat, 3 Dec 2022 00:22:39 +0000 Subject: [PATCH 3/4] apply spotless. Signed-off-by: Rishikesh1159 --- .../ShardIndexingPressureConcurrentExecutionTests.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java b/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java index 8e49c17f32e36..44b7e96cf42f1 100644 --- a/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java +++ b/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java @@ -269,10 +269,9 @@ public void testCoordinatingPrimaryThreadedUpdateToShardLimitsAndRejections() th nodeStats = shardIndexingPressure.stats(); IndexingPressurePerShardStats shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId1); - if(rejectionCount.get() == NUM_THREADS){ + if (rejectionCount.get() == NUM_THREADS) { assertEquals(10, shardStoreStats.getCurrentPrimaryAndCoordinatingLimits()); - } - else{ + } else { assertNull(shardStoreStats); } shardStats = shardIndexingPressure.coldStats(); @@ -336,10 +335,9 @@ public void testReplicaThreadedUpdateToShardLimitsAndRejections() throws Excepti assertEquals(0, nodeStats.getCurrentReplicaBytes()); IndexingPressurePerShardStats shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId1); - if(rejectionCount.get() == NUM_THREADS){ + if (rejectionCount.get() == NUM_THREADS) { assertEquals(15, shardStoreStats.getCurrentReplicaLimits()); - } - else{ + } else { assertNull(shardStoreStats); } From bdcefdbf9156b724d11d2d522d2dfa8ec19df977 Mon Sep 17 00:00:00 2001 From: Rishikesh1159 Date: Sat, 3 Dec 2022 00:57:17 +0000 Subject: [PATCH 4/4] Add comments for the optional null check. Signed-off-by: Rishikesh1159 --- .../index/ShardIndexingPressureConcurrentExecutionTests.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java b/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java index 44b7e96cf42f1..8757458e3317e 100644 --- a/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java +++ b/server/src/test/java/org/opensearch/index/ShardIndexingPressureConcurrentExecutionTests.java @@ -269,6 +269,8 @@ public void testCoordinatingPrimaryThreadedUpdateToShardLimitsAndRejections() th nodeStats = shardIndexingPressure.stats(); IndexingPressurePerShardStats shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId1); + // If rejection count equals NUM_THREADS that means rejections happened until the last request, then we'll get shardStoreStats which + // was updated on the last request. In other cases, the shardStoreStats simply moves to the cold store and null is returned. if (rejectionCount.get() == NUM_THREADS) { assertEquals(10, shardStoreStats.getCurrentPrimaryAndCoordinatingLimits()); } else { @@ -335,6 +337,8 @@ public void testReplicaThreadedUpdateToShardLimitsAndRejections() throws Excepti assertEquals(0, nodeStats.getCurrentReplicaBytes()); IndexingPressurePerShardStats shardStoreStats = shardIndexingPressure.shardStats().getIndexingPressureShardStats(shardId1); + // If rejection count equals NUM_THREADS that means rejections happened until the last request, then we'll get shardStoreStats which + // was updated on the last request. In other cases, the shardStoreStats simply moves to the cold store and null is returned. if (rejectionCount.get() == NUM_THREADS) { assertEquals(15, shardStoreStats.getCurrentReplicaLimits()); } else {