Skip to content

Commit de1397c

Browse files
committed
Cleanup named pipe when debugging
1 parent c927bc7 commit de1397c

File tree

1 file changed

+114
-112
lines changed

1 file changed

+114
-112
lines changed

Diff for: src/TestExplorer/TestRunner.ts

+114-112
Original file line numberDiff line numberDiff line change
@@ -503,139 +503,141 @@ export class TestRunner {
503503
? `\\\\.\\pipe\\vscodemkfifo-${Date.now()}`
504504
: path.join(os.tmpdir(), `vscodemkfifo-${Date.now()}`);
505505

506-
if (this.testArgs.hasSwiftTestingTests) {
507-
const swiftTestBuildConfig =
508-
await LaunchConfigurations.createLaunchConfigurationForSwiftTesting(
509-
this.testArgs.swiftTestArgs,
510-
this.folderContext,
511-
fifoPipePath
512-
);
513-
514-
if (swiftTestBuildConfig !== null) {
515-
// given we have already run a build task there is no need to have a pre launch task
516-
// to build the tests
517-
swiftTestBuildConfig.preLaunchTask = undefined;
518-
519-
// output test build configuration
520-
if (configuration.diagnostics) {
521-
const configJSON = JSON.stringify(swiftTestBuildConfig);
522-
this.workspaceContext.outputChannel.logDiagnostic(
523-
`swift-testing Debug Config: ${configJSON}`,
524-
this.folderContext.name
506+
await TemporaryFolder.withNamedTemporaryFile(fifoPipePath, async () => {
507+
if (this.testArgs.hasSwiftTestingTests) {
508+
const swiftTestBuildConfig =
509+
await LaunchConfigurations.createLaunchConfigurationForSwiftTesting(
510+
this.testArgs.swiftTestArgs,
511+
this.folderContext,
512+
fifoPipePath
525513
);
526-
}
527-
// Watch the pipe for JSONL output and parse the events into test explorer updates.
528-
// The await simply waits for the watching to be configured.
529-
await this.swiftTestOutputParser.watch(fifoPipePath, runState);
530514

531-
buildConfigs.push(swiftTestBuildConfig);
532-
}
533-
}
515+
if (swiftTestBuildConfig !== null) {
516+
// given we have already run a build task there is no need to have a pre launch task
517+
// to build the tests
518+
swiftTestBuildConfig.preLaunchTask = undefined;
534519

535-
// create launch config for testing
536-
if (this.testArgs.hasXCTests) {
537-
const xcTestBuildConfig =
538-
await LaunchConfigurations.createLaunchConfigurationForXCTestTesting(
539-
this.testArgs.xcTestArgs,
540-
this.workspaceContext,
541-
this.folderContext,
542-
true
543-
);
520+
// output test build configuration
521+
if (configuration.diagnostics) {
522+
const configJSON = JSON.stringify(swiftTestBuildConfig);
523+
this.workspaceContext.outputChannel.logDiagnostic(
524+
`swift-testing Debug Config: ${configJSON}`,
525+
this.folderContext.name
526+
);
527+
}
528+
// Watch the pipe for JSONL output and parse the events into test explorer updates.
529+
// The await simply waits for the watching to be configured.
530+
await this.swiftTestOutputParser.watch(fifoPipePath, runState);
544531

545-
if (xcTestBuildConfig !== null) {
546-
// given we have already run a build task there is no need to have a pre launch task
547-
// to build the tests
548-
xcTestBuildConfig.preLaunchTask = undefined;
549-
550-
// output test build configuration
551-
if (configuration.diagnostics) {
552-
const configJSON = JSON.stringify(xcTestBuildConfig);
553-
this.workspaceContext.outputChannel.logDiagnostic(
554-
`XCTest Debug Config: ${configJSON}`,
555-
this.folderContext.name
556-
);
532+
buildConfigs.push(swiftTestBuildConfig);
557533
}
558-
559-
buildConfigs.push(xcTestBuildConfig);
560534
}
561-
}
562535

563-
const validBuildConfigs = buildConfigs.filter(
564-
config => config !== null
565-
) as vscode.DebugConfiguration[];
536+
// create launch config for testing
537+
if (this.testArgs.hasXCTests) {
538+
const xcTestBuildConfig =
539+
await LaunchConfigurations.createLaunchConfigurationForXCTestTesting(
540+
this.testArgs.xcTestArgs,
541+
this.workspaceContext,
542+
this.folderContext,
543+
true
544+
);
566545

567-
const subscriptions: vscode.Disposable[] = [];
546+
if (xcTestBuildConfig !== null) {
547+
// given we have already run a build task there is no need to have a pre launch task
548+
// to build the tests
549+
xcTestBuildConfig.preLaunchTask = undefined;
568550

569-
const debugRuns = validBuildConfigs.map(config => {
570-
return () =>
571-
new Promise<void>((resolve, reject) => {
572-
// add cancelation
573-
const startSession = vscode.debug.onDidStartDebugSession(session => {
551+
// output test build configuration
552+
if (configuration.diagnostics) {
553+
const configJSON = JSON.stringify(xcTestBuildConfig);
574554
this.workspaceContext.outputChannel.logDiagnostic(
575-
"Start Test Debugging",
555+
`XCTest Debug Config: ${configJSON}`,
576556
this.folderContext.name
577557
);
578-
LoggingDebugAdapterTracker.setDebugSessionCallback(session, output => {
579-
this.testRun.appendOutput(output);
580-
this.xcTestOutputParser.parseResult(output, runState);
581-
});
582-
const cancellation = token.onCancellationRequested(() => {
558+
}
559+
560+
buildConfigs.push(xcTestBuildConfig);
561+
}
562+
}
563+
564+
const validBuildConfigs = buildConfigs.filter(
565+
config => config !== null
566+
) as vscode.DebugConfiguration[];
567+
568+
const subscriptions: vscode.Disposable[] = [];
569+
570+
const debugRuns = validBuildConfigs.map(config => {
571+
return () =>
572+
new Promise<void>((resolve, reject) => {
573+
// add cancelation
574+
const startSession = vscode.debug.onDidStartDebugSession(session => {
583575
this.workspaceContext.outputChannel.logDiagnostic(
584-
"Test Debugging Cancelled",
576+
"Start Test Debugging",
585577
this.folderContext.name
586578
);
587-
vscode.debug.stopDebugging(session);
579+
LoggingDebugAdapterTracker.setDebugSessionCallback(session, output => {
580+
this.testRun.appendOutput(output);
581+
this.xcTestOutputParser.parseResult(output, runState);
582+
});
583+
const cancellation = token.onCancellationRequested(() => {
584+
this.workspaceContext.outputChannel.logDiagnostic(
585+
"Test Debugging Cancelled",
586+
this.folderContext.name
587+
);
588+
vscode.debug.stopDebugging(session);
589+
});
590+
subscriptions.push(cancellation);
588591
});
589-
subscriptions.push(cancellation);
590-
});
591-
subscriptions.push(startSession);
592-
593-
vscode.debug.startDebugging(this.folderContext.workspaceFolder, config).then(
594-
started => {
595-
if (started) {
596-
if (config === validBuildConfigs[0]) {
597-
this.testRun.appendOutput(
598-
`> Test run started at ${new Date().toLocaleString()} <\r\n\r\n`
599-
);
600-
}
601-
// show test results pane
602-
vscode.commands.executeCommand("testing.showMostRecentOutput");
603-
604-
const terminateSession = vscode.debug.onDidTerminateDebugSession(
605-
async () => {
606-
this.workspaceContext.outputChannel.logDiagnostic(
607-
"Stop Test Debugging",
608-
this.folderContext.name
609-
);
610-
// dispose terminate debug handler
611-
subscriptions.forEach(sub => sub.dispose());
612-
592+
subscriptions.push(startSession);
593+
594+
vscode.debug
595+
.startDebugging(this.folderContext.workspaceFolder, config)
596+
.then(
597+
started => {
598+
if (started) {
599+
if (config === validBuildConfigs[0]) {
600+
this.testRun.appendOutput(
601+
`> Test run started at ${new Date().toLocaleString()} <\r\n\r\n`
602+
);
603+
}
604+
// show test results pane
613605
vscode.commands.executeCommand(
614-
"workbench.view.extension.test"
606+
"testing.showMostRecentOutput"
615607
);
616608

617-
resolve();
609+
const terminateSession =
610+
vscode.debug.onDidTerminateDebugSession(async () => {
611+
this.workspaceContext.outputChannel.logDiagnostic(
612+
"Stop Test Debugging",
613+
this.folderContext.name
614+
);
615+
// dispose terminate debug handler
616+
subscriptions.forEach(sub => sub.dispose());
617+
618+
vscode.commands.executeCommand(
619+
"workbench.view.extension.test"
620+
);
621+
622+
resolve();
623+
});
624+
subscriptions.push(terminateSession);
625+
} else {
626+
subscriptions.forEach(sub => sub.dispose());
627+
reject();
618628
}
619-
);
620-
subscriptions.push(terminateSession);
621-
} else {
622-
subscriptions.forEach(sub => sub.dispose());
623-
reject();
624-
}
625-
},
626-
reason => {
627-
subscriptions.forEach(sub => sub.dispose());
628-
reject(reason);
629-
}
630-
);
631-
});
632-
});
633-
634-
// Run each debugging session sequentially
635-
await debugRuns.reduce((p, fn) => p.then(() => fn()), Promise.resolve());
629+
},
630+
reason => {
631+
subscriptions.forEach(sub => sub.dispose());
632+
reject(reason);
633+
}
634+
);
635+
});
636+
});
636637

637-
// If we created a named pipe for this run then clean it up.
638-
await asyncfs.rm(fifoPipePath, { force: true });
638+
// Run each debugging session sequentially
639+
await debugRuns.reduce((p, fn) => p.then(() => fn()), Promise.resolve());
640+
});
639641
}
640642

641643
setTestsEnqueued() {

0 commit comments

Comments
 (0)