mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
fix(run): debug Maven tests from the gutter and attach when Surefire starts the fork (#2684)
The run gutter and context menu offered Debug only for configurations with a debug plan or adapter, so Maven / Gradle tests (debugged through a JDWP agent) had none. Debugging a Maven test attached to the pinned Surefire port right away and java-debug's 30-second retry could run out while Maven recompiled; it now attaches when Maven prints the T E S T S banner just before starting the fork. A failed attach to a JVM started for the debugger now stops that run (as for Python), so its suspended JVM doesn't keep it alive. Fixes #2656
This commit is contained in:
@@ -86,6 +86,13 @@ export function jdwpLaunch(config: RunConfig, jdwpPort?: number): RunConfig | nu
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Surefire / Failsafe print this banner just before they start the forked test JVM. It comes from
|
||||
* Maven itself, so unlike the fork's "Listening" line it is not held back until the tests run.
|
||||
*/
|
||||
const SGR = /\x1b\[[0-9;]*m/g; // eslint-disable-line no-control-regex
|
||||
export const isTestForkBanner = (line: string) => /^(?:\[INFO\])?\s*T E S T S$/.test(line.replace(SGR, "").trim());
|
||||
|
||||
/** A Maven test launch: its Surefire / Failsafe fork holds the "Listening" line, so pin its JDWP port. */
|
||||
function needsPinnedPort(config: RunConfig): boolean {
|
||||
if (config.kind !== "maven" && !/(^|\/)mvnw?(\.cmd)?$/.test(config.command)) return false;
|
||||
@@ -119,7 +126,9 @@ export async function debugWithAgent(config: RunConfig, show?: boolean): Promise
|
||||
launch,
|
||||
show,
|
||||
onLine: (line) => {
|
||||
const port = jdwpListeningPort(line);
|
||||
// The pinned port is attached when the fork starts: java-debug retries the connect for
|
||||
// 30 s, which compiling and resolving dependencies before the tests can use up.
|
||||
const port = jdwpListeningPort(line) ?? (pinned !== null && isTestForkBanner(line) ? pinned : null);
|
||||
if (port === null) return;
|
||||
if (sessionId) attach(port);
|
||||
else waiting.push(port);
|
||||
@@ -127,8 +136,6 @@ export async function debugWithAgent(config: RunConfig, show?: boolean): Promise
|
||||
});
|
||||
if (!session) return true;
|
||||
sessionId = session.id;
|
||||
// The pinned port needs no output line: java-debug retries the attach while the fork starts.
|
||||
if (pinned !== null) attach(pinned);
|
||||
waiting.splice(0).forEach(attach);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user