Skip to content

Commit

Permalink
Add retries to InternalAuditLogTest as the indices might not be ready…
Browse files Browse the repository at this point in the history
… right after query.

Signed-off-by: Timo Olkkonen <[email protected]>
  • Loading branch information
Timo Olkkonen committed Feb 20, 2025
1 parent ac18e8b commit d6134ad
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
package org.opensearch.security;

import java.io.IOException;
import java.time.Duration;

import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -48,13 +48,24 @@ public class InternalAuditLogTest {
.build();

@Test
public void testAuditLogShouldBeGreenInSingleNodeCluster() throws IOException {
public void testAuditLogShouldBeGreenInSingleNodeCluster() throws InterruptedException {
try (TestRestClient client = cluster.getRestClient(USER_ADMIN)) {
client.get(""); // demo request for insuring audit-log index is created beforehand
TestRestClient.HttpResponse indicesResponse = client.get("_cat/indices");

assertThat(indicesResponse.getBody(), containsString("security-auditlog"));
assertThat(indicesResponse.getBody(), containsString("green"));
int retriesLeft = 5;
while (retriesLeft > 0) {
retriesLeft = retriesLeft - 1;
try {
TestRestClient.HttpResponse indicesResponse = client.get("_cat/indices");
assertThat(indicesResponse.getBody(), containsString("security-auditlog"));
assertThat(indicesResponse.getBody(), containsString("green"));
break;
} catch (AssertionError e) {
if (retriesLeft == 0) {
throw e;
}
Thread.sleep(Duration.ofSeconds(1));
}
}
}
}
}

0 comments on commit d6134ad

Please sign in to comment.