Skip to content

Commit 34664c3

Browse files
committed
Add timeout detection to SharedEngineMultithreadingTestBase
1 parent 51bf2a3 commit 34664c3

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/Utils.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -40,8 +40,29 @@
4040
*/
4141
package com.oracle.graal.python.test.integration;
4242

43+
import java.lang.management.ManagementFactory;
44+
import java.lang.management.ThreadInfo;
45+
import java.lang.management.ThreadMXBean;
4346
import java.util.Locale;
4447

4548
public class Utils {
4649
public static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows");
50+
51+
public static String getThreadDump() {
52+
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
53+
ThreadInfo[] threads = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
54+
final String line = "=====================================\n";
55+
StringBuilder sb = new StringBuilder(line);
56+
for (ThreadInfo thread : threads) {
57+
if (thread != null) {
58+
sb.append("-------\n");
59+
sb.append(thread.getThreadName()).append('\n');
60+
sb.append("Thread state:").append(thread.getThreadState()).append('\n');
61+
for (StackTraceElement element : thread.getStackTrace()) {
62+
sb.append(" ").append(element).append('\n');
63+
}
64+
}
65+
}
66+
return sb.append(line).toString();
67+
}
4768
}

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/engine/SharedEngineMultithreadingTestBase.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -50,6 +50,7 @@
5050
import java.util.concurrent.Future;
5151
import java.util.concurrent.ThreadFactory;
5252
import java.util.concurrent.TimeUnit;
53+
import java.util.concurrent.TimeoutException;
5354
import java.util.function.Consumer;
5455

5556
import org.graalvm.polyglot.Context;
@@ -58,6 +59,7 @@
5859

5960
import com.oracle.graal.python.test.integration.CleanupRule;
6061
import com.oracle.graal.python.test.integration.PythonTests;
62+
import com.oracle.graal.python.test.integration.Utils;
6163

6264
/**
6365
* Base class for tests that run in multiple context with a shared engine and in parallel.
@@ -112,8 +114,17 @@ protected static void submitAndWaitAll(ExecutorService service, Task[] tasks) th
112114
}
113115
});
114116
}
117+
boolean wasTimeout = false;
115118
for (Future<?> future : futures) {
116-
future.get();
119+
try {
120+
future.get(2, TimeUnit.MINUTES);
121+
} catch (TimeoutException e) {
122+
wasTimeout = true;
123+
}
124+
}
125+
if (wasTimeout) {
126+
System.err.println(Utils.getThreadDump());
127+
throw new AssertionError("One of the tasks did not finish in 2 minutes");
117128
}
118129
log("All %d futures finished...", tasks.length);
119130
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advanced/LeakTest.java

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -43,8 +43,6 @@
4343
import java.io.IOException;
4444
import java.io.OutputStream;
4545
import java.lang.management.ManagementFactory;
46-
import java.lang.management.ThreadInfo;
47-
import java.lang.management.ThreadMXBean;
4846
import java.nio.file.Files;
4947
import java.nio.file.Path;
5048
import java.util.ArrayList;
@@ -69,6 +67,7 @@
6967
import org.netbeans.lib.profiler.heap.Instance;
7068
import org.netbeans.lib.profiler.heap.JavaClass;
7169

70+
import com.oracle.graal.python.test.integration.Utils;
7271
import com.sun.management.HotSpotDiagnosticMXBean;
7372

7473
public class LeakTest extends AbstractLanguageLauncher {
@@ -127,7 +126,7 @@ private void dumpAndAnalyze() {
127126
}
128127

129128
MBeanServer server = doFullGC();
130-
String threadDump = getThreadDump();
129+
String threadDump = Utils.getThreadDump();
131130
Path dumpFile = dumpHeap(server, keepDump);
132131
boolean fail = checkForLeaks(dumpFile);
133132
if (fail) {
@@ -138,24 +137,6 @@ private void dumpAndAnalyze() {
138137
}
139138
}
140139

141-
private String getThreadDump() {
142-
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
143-
ThreadInfo[] threads = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
144-
final String line = "=====================================\n";
145-
StringBuilder sb = new StringBuilder(line);
146-
for (ThreadInfo thread : threads) {
147-
if (thread != null) {
148-
sb.append("-------\n");
149-
sb.append(thread.getThreadName()).append('\n');
150-
sb.append("Thread state:").append(thread.getThreadState()).append('\n');
151-
for (StackTraceElement element : thread.getStackTrace()) {
152-
sb.append(" ").append(element).append('\n');
153-
}
154-
}
155-
}
156-
return sb.append(line).toString();
157-
}
158-
159140
private boolean checkForLeaks(Path dumpFile) {
160141
boolean fail = false;
161142
try {

0 commit comments

Comments
 (0)