aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process-monitor
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-12 18:09:22 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-12 18:09:22 +0200
commit694593579b492c33a67b3747a9d8815eac88da7a (patch)
tree84529eb8203f82c8cd62d617cb497c287e3e5294 /server/sonar-process-monitor
parent0dfdd2d05bedf3effc81e5686c4f1fcb28308d8f (diff)
downloadsonarqube-694593579b492c33a67b3747a9d8815eac88da7a.tar.gz
sonarqube-694593579b492c33a67b3747a9d8815eac88da7a.zip
SONAR-4898 improve stability of WatcherThreadTest on slow machines
Diffstat (limited to 'server/sonar-process-monitor')
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/WatcherThreadTest.java10
1 files changed, 8 insertions, 2 deletions
diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/WatcherThreadTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/WatcherThreadTest.java
index 86f3a47e6ff..251dcdb21ea 100644
--- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/WatcherThreadTest.java
+++ b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/WatcherThreadTest.java
@@ -24,6 +24,8 @@ import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import java.util.concurrent.atomic.AtomicBoolean;
+
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -33,9 +35,11 @@ public class WatcherThreadTest {
@Test(timeout = 10000L)
public void kill_process_if_watcher_is_interrupted() throws Exception {
ProcessRef ref = mock(ProcessRef.class, Mockito.RETURNS_DEEP_STUBS);
+ final AtomicBoolean waiting = new AtomicBoolean(false);
when(ref.getProcess().waitFor()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
+ waiting.set(true);
Thread.sleep(Long.MAX_VALUE);
return 0;
}
@@ -44,9 +48,11 @@ public class WatcherThreadTest {
WatcherThread watcher = new WatcherThread(ref, monitor);
watcher.start();
- Thread.sleep(50L);
- watcher.interrupt();
+ while (!waiting.get()) {
+ Thread.sleep(50L);
+ }
+ watcher.interrupt();
verify(ref).hardKill();
}
}