Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky application logging test #9341

Merged
merged 3 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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