Resolve some test flakiness by adding a deterministic "wait" mechanism. (SERVER-86)

This commit is contained in:
Jon Chambers
2020-06-26 16:27:24 -04:00
committed by Jon Chambers
parent e48afc9fdf
commit a68d91b54c
2 changed files with 19 additions and 8 deletions

View File

@@ -32,12 +32,12 @@ public class RemoteConfigsManager implements Managed {
@Override
public void start() {
this.cachedConfigs.set(remoteConfigs.getAll());
refreshCache();
new Thread(() -> {
while (true) {
try {
this.cachedConfigs.set(remoteConfigs.getAll());
refreshCache();
} catch (Throwable t) {
logger.warn("Error updating remote configs cache", t);
}
@@ -47,6 +47,21 @@ public class RemoteConfigsManager implements Managed {
}).start();
}
private void refreshCache() {
this.cachedConfigs.set(remoteConfigs.getAll());
synchronized (this.cachedConfigs) {
this.cachedConfigs.notifyAll();
}
}
@VisibleForTesting
void waitForCacheRefresh() throws InterruptedException {
synchronized (this.cachedConfigs) {
this.cachedConfigs.wait();
}
}
public List<RemoteConfig> getAll() {
return cachedConfigs.get();
}