Skip to content
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 @@ -318,12 +318,16 @@ void trackDataSourceState(State newState, ErrorInfo newError) {
// with a timeout for logging the outage at a higher level, schedule that timeout.
if (inOutage) {
// We were already in one - just record this latest error for logging later.
recordError(newError);
} else {
if (newError != null) {
recordError(newError);
}
} else {
// We weren't already in one, so set the timeout and start recording errors.
inOutage = true;
errorCounts.clear();
recordError(newError);
if (newError != null) {
recordError(newError);
}
timeoutFuture = sharedExecutor.schedule(this::onTimeout, loggingTimeout.toMillis(), TimeUnit.MILLISECONDS);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,53 @@ public void outageTimeoutLogging() throws Exception {
assertThat(errorsDesc, containsString("ERROR_RESPONSE(502) (1 time)"));
}

@Test
public void outageTrackerToleratesInterruptedStatusWithNoError() throws Exception {
BlockingQueue<String> outageErrors = new LinkedBlockingQueue<>();
Duration outageTimeout = Duration.ofMillis(100);

DataSourceUpdatesImpl updates = new DataSourceUpdatesImpl(
inMemoryDataStore(),
null,
flagChangeBroadcaster,
EventBroadcasterImpl.forDataSourceStatus(sharedExecutor, nullLogger),
sharedExecutor,
outageTimeout,
nullLogger
);
updates.onOutageErrorLog = outageErrors::add;

// a status update during an outage is not required to carry an error
updates.updateStatus(State.INTERRUPTED, ErrorInfo.fromHttpError(401));
updates.updateStatus(State.INTERRUPTED, null);

String errorsDesc = awaitValue(outageErrors, 250, TimeUnit.MILLISECONDS);
assertThat(errorsDesc, containsString("ERROR_RESPONSE(401) (1 time)"));
}

@Test
public void outageTrackerToleratesFirstInterruptedStatusWithNoError() throws Exception {
BlockingQueue<String> outageErrors = new LinkedBlockingQueue<>();
Duration outageTimeout = Duration.ofMillis(100);

DataSourceUpdatesImpl updates = new DataSourceUpdatesImpl(
inMemoryDataStore(),
null,
flagChangeBroadcaster,
EventBroadcasterImpl.forDataSourceStatus(sharedExecutor, nullLogger),
sharedExecutor,
outageTimeout,
nullLogger
);
updates.onOutageErrorLog = outageErrors::add;

// the outage must still be timed even when its first report carries no error
updates.updateStatus(State.VALID, null);
updates.updateStatus(State.INTERRUPTED, null);

awaitValue(outageErrors, 250, TimeUnit.MILLISECONDS);
}

@Test
public void applyFullChangeSetSendsEventsForNewlyAddedFlags() throws Exception {
DataSourceUpdatesImpl updates = makeInstance(inMemoryDataStore());
Expand Down