Skip to content

Commit

Permalink
Fix race in SpawnerNoBootstrapTests (#108416)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoop committed May 9, 2024
1 parent 864543b commit f5b356d
Showing 1 changed file with 9 additions and 7 deletions.
Expand Up @@ -39,8 +39,10 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;

/**
* Create a simple "daemon controller", put it in the right place and check that it runs.
Expand Down Expand Up @@ -70,13 +72,13 @@ public class SpawnerNoBootstrapTests extends LuceneTestCase {
static class ExpectedStreamMessage implements MockLogAppender.LoggingExpectation {
final String expectedLogger;
final String expectedMessage;
final CountDownLatch matchCalledLatch;
boolean saw;
final CountDownLatch matched;
volatile boolean saw;

ExpectedStreamMessage(String logger, String message, CountDownLatch matchCalledLatch) {
ExpectedStreamMessage(String logger, String message, CountDownLatch matched) {
this.expectedLogger = logger;
this.expectedMessage = message;
this.matchCalledLatch = matchCalledLatch;
this.matched = matched;
}

@Override
Expand All @@ -85,8 +87,8 @@ public void match(LogEvent event) {
&& event.getLevel().equals(Level.WARN)
&& event.getMessage().getFormattedMessage().equals(expectedMessage)) {
saw = true;
matched.countDown();
}
matchCalledLatch.countDown();
}

@Override
Expand Down Expand Up @@ -130,7 +132,7 @@ public void testNoControllerSpawn() throws IOException {

try (Spawner spawner = new Spawner()) {
spawner.spawnNativeControllers(environment);
assertThat(spawner.getProcesses(), hasSize(0));
assertThat(spawner.getProcesses(), is(empty()));
}
}

Expand Down Expand Up @@ -229,7 +231,7 @@ private void assertControllerSpawns(final Function<Environment, Path> pluginsDir
// fail if the process does not die within one second; usually it will be even quicker but it depends on OS scheduling
assertTrue(process.waitFor(1, TimeUnit.SECONDS));
} else {
assertThat(processes, hasSize(0));
assertThat(processes, is(empty()));
}
appender.assertAllExpectationsMatched();
}
Expand Down

0 comments on commit f5b356d

Please sign in to comment.