Skip to content

Commit 66a6dee

Browse files
Fix testSkipRefreshIfShardIsRefreshingAlready
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 elastic#50769
1 parent 807a4fb commit 66a6dee

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

server/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,20 +432,20 @@ protected long getShardWritingBytes(IndexShard shard) {
432432
}
433433
};
434434
int iterations = randomIntBetween(10, 100);
435+
ThreadPoolStats.Stats beforeStats = getRefreshThreadPoolStats();
435436
for (int i = 0; i < iterations; i++) {
436437
controller.forceCheck();
437438
}
438439
assertBusy(() -> {
439440
ThreadPoolStats.Stats stats = getRefreshThreadPoolStats();
440-
assertThat(stats.getQueue(), equalTo(0));
441-
assertThat(stats.getActive(), equalTo(1));
441+
assertThat(stats.getCompleted(), equalTo(beforeStats.getCompleted() + iterations - 1));
442442
});
443443
refreshLatch.get().countDown(); // allow refresh
444444
assertBusy(() -> {
445445
ThreadPoolStats.Stats stats = getRefreshThreadPoolStats();
446-
assertThat(stats.getQueue(), equalTo(0));
447-
assertThat(stats.getActive(), equalTo(0));
446+
assertThat(stats.getCompleted(), equalTo(beforeStats.getCompleted() + iterations));
448447
});
448+
System.out.println(shard.refreshStats().getTotal());
449449
assertThat(shard.refreshStats().getTotal(), equalTo(refreshStats.getTotal() + 1));
450450
closeShards(shard);
451451
}

0 commit comments

Comments
 (0)