1
0
Эх сурвалжийг харах

Fix race in SpawnerNoBootstrapTests (#108416)

Simon Cooper 1 жил өмнө
parent
commit
f5b356d11c

+ 9 - 7
qa/no-bootstrap-tests/src/test/java/org/elasticsearch/bootstrap/SpawnerNoBootstrapTests.java

@@ -39,8 +39,10 @@ import java.util.concurrent.CountDownLatch;
 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.
@@ -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
@@ -85,8 +87,8 @@ public class SpawnerNoBootstrapTests extends LuceneTestCase {
                 && event.getLevel().equals(Level.WARN)
                 && event.getMessage().getFormattedMessage().equals(expectedMessage)) {
                 saw = true;
+                matched.countDown();
             }
-            matchCalledLatch.countDown();
         }
 
         @Override
@@ -130,7 +132,7 @@ public class SpawnerNoBootstrapTests extends LuceneTestCase {
 
         try (Spawner spawner = new Spawner()) {
             spawner.spawnNativeControllers(environment);
-            assertThat(spawner.getProcesses(), hasSize(0));
+            assertThat(spawner.getProcesses(), is(empty()));
         }
     }
 
@@ -229,7 +231,7 @@ public class SpawnerNoBootstrapTests extends LuceneTestCase {
                 // 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();
         }