mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix tests: accurately wait for all threads while testing "All" suspend policy
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user