From b6538eff38beb987ce3a99b901435e1b0860b45b Mon Sep 17 00:00:00 2001 From: Elizaveta Shashkova Date: Fri, 23 Sep 2016 15:01:34 +0300 Subject: [PATCH] Fix tests: accurately wait for all threads while testing "All" suspend policy --- python/testData/debug/test_two_threads.py | 4 ++-- .../env/python/PythonDebuggerTest.java | 2 +- .../env/python/debug/PyDebuggerTask.java | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/python/testData/debug/test_two_threads.py b/python/testData/debug/test_two_threads.py index d0d1e75f561c..49d229678ec3 100644 --- a/python/testData/debug/test_two_threads.py +++ b/python/testData/debug/test_two_threads.py @@ -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) diff --git a/python/testSrc/com/jetbrains/env/python/PythonDebuggerTest.java b/python/testSrc/com/jetbrains/env/python/PythonDebuggerTest.java index 665a3f1b21af..a1c9e37f2073 100644 --- a/python/testSrc/com/jetbrains/env/python/PythonDebuggerTest.java +++ b/python/testSrc/com/jetbrains/env/python/PythonDebuggerTest.java @@ -992,7 +992,7 @@ public class PythonDebuggerTest extends PyEnvTestCase { @Override public void testing() throws Exception { - waitForPause(); + waitForAllThreadsPause(); eval("m").hasValue("42"); assertNull(getRunningThread()); resume(); diff --git a/python/testSrc/com/jetbrains/env/python/debug/PyDebuggerTask.java b/python/testSrc/com/jetbrains/env/python/debug/PyDebuggerTask.java index 6065fdd87a02..ba45bee3466e 100644 --- a/python/testSrc/com/jetbrains/env/python/debug/PyDebuggerTask.java +++ b/python/testSrc/com/jetbrains/env/python/debug/PyDebuggerTask.java @@ -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) {