提交 b49019f1 authored 作者: Noel Grandin's avatar Noel Grandin

add watchdog when running tests

to give us a thread dump when they get stuck
上级 6ca8e8dd
...@@ -16,7 +16,6 @@ import java.util.ArrayList; ...@@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import org.h2.mvstore.db.MVTable; import org.h2.mvstore.db.MVTable;
/** /**
...@@ -60,16 +59,27 @@ public class ThreadDeadlockDetector { ...@@ -60,16 +59,27 @@ public class ThreadDeadlockDetector {
* information. * information.
*/ */
void checkForDeadlocks() { void checkForDeadlocks() {
long[] ids = threadBean.findDeadlockedThreads(); long[] deadlockedThreadIds = threadBean.findDeadlockedThreads();
if (ids == null) { if (deadlockedThreadIds == null) {
return; return;
} }
dumpThreadsAndLocks("ThreadDeadlockDetector - deadlock found :",
threadBean, deadlockedThreadIds);
}
public static void dumpAllThreadsAndLocks(String msg) {
final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
final long[] allThreadIds = threadBean.getAllThreadIds();
dumpThreadsAndLocks(msg, threadBean, allThreadIds);
}
private static void dumpThreadsAndLocks(String msg, ThreadMXBean threadBean, long[] threadIds)
{
final StringWriter stringWriter = new StringWriter(); final StringWriter stringWriter = new StringWriter();
final PrintWriter print = new PrintWriter(stringWriter); final PrintWriter print = new PrintWriter(stringWriter);
print.println("ThreadDeadlockDetector - deadlock found :"); print.println(msg);
final ThreadInfo[] infos = threadBean.getThreadInfo(ids, true, true); final ThreadInfo[] infos = threadBean.getThreadInfo(threadIds, true, true);
final HashMap<Long, String> tableWaitingForLockMap = final HashMap<Long, String> tableWaitingForLockMap =
MVTable.WAITING_FOR_LOCK.getSnapshotOfAllThreads(); MVTable.WAITING_FOR_LOCK.getSnapshotOfAllThreads();
final HashMap<Long, ArrayList<String>> tableExclusiveLocksMap = final HashMap<Long, ArrayList<String>> tableExclusiveLocksMap =
......
...@@ -9,6 +9,7 @@ import java.lang.management.ManagementFactory; ...@@ -9,6 +9,7 @@ import java.lang.management.ManagementFactory;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Properties; import java.util.Properties;
import java.util.TimerTask;
import org.h2.Driver; import org.h2.Driver;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.store.fs.FilePathRec; import org.h2.store.fs.FilePathRec;
...@@ -224,6 +225,7 @@ import org.h2.util.New; ...@@ -224,6 +225,7 @@ import org.h2.util.New;
import org.h2.util.Profiler; import org.h2.util.Profiler;
import org.h2.util.StringUtils; import org.h2.util.StringUtils;
import org.h2.util.Task; import org.h2.util.Task;
import org.h2.util.ThreadDeadlockDetector;
import org.h2.util.Utils; import org.h2.util.Utils;
/** /**
...@@ -920,7 +922,20 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -920,7 +922,20 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
// tests.add(test); // tests.add(test);
// run directly for now, because concurrently running tests // run directly for now, because concurrently running tests
// fails on Raspberry Pi quite often (seems to be a JVM problem) // fails on Raspberry Pi quite often (seems to be a JVM problem)
test.runTest(this);
// event queue watchdog for tests that get stuck when running in Jenkins CI
final java.util.Timer watchdog = new java.util.Timer();
watchdog.schedule(new TimerTask() {
@Override
public void run() {
ThreadDeadlockDetector.dumpAllThreadsAndLocks("test watchdog timed out");
}
}, 5 * 60 * 1000); // 5 minutes
try {
test.runTest(this);
} finally {
watchdog.cancel();
}
} }
private void runAddedTests() { private void runAddedTests() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论