Even more robust test for API key auth 429 response (#59159) (#59208)

Ensure blocking tasks are running before submitting more no-op tasks. This ensures no task would be popped out of the queue unexpectedly, which in turn guarantees the rejection of subsequent authentication request.
This commit is contained in:
Yang Wang 2020-07-08 16:43:07 +10:00 committed by GitHub
parent 3700bd1c08
commit a6109063a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -858,10 +858,10 @@ public class ApiKeyIntegTests extends SecurityIntegTestCase {
assertApiKeyNotCreated(client,"key-5");
}
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/59149")
public void testAuthenticationReturns429WhenThreadPoolIsSaturated() throws IOException, InterruptedException, ExecutionException {
final String nodeName = randomFrom(internalCluster().getNodeNames());
final Settings settings = internalCluster().getInstance(Settings.class, nodeName);
final int allocatedProcessors = EsExecutors.allocatedProcessors(settings);
final ThreadPool threadPool = internalCluster().getInstance(ThreadPool.class, nodeName);
final RoleDescriptor descriptor = new RoleDescriptor("auth_only", new String[] { }, null, null);
@ -880,9 +880,9 @@ public class ApiKeyIntegTests extends SecurityIntegTestCase {
final List<NodeInfo> nodeInfos = client().admin().cluster().prepareNodesInfo().get().getNodes().stream()
.filter(nodeInfo -> nodeInfo.getNode().getName().equals(nodeName))
.collect(Collectors.toList());
assertEquals(1, nodeInfos.size());
final ExecutorService executorService = threadPool.executor(SECURITY_CRYPTO_THREAD_POOL_NAME);
final int allocatedProcessors = EsExecutors.allocatedProcessors(settings);
final int numberOfThreads = (allocatedProcessors + 1) / 2;
final CountDownLatch blockingLatch = new CountDownLatch(1);
final CountDownLatch readyLatch = new CountDownLatch(numberOfThreads);
@ -896,15 +896,18 @@ public class ApiKeyIntegTests extends SecurityIntegTestCase {
}
});
}
// Fill the whole queue for the crypto thread pool
// Make sure above tasks are running
readyLatch.await();
// Then fill the whole queue for the crypto thread pool
Future<?> lastTaskFuture = null;
int i = 0;
try {
for (int i = 0; i < CRYPTO_THREAD_POOL_QUEUE_SIZE; i++) {
for (i = 0; i < CRYPTO_THREAD_POOL_QUEUE_SIZE; i++) {
lastTaskFuture = executorService.submit(() -> { });
}
} catch (EsRejectedExecutionException e) {
logger.info("Attempted to push {} tasks but only pushed {}", CRYPTO_THREAD_POOL_QUEUE_SIZE, i + 1);
}
readyLatch.await();
try (RestClient restClient = createRestClient(nodeInfos, null, "http")) {
final String base64ApiKeyKeyValue = Base64.getEncoder().encodeToString(