4343import org .elasticsearch .xcontent .XContentParser ;
4444import org .junit .After ;
4545import org .junit .Before ;
46+ import org .mockito .Mockito ;
4647import org .mockito .stubbing .Answer ;
4748
4849import java .io .IOException ;
@@ -315,7 +316,13 @@ public void testInvalidJSON() throws Exception {
315316 writeTestFile (fileSettingsService .watchedFile (), "test_invalid_JSON" );
316317 awaitOrBust (fileChangeBarrier );
317318
318- verify (fileSettingsService , times (1 )).onProcessFileChangesException (
319+ // These checks use atLeast(1) because the initial JSON is also invalid,
320+ // and so we sometimes get two calls to these error-reporting methods
321+ // depending on timing. Rather than trace down the root cause and fix
322+ // it, we tolerate this for now because, hey, invalid JSON is invalid JSON
323+ // and this is still testing what we want to test.
324+
325+ verify (fileSettingsService , Mockito .atLeast (1 )).onProcessFileChangesException (
319326 argThat (e -> unwrapException (e ) instanceof XContentParseException )
320327 );
321328
@@ -324,7 +331,7 @@ public void testInvalidJSON() throws Exception {
324331 // of the watcher thread itself, which occurs asynchronously when clusterChanged is first called.
325332
326333 assertEquals (YELLOW , healthIndicatorService .calculate (false , null ).status ());
327- verify (healthIndicatorService ).failureOccurred (contains (XContentParseException .class .getName ()));
334+ verify (healthIndicatorService , Mockito . atLeast ( 1 ) ).failureOccurred (contains (XContentParseException .class .getName ()));
328335 }
329336
330337 /**
0 commit comments