From 86aab98fde8dc4be8843ddb79216061aca0da406 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Fri, 28 Apr 2017 20:42:56 +0200 Subject: [PATCH] [TEST] Fix race condition in ZenDiscoveryIT.testDiscoveryStats With #24236, the master now uses the pending queue when publishing to itself. This means that a cluster state update is put into the pending queue, then sent to the ClusterApplierService to be applied. After it has been applied, it is marked as processed and removed from the pending queue. ensureGreen is implemented as a cluster health action that waits on certain conditions, which will lead to a cluster state update task to be submitted on the master. When this task gets to run and the conditions are not satisfied yet, it register a cluster state observer. This observer is registered on the ClusterApplierService and waits on cluster state change events. ClusterApplierService first notifies the observer and then the discovery layer. This means that there is a small time frame where ensureGreen can complete and call the node stats to find the pending queue still containing the last cluster state update. Closes #24388 --- .../java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java b/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java index 7ac463616fc..7821d4fd944 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/ZenDiscoveryIT.java @@ -248,7 +248,7 @@ public class ZenDiscoveryIT extends ESIntegTestCase { } } - public void testDiscoveryStats() throws IOException { + public void testDiscoveryStats() throws Exception { String expectedStatsJsonResponse = "{\n" + " \"discovery\" : {\n" + " \"cluster_state_queue\" : {\n" + @@ -261,6 +261,9 @@ public class ZenDiscoveryIT extends ESIntegTestCase { internalCluster().startNode(); ensureGreen(); // ensures that all events are processed (in particular state recovery fully completed) + assertBusy(() -> + assertThat(internalCluster().clusterService(internalCluster().getMasterName()).getMasterService().numberOfPendingTasks(), + equalTo(0))); // see https://github.com/elastic/elasticsearch/issues/24388 logger.info("--> request node discovery stats"); NodesStatsResponse statsResponse = client().admin().cluster().prepareNodesStats().clear().setDiscovery(true).get();