Skip to content

Commit 28dba24

Browse files
committed
Clean up sleeps and unit test settings
1 parent 2c5a6a0 commit 28dba24

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed

.vscode-test.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import { defineConfig } from "@vscode/test-cli";
2-
import os from "os";
3-
import path from "path";
42

53
export default defineConfig({
64
files: "test/**/*.test.ts",
7-
// The default user data directory had too many characters for the IPC connection on macOS in CI.
5+
// It may break CI but we'll know sooner rather than later
6+
version: "insiders",
87
launchArgs: [
8+
// Other extensions are unnecessary while testing
9+
"--disable-extensions",
10+
// Undocumented but valid option to use a temporary profile for testing
911
"--profile-temp",
10-
"--user-data-dir",
11-
path.join(os.tmpdir(), "vscode-user-data"),
1212
],
1313
workspaceFolder: "test/TestEnvironment.code-workspace",
1414
mocha: {
1515
ui: "bdd", // describe, it, etc.
1616
require: ["esbuild-register"], // transpile TypeScript on-the-fly
17-
slow: 2000, // 2 seconds for slow test
18-
timeout: 60 * 1000, // 10 minutes to allow for debugging
17+
slow: 2 * 1000, // 2 seconds for slow test
18+
timeout: 2 * 60 * 1000, // 2 minutes to allow for debugging
1919
},
2020
});

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { LanguageClientConsumer } from "./languageClientConsumer";
2929
import { Logger } from "./logging";
3030
import { SessionManager } from "./session";
3131
import { getSettings } from "./settings";
32-
import { PowerShellLanguageId } from "./utils";
32+
import { PowerShellLanguageId, sleep } from "./utils";
3333
// The 1DS telemetry key, which is just shared among all Microsoft extensions
3434
// (and isn't sensitive).
3535
const TELEMETRY_KEY =
@@ -257,7 +257,7 @@ function registerWaitForPsesActivationCommand(
257257
return pidContent.toString();
258258
} catch {
259259
// File doesn't exist yet, wait and try again
260-
await new Promise((resolve) => setTimeout(resolve, 1000));
260+
await sleep(200);
261261
}
262262
}
263263
},

src/process.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ export class PowerShellProcess {
315315
}
316316

317317
// Wait a bit and try again.
318-
await utils.sleep(1000);
318+
await utils.sleep(200);
319319
}
320320

321321
this.logger.writeError("Timed out waiting for session file!");

src/session.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export class SessionManager implements Middleware {
319319
try {
320320
// If the stop fails, so will the dispose, I think this is a bug in
321321
// the client library.
322-
await this.languageClient?.stop(3000);
322+
await this.languageClient?.stop(2000);
323323
await this.languageClient?.dispose();
324324
} catch (err) {
325325
this.logger.writeError(
@@ -491,7 +491,7 @@ export class SessionManager implements Middleware {
491491

492492
public async waitUntilStarted(): Promise<void> {
493493
while (this.sessionStatus !== SessionStatus.Running) {
494-
await utils.sleep(300);
494+
await utils.sleep(200);
495495
}
496496
}
497497

@@ -1180,13 +1180,13 @@ Type 'help' to get help.
11801180
) {
11811181
return;
11821182
}
1183-
await utils.sleep(300);
1183+
await utils.sleep(200);
11841184
}
11851185
}
11861186

11871187
private async waitWhileStopping(): Promise<void> {
11881188
while (this.sessionStatus === SessionStatus.Stopping) {
1189-
await utils.sleep(300);
1189+
await utils.sleep(200);
11901190
}
11911191
}
11921192

test/features/DebugSession.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,6 @@ describe("DebugSessionFeature", () => {
656656
});
657657

658658
describe("DebugSessionFeature E2E", function () {
659-
// E2E tests can take a while to run since the debugger has to start up and attach
660-
this.slow(20000);
661659
before(async () => {
662660
// Registers and warms up the debug adapter and the PowerShell Extension Terminal
663661
await ensureEditorServicesIsConnected();

test/features/ISECompatibility.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ describe("ISE compatibility feature", function () {
9494
});
9595

9696
describe("Color theme interactions", function () {
97-
// These tests are slow because they change the user's theme.
98-
this.slow(3000);
9997
beforeEach(enableISEMode);
10098

10199
function assertISESettings(): void {

test/utils.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as path from "path";
66
import * as vscode from "vscode";
77
import type { IPowerShellExtensionClient } from "../src/features/ExternalApi";
88
import type { ILogger } from "../src/logging";
9+
import { sleep } from "../src/utils";
910

1011
// This lets us test the rest of our path assumptions against the baseline of
1112
// this test file existing at `<root>/test/utils.js`.
@@ -64,11 +65,19 @@ export class TestLogger implements ILogger {
6465
export const testLogger = new TestLogger();
6566

6667
export async function ensureExtensionIsActivated(): Promise<IPowerShellExtensionClient> {
67-
const extension = vscode.extensions.getExtension(extensionId);
68-
if (!extension!.isActive) {
69-
await extension!.activate();
68+
let extension = vscode.extensions.getExtension(extensionId);
69+
while (!extension) {
70+
// Wait for VS Code to be ready
71+
testLogger.writeDebug(`Extension ${extensionId} not yet found...`);
72+
await sleep(200);
73+
extension = vscode.extensions.getExtension(extensionId);
74+
// Wait for VS Code to be ready
75+
await sleep(200);
7076
}
71-
return extension!.exports as IPowerShellExtensionClient;
77+
if (!extension.isActive) {
78+
await extension.activate();
79+
}
80+
return extension.exports as IPowerShellExtensionClient;
7281
}
7382

7483
export async function ensureEditorServicesIsConnected(): Promise<IPowerShellExtensionClient> {

0 commit comments

Comments
 (0)