Skip to content

Commit 204f5d0

Browse files
committed
Fixup several test issues
1 parent eac6127 commit 204f5d0

File tree

9 files changed

+158
-110
lines changed

9 files changed

+158
-110
lines changed

src/BackgroundCompilation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class BackgroundCompilation implements vscode.Disposable {
2626
private workspaceFileWatcher?: vscode.FileSystemWatcher;
2727
private configurationEventDisposable?: vscode.Disposable;
2828
private disposables: vscode.Disposable[] = [];
29+
private _disposed = false;
2930

3031
constructor(private folderContext: FolderContext) {
3132
// We only want to configure the file watcher if background compilation is enabled.
@@ -59,7 +60,9 @@ export class BackgroundCompilation implements vscode.Disposable {
5960
this.workspaceFileWatcher.onDidChange(
6061
debounce(
6162
() => {
62-
void this.runTask();
63+
if (!this._disposed) {
64+
void this.runTask();
65+
}
6366
},
6467
100 /* 10 times per second */,
6568
{ trailing: true }
@@ -73,6 +76,7 @@ export class BackgroundCompilation implements vscode.Disposable {
7376
}
7477

7578
dispose() {
79+
this._disposed = true;
7680
this.configurationEventDisposable?.dispose();
7781
this.disposables.forEach(disposable => disposable.dispose());
7882
}

src/FolderContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export class FolderContext implements vscode.Disposable {
7070
this.packageWatcher.dispose();
7171
this.testExplorer?.dispose();
7272
this.backgroundCompilation.dispose();
73+
this.taskQueue.dispose();
7374
}
7475

7576
/**

src/debugger/buildConfig.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ export class TestingConfigurationFactory {
414414
if (xcTestPath === undefined) {
415415
return null;
416416
}
417+
const toolchain = this.ctx.toolchain;
417418
return {
418419
...baseConfig,
419420
program: path.join(xcTestPath, "xctest"),
@@ -423,6 +424,16 @@ export class TestingConfigurationFactory {
423424
env: {
424425
...this.testEnv,
425426
...this.sanitizerRuntimeEnvironment,
427+
...(toolchain.swiftVersion.isGreaterThanOrEqual(
428+
new Version(6, 2, 0)
429+
)
430+
? {
431+
// Starting in 6.2 we need to provide libTesting.dylib for xctests
432+
DYLD_FRAMEWORK_PATH:
433+
toolchain.swiftTestingFrameworkPath(),
434+
DYLD_LIBRARY_PATH: toolchain.swiftTestingLibraryPath(),
435+
}
436+
: {}),
426437
SWIFT_TESTING_ENABLED: "0",
427438
},
428439
};

src/tasks/TaskQueue.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class QueuedOperation {
163163
*
164164
* Queue swift task operations to be executed serially
165165
*/
166-
export class TaskQueue {
166+
export class TaskQueue implements vscode.Disposable {
167167
queue: QueuedOperation[];
168168
activeOperation?: QueuedOperation;
169169
workspaceContext: WorkspaceContext;
@@ -176,6 +176,11 @@ export class TaskQueue {
176176
this.disabled = false;
177177
}
178178

179+
dispose() {
180+
this.queue = [];
181+
this.activeOperation = undefined;
182+
}
183+
179184
/**
180185
* Add operation to queue
181186
* @param operation Operation to queue

test/integration-tests/FolderContext.test.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { activateExtensionForSuite, getRootWorkspaceFolder } from "./utilities/t
2626

2727
suite("FolderContext Error Handling Test Suite", () => {
2828
let workspaceContext: WorkspaceContext;
29+
let folderContext: FolderContext | undefined;
2930
let swiftToolchainCreateStub: MockedFunction<typeof SwiftToolchain.create>;
3031
const showToolchainError = mockGlobalValue(toolchain, "showToolchainError");
3132

@@ -38,6 +39,7 @@ suite("FolderContext Error Handling Test Suite", () => {
3839
});
3940

4041
afterEach(() => {
42+
folderContext?.dispose();
4143
restore();
4244
});
4345

@@ -52,11 +54,7 @@ suite("FolderContext Error Handling Test Suite", () => {
5254
const workspaceFolder = getRootWorkspaceFolder();
5355
const testFolder = testAssetUri("package2");
5456

55-
const folderContext = await FolderContext.create(
56-
testFolder,
57-
workspaceFolder,
58-
workspaceContext
59-
);
57+
folderContext = await FolderContext.create(testFolder, workspaceFolder, workspaceContext);
6058

6159
assert.ok(folderContext, "FolderContext should be created despite toolchain failure");
6260
assert.strictEqual(
@@ -99,11 +97,7 @@ suite("FolderContext Error Handling Test Suite", () => {
9997
const showToolchainErrorStub = stub().resolves(true);
10098
showToolchainError.setValue(showToolchainErrorStub);
10199

102-
const folderContext = await FolderContext.create(
103-
testFolder,
104-
workspaceFolder,
105-
workspaceContext
106-
);
100+
folderContext = await FolderContext.create(testFolder, workspaceFolder, workspaceContext);
107101

108102
// Assert: FolderContext should be created successfully
109103
assert.ok(folderContext, "FolderContext should be created after retry");
@@ -146,11 +140,7 @@ suite("FolderContext Error Handling Test Suite", () => {
146140
const showToolchainErrorStub = stub().resolves(true);
147141
showToolchainError.setValue(showToolchainErrorStub);
148142

149-
const folderContext = await FolderContext.create(
150-
testFolder,
151-
workspaceFolder,
152-
workspaceContext
153-
);
143+
folderContext = await FolderContext.create(testFolder, workspaceFolder, workspaceContext);
154144

155145
assert.ok(
156146
folderContext,

test/integration-tests/language/LanguageClientIntegration.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ async function buildProject(ctx: WorkspaceContext, name: string) {
3030
await waitForNoRunningTasks();
3131
const folderContext = await folderInRootWorkspace(name, ctx);
3232
const task = await createBuildAllTask(folderContext);
33+
task.definition.dontTriggerTestDiscovery = true;
3334
const { exitCode, output } = await executeTaskAndWaitForResult(task);
3435
expect(exitCode, `${output}`).to.equal(0);
3536
return folderContext;

test/integration-tests/testexplorer/TestExplorerIntegration.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
activateExtensionForSuite,
4040
folderInRootWorkspace,
4141
updateSettings,
42+
withLogging,
4243
} from "../utilities/testutilities";
4344
import {
4445
assertContains,
@@ -60,19 +61,29 @@ tag("large").suite("Test Explorer Suite", function () {
6061
activateExtensionForSuite({
6162
async setup(ctx) {
6263
workspaceContext = ctx;
63-
folderContext = await folderInRootWorkspace("defaultPackage", workspaceContext);
64+
const logger = withLogging(ctx.logger);
65+
folderContext = await logger("Locating defaultPackage folder in root workspace", () =>
66+
folderInRootWorkspace("defaultPackage", workspaceContext)
67+
);
6468

6569
if (!folderContext) {
6670
throw new Error("Unable to find test explorer");
6771
}
6872

69-
testExplorer = await folderContext.resolvedTestExplorer;
73+
testExplorer = await logger(
74+
"Waiting for test explorer to resolve",
75+
() => folderContext.resolvedTestExplorer
76+
);
7077

71-
await executeTaskAndWaitForResult(await createBuildAllTask(folderContext));
78+
await logger("Executing build all task", async () =>
79+
executeTaskAndWaitForResult(await createBuildAllTask(folderContext))
80+
);
7281

7382
// Set up the listener before bringing the text explorer in to focus,
7483
// which starts searching the workspace for tests.
75-
await waitForTestExplorerReady(testExplorer);
84+
await logger("Waiting for test explorer to be ready", () =>
85+
waitForTestExplorerReady(testExplorer)
86+
);
7687
},
7788
requiresLSP: true,
7889
requiresDebugger: true,

0 commit comments

Comments
 (0)