Fix testSkipRefreshIfShardIsRefreshingAlready (#50856)

The test checked queue size and active count, however,
ThreadPoolExecutor pulls out the request from the queue before marking
the worker active, risking that we think all tasks are done when they
are not. Now check on completed-tasks metric instead, which is
guaranteed to be monotonic.

Relates #50769
This commit is contained in:
Henning Andersen 2020-01-10 17:29:00 +01:00 committed by Nhat Nguyen
parent f4aabdcd89
commit 2e5e5fd483
1 changed files with 3 additions and 4 deletions

View File

@ -432,19 +432,18 @@ public class IndexingMemoryControllerTests extends IndexShardTestCase {
} }
}; };
int iterations = randomIntBetween(10, 100); int iterations = randomIntBetween(10, 100);
ThreadPoolStats.Stats beforeStats = getRefreshThreadPoolStats();
for (int i = 0; i < iterations; i++) { for (int i = 0; i < iterations; i++) {
controller.forceCheck(); controller.forceCheck();
} }
assertBusy(() -> { assertBusy(() -> {
ThreadPoolStats.Stats stats = getRefreshThreadPoolStats(); ThreadPoolStats.Stats stats = getRefreshThreadPoolStats();
assertThat(stats.getQueue(), equalTo(0)); assertThat(stats.getCompleted(), equalTo(beforeStats.getCompleted() + iterations - 1));
assertThat(stats.getActive(), equalTo(1));
}); });
refreshLatch.get().countDown(); // allow refresh refreshLatch.get().countDown(); // allow refresh
assertBusy(() -> { assertBusy(() -> {
ThreadPoolStats.Stats stats = getRefreshThreadPoolStats(); ThreadPoolStats.Stats stats = getRefreshThreadPoolStats();
assertThat(stats.getQueue(), equalTo(0)); assertThat(stats.getCompleted(), equalTo(beforeStats.getCompleted() + iterations));
assertThat(stats.getActive(), equalTo(0));
}); });
assertThat(shard.refreshStats().getTotal(), equalTo(refreshStats.getTotal() + 1)); assertThat(shard.refreshStats().getTotal(), equalTo(refreshStats.getTotal() + 1));
closeShards(shard); closeShards(shard);