From 4afe1e543d898afd2efc3f7cbb628150a7ddbde8 Mon Sep 17 00:00:00 2001 From: Yang Wang Date: Thu, 16 Sep 2021 16:06:10 +1000 Subject: [PATCH] [Test] Reduce concurrency when testing creation of security index (#75293) The internal cluster could get overwhelmed by many nodes and large number of concurrent putUser request. It can sometimes fail with confusing messages when JVM is under pressure. This PR reduces the concurrency so it has a better chance to succeed. The test also no longer relies on the user being "created" instead of "updated". Since they do not make a difference for the purpose of this test. --- .../support/SecurityIndexManagerIntegTests.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerIntegTests.java b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerIntegTests.java index 6060fc6e35691..ddbb533c0b21f 100644 --- a/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerIntegTests.java +++ b/x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerIntegTests.java @@ -27,9 +27,10 @@ public class SecurityIndexManagerIntegTests extends SecurityIntegTestCase { public void testConcurrentOperationsTryingToCreateSecurityIndexAndAlias() throws Exception { assertSecurityIndexActive(); final int processors = Runtime.getRuntime().availableProcessors(); - final int numThreads = scaledRandomIntBetween((processors + 1) / 2, 4 * processors); - final int maxNumRequests = 100 / numThreads; // bound to a maximum of 100 requests + final int numThreads = Math.min(50, scaledRandomIntBetween((processors + 1) / 2, 4 * processors)); // up to 50 threads + final int maxNumRequests = 50 / numThreads; // bound to a maximum of 50 requests final int numRequests = scaledRandomIntBetween(Math.min(4, maxNumRequests), maxNumRequests); + logger.info("creating users with [{}] threads, each sending [{}] requests", numThreads, numRequests); final List> futures = new CopyOnWriteArrayList<>(); final List exceptions = new CopyOnWriteArrayList<>(); @@ -71,7 +72,10 @@ protected void doRun() throws Exception { assertThat(exceptions, Matchers.empty()); assertEquals(futures.size(), numRequests * numThreads); for (ActionFuture future : futures) { - assertTrue(future.actionGet().created()); + // In rare cases, the user could be updated instead of created. For the purpose of + // this test, either created or updated is sufficient to prove that the security + // index is created. So we don't need to assert the value. + future.actionGet().created(); } }