Skip to content

Commit

Permalink
Fix flaky application logging test (#9341)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored Aug 30, 2023
1 parent 91dce58 commit b2e1fab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected void install(InternalLogger.Factory applicationLoggerFactory) {
while (inMemoryLogStore.currentSize() > 0) {
inMemoryLogStore.flush(applicationLoggerFactory);
}
inMemoryLogStore.setApplicationLoggerFactory(applicationLoggerFactory);

// actually install the application logger - from this point, everything will be logged
// directly through the application logging system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ final class InMemoryLogStore {

private final int limit;

private InternalLogger.Factory applicationLoggerFactory;

InMemoryLogStore(int limit) {
this.limit = limit;
}

void write(InMemoryLog log) {
synchronized (lock) {
// redirect to application logging system if it is already set up
// this is here to ensure that we don't lose any logs when switching from in memory to
// application logging
if (applicationLoggerFactory != null) {
applicationLoggerFactory.create(log.name()).log(log.level(), log.message(), log.error());
return;
}

// just drop the log if hit the limit
if (limit >= 0 && inMemoryLogs.size() >= limit) {
return;
Expand All @@ -49,6 +59,12 @@ void flush(InternalLogger.Factory applicationLoggerFactory) {
}
}

void setApplicationLoggerFactory(InternalLogger.Factory applicationLoggerFactory) {
synchronized (lock) {
this.applicationLoggerFactory = applicationLoggerFactory;
}
}

int currentSize() {
synchronized (lock) {
return inMemoryLogs.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void shouldOnlyInstallTheFirstBridge() {

verify(logStore, times(3)).currentSize();
verify(logStore).flush(applicationLoggerBridge);
verify(logStore).setApplicationLoggerFactory(applicationLoggerBridge);
verify(logStore).freeMemory();

underTest.install(applicationLoggerBridge);
Expand Down

0 comments on commit b2e1fab

Please sign in to comment.