Skip to content

Commit

Permalink
Fix occasionally ConcurrentModificationException in Netty tests
Browse files Browse the repository at this point in the history
Due to using stream() on a log appender while the appender is still running and possibly adding more logs.
  • Loading branch information
jduo committed Dec 1, 2023
1 parent 478446a commit 0345c65
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ public void testMemoryUsage() {
boolean result = false;
long startTime = System.currentTimeMillis();
while ((System.currentTimeMillis() - startTime) < 10000) { // 10 seconds maximum for time to read logs
// Pause the appender while collecting results to avoid concurrent modification exceptions
// since another thread might be using the logger.
memoryLogsAppender.stop();
result = memoryLogsAppender.list.stream()
.anyMatch(
log -> log.toString().contains("Memory Usage: \n") &&
log.toString().contains("Large buffers outstanding: ") &&
log.toString().contains("Normal buffers outstanding: ") &&
log.getLevel().equals(Level.TRACE)
);
memoryLogsAppender.start();
if (result) {
break;
}
Expand Down

0 comments on commit 0345c65

Please sign in to comment.