aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process-monitor
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-12 20:27:24 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-12 20:27:24 +0200
commit5de5566591c3fa67edee667e482cbde9312227ee (patch)
tree407f48c8db96eac1451da301fe342f571f115338 /server/sonar-process-monitor
parent694593579b492c33a67b3747a9d8815eac88da7a (diff)
downloadsonarqube-5de5566591c3fa67edee667e482cbde9312227ee.tar.gz
sonarqube-5de5566591c3fa67edee667e482cbde9312227ee.zip
SONAR-4898 improve (again) stability of WatcherThreadTest
Diffstat (limited to 'server/sonar-process-monitor')
-rw-r--r--server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/WatcherThreadTest.java16
1 files changed, 2 insertions, 14 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 251dcdb21ea..5c953c1fef9 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,35 +24,23 @@ 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;
+import static org.mockito.Mockito.*;
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;
+ throw new InterruptedException();
}
});
Monitor monitor = mock(Monitor.class);
WatcherThread watcher = new WatcherThread(ref, monitor);
watcher.start();
-
- while (!waiting.get()) {
- Thread.sleep(50L);
- }
- watcher.interrupt();
verify(ref).hardKill();
}
}