diff --git a/src/test/java/net/openhft/chronicle/queue/impl/single/NormaliseEOFsTest.java b/src/test/java/net/openhft/chronicle/queue/impl/single/NormaliseEOFsTest.java index c9297257dd..9af8cbacf7 100644 --- a/src/test/java/net/openhft/chronicle/queue/impl/single/NormaliseEOFsTest.java +++ b/src/test/java/net/openhft/chronicle/queue/impl/single/NormaliseEOFsTest.java @@ -74,12 +74,15 @@ public void normaliseShouldResumeFromPreviousNormalisation() { excerptAppender.normaliseEOFs(); } final Pattern logPattern = Pattern.compile("Normalising from cycle (\\d+)"); - // Note a defensive copy of exceptionMap is used as this code has yielded concurrent modification exceptions leading to flakiness under load - final List startIndices = new LinkedHashMap<>(exceptionMap).keySet().stream() - .map(exceptionKey -> logPattern.matcher(exceptionKey.message)) - .filter(Matcher::matches) - .map(matcher -> Integer.parseInt(matcher.group(1))) - .collect(Collectors.toList()); + // Note: lock the exceptionMap to avoid a concurrent modification exceptions leading to flakiness under load + final List startIndices; + synchronized (exceptionMap) { + startIndices = exceptionMap.keySet().stream() + .map(exceptionKey -> logPattern.matcher(exceptionKey.message)) + .filter(Matcher::matches) + .map(matcher -> Integer.parseInt(matcher.group(1))) + .collect(Collectors.toList()); + } // There is at least 5 calls to normaliseEOF and the start index increases each time assertTrue(startIndices.size() >= 5);