Skip to content

Commit 718c7e4

Browse files
trancexpressiloveeclipse
authored andcommitted
Add timeout to the launch of Java programs in debug tests
Fixes: #870
1 parent a3bf1ad commit 718c7e4

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

org.eclipse.jdt.debug.tests/tests/org/eclipse/jdt/debug/tests/AbstractDebugTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ protected Object launchAndWait(ILaunchConfiguration configuration, DebugEventWai
14301430
* if the event is never received.
14311431
*/
14321432
protected Object launchAndWait(ILaunchConfiguration configuration, String mode, DebugEventWaiter waiter, boolean register) throws CoreException {
1433-
ILaunch launch = configuration.launch(mode, null, false, register);
1433+
ILaunch launch = configuration.launch(mode, new TimeoutMonitor(DEFAULT_TIMEOUT), false, register);
14341434
Object suspendee= waiter.waitForEvent();
14351435
if (suspendee == null) {
14361436
StringBuilder buf = new StringBuilder();
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2026 Simeon Andreev and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Simeon Andreev - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.jdt.debug.tests;
15+
16+
import org.eclipse.core.runtime.IProgressMonitor;
17+
18+
/**
19+
* A progress monitor which reports that the task is cancelled if a timeout occurs. The starting time for the timeout is the creation of the monitor.
20+
*/
21+
public class TimeoutMonitor implements IProgressMonitor {
22+
23+
private final long timeoutMs;
24+
private final long startMs;
25+
26+
TimeoutMonitor(long timeoutMs) {
27+
this.timeoutMs = timeoutMs;
28+
this.startMs = System.currentTimeMillis();
29+
}
30+
31+
@Override
32+
public void beginTask(String name, int totalWork) {
33+
}
34+
35+
@Override
36+
public void done() {
37+
}
38+
39+
@Override
40+
public void internalWorked(double work) {
41+
}
42+
43+
@Override
44+
public boolean isCanceled() {
45+
return System.currentTimeMillis() - startMs > timeoutMs;
46+
}
47+
48+
@Override
49+
public void setCanceled(boolean value) {
50+
throw new UnsupportedOperationException();
51+
}
52+
53+
@Override
54+
public void setTaskName(String name) {
55+
}
56+
57+
@Override
58+
public void subTask(String name) {
59+
}
60+
61+
@Override
62+
public void worked(int work) {
63+
}
64+
65+
}

0 commit comments

Comments
 (0)