Fix tests: accurately wait for all threads while testing "All" suspend policy

This commit is contained in:
Elizaveta Shashkova
2016-09-23 15:17:14 +03:00
parent c9cb2c65b7
commit b6538eff38
3 changed files with 20 additions and 4 deletions
+2 -2
View File
@@ -3,14 +3,14 @@ from time import sleep
def fun1(n):
for i in range(1000):
while True:
sleep(0.01)
print("finished fun1()", n)
def fun2(m):
sleep(2)
for i in range(1000):
while True:
sleep(0.01) #breakpoint
print("finished fun2()", m)
@@ -992,7 +992,7 @@ public class PythonDebuggerTest extends PyEnvTestCase {
@Override
public void testing() throws Exception {
waitForPause();
waitForAllThreadsPause();
eval("m").hasValue("42");
assertNull(getRunningThread());
resume();
@@ -39,6 +39,7 @@ import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.ServerSocket;
import java.util.concurrent.Semaphore;
@@ -167,7 +168,7 @@ public class PyDebuggerTask extends PyBaseDebuggerTask {
myPausedSemaphore = new Semaphore(0);
mySession.addSessionListener(new XDebugSessionAdapter() {
mySession.addSessionListener(new XDebugSessionListener() {
@Override
public void sessionPaused() {
if (myPausedSemaphore != null) {
@@ -195,6 +196,21 @@ public class PyDebuggerTask extends PyBaseDebuggerTask {
myMultiprocessDebug = multiprocessDebug;
}
protected void waitForAllThreadsPause() throws InterruptedException, InvocationTargetException {
waitForPause();
Assert.assertTrue(String.format("All threads didn't stop within timeout\n" +
"Output: %s", output()), waitForAllThreads());
XDebuggerTestUtil.waitForSwing();
}
protected boolean waitForAllThreads() throws InterruptedException {
long until = System.currentTimeMillis() + NORMAL_TIMEOUT;
while (System.currentTimeMillis() < until && getRunningThread() != null) {
Thread.sleep(1000);
}
return getRunningThread() == null;
}
@Override
protected void disposeDebugProcess() throws InterruptedException {
if (myDebugProcess != null) {