Skip to content

Commit 30224d0

Browse files
authored
[ML] Fix rare ML daily maintenance test race condition (#64043)
Depending on thread scheduling the ML daily maintenance tests could do one more iteration than expected, causing rare failures. Fixes #64036
1 parent 0e0fb73 commit 30224d0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlDailyMaintenanceServiceTests.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,16 @@ private void testJobInDeletingStateDoesNotHaveDeletionTask(boolean deleted) thro
230230

231231
private MlDailyMaintenanceService createService(CountDownLatch latch, Client client) {
232232
return new MlDailyMaintenanceService(Settings.EMPTY, threadPool, client, clusterService, mlAssignmentNotifier, () -> {
233-
latch.countDown();
234-
return TimeValue.timeValueMillis(100);
233+
// We need to be careful that an unexpected iteration doesn't get squeezed in by the maintenance threadpool in
234+
// between the latch getting counted down to zero and the main test thread stopping the maintenance service.
235+
// This could happen if the main test thread happens to be waiting for a CPU for the whole 100ms after the
236+
// latch counts down to zero.
237+
if (latch.getCount() > 0) {
238+
latch.countDown();
239+
return TimeValue.timeValueMillis(100);
240+
} else {
241+
return TimeValue.timeValueHours(1);
242+
}
235243
});
236244
}
237245

0 commit comments

Comments
 (0)