From 46f251d7d379e84a35082d25fbc7dd72003892d3 Mon Sep 17 00:00:00 2001 From: David Kyle Date: Thu, 28 Oct 2021 13:01:24 +0100 Subject: [PATCH] [ML] Account for service being triggered twice in tests (#80000) (#80006) A race can cause the service under test to be triggered twice. As the test is asserting that the trigger occurs at least once multiple invocations should not be considered a failure --- .../xpack/ml/MlDailyMaintenanceServiceTests.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlDailyMaintenanceServiceTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlDailyMaintenanceServiceTests.java index 414fd242fcb3c..38d88097fa827 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlDailyMaintenanceServiceTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlDailyMaintenanceServiceTests.java @@ -34,6 +34,7 @@ import org.elasticsearch.xpack.core.ml.job.config.Job; import org.junit.After; import org.junit.Before; +import org.mockito.Mockito; import org.mockito.stubbing.Answer; import java.util.Collections; @@ -149,10 +150,10 @@ private void assertThatBothTasksAreTriggered(Answer deleteExpiredDataAnswer, latch.await(5, TimeUnit.SECONDS); } - verify(client, times(2)).threadPool(); - verify(client).execute(same(DeleteExpiredDataAction.INSTANCE), any(), any()); - verify(client).execute(same(GetJobsAction.INSTANCE), any(), any()); - verify(mlAssignmentNotifier).auditUnassignedMlTasks(any(), any()); + verify(client, Mockito.atLeast(2)).threadPool(); + verify(client, Mockito.atLeast(1)).execute(same(DeleteExpiredDataAction.INSTANCE), any(), any()); + verify(client, Mockito.atLeast(1)).execute(same(GetJobsAction.INSTANCE), any(), any()); + verify(mlAssignmentNotifier, Mockito.atLeast(1)).auditUnassignedMlTasks(any(), any()); verifyNoMoreInteractions(client, mlAssignmentNotifier); }