Skip to content

Commit b54dfe9

Browse files
authored
Fix flaky test: avoid file watcher in db manager tests (#1951)
1 parent 4f588d9 commit b54dfe9

4 files changed

Lines changed: 25 additions & 18 deletions

File tree

extensions/ql-vscode/src/databases/config/db-config-store.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export class DbConfigStore extends DisposableObject {
4242
private configErrors: DbConfigValidationError[];
4343
private configWatcher: chokidar.FSWatcher | undefined;
4444

45-
public constructor(private readonly app: App) {
45+
public constructor(
46+
private readonly app: App,
47+
private readonly shouldWatchConfig = true,
48+
) {
4649
super();
4750

4851
const storagePath = app.workspaceStoragePath || app.globalStoragePath;
@@ -58,7 +61,9 @@ export class DbConfigStore extends DisposableObject {
5861

5962
public async initialize(): Promise<void> {
6063
await this.loadConfig();
61-
this.watchConfig();
64+
if (this.shouldWatchConfig) {
65+
this.watchConfig();
66+
}
6267
}
6368

6469
public dispose(disposeHandler?: DisposeHandler): void {

extensions/ql-vscode/test/unit-tests/databases/config/db-config-store.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe("db config store", () => {
4444
"workspace-databases.json",
4545
);
4646

47-
const configStore = new DbConfigStore(app);
47+
const configStore = new DbConfigStore(app, false);
4848
await configStore.initialize();
4949

5050
expect(await pathExists(configPath)).toBe(true);
@@ -65,7 +65,7 @@ describe("db config store", () => {
6565
extensionPath,
6666
workspaceStoragePath: testDataStoragePath,
6767
});
68-
const configStore = new DbConfigStore(app);
68+
const configStore = new DbConfigStore(app, false);
6969
await configStore.initialize();
7070

7171
const config = configStore.getConfig().value;
@@ -120,7 +120,7 @@ describe("db config store", () => {
120120
workspaceStoragePath: testDataStoragePathWithout,
121121
});
122122

123-
const configStore = new DbConfigStore(app);
123+
const configStore = new DbConfigStore(app, false);
124124
await configStore.initialize();
125125

126126
const config = configStore.getConfig().value;
@@ -134,7 +134,7 @@ describe("db config store", () => {
134134
extensionPath,
135135
workspaceStoragePath: testDataStoragePath,
136136
});
137-
const configStore = new DbConfigStore(app);
137+
const configStore = new DbConfigStore(app, false);
138138
await configStore.initialize();
139139

140140
const config = configStore.getConfig().value;
@@ -155,7 +155,7 @@ describe("db config store", () => {
155155
extensionPath,
156156
workspaceStoragePath: testDataStoragePathInvalid,
157157
});
158-
const configStore = new DbConfigStore(app);
158+
const configStore = new DbConfigStore(app, false);
159159
await configStore.initialize();
160160

161161
expect(app.executeCommand).toBeCalledWith(
@@ -171,7 +171,7 @@ describe("db config store", () => {
171171
extensionPath,
172172
workspaceStoragePath: testDataStoragePath,
173173
});
174-
const configStore = new DbConfigStore(app);
174+
const configStore = new DbConfigStore(app, false);
175175
await configStore.initialize();
176176

177177
expect(app.executeCommand).toBeCalledWith(
@@ -215,7 +215,7 @@ describe("db config store", () => {
215215

216216
await writeJSON(configPath, dbConfig);
217217

218-
const configStore = new DbConfigStore(app);
218+
const configStore = new DbConfigStore(app, false);
219219
await configStore.initialize();
220220

221221
// Rename
@@ -262,7 +262,7 @@ describe("db config store", () => {
262262

263263
await writeJSON(configPath, dbConfig);
264264

265-
const configStore = new DbConfigStore(app);
265+
const configStore = new DbConfigStore(app, false);
266266
await configStore.initialize();
267267

268268
// Rename
@@ -309,7 +309,7 @@ describe("db config store", () => {
309309

310310
await writeJSON(configPath, dbConfig);
311311

312-
const configStore = new DbConfigStore(app);
312+
const configStore = new DbConfigStore(app, false);
313313
await configStore.initialize();
314314

315315
// Rename
@@ -353,7 +353,7 @@ describe("db config store", () => {
353353

354354
await writeJSON(configPath, dbConfig);
355355

356-
const configStore = new DbConfigStore(app);
356+
const configStore = new DbConfigStore(app, false);
357357
await configStore.initialize();
358358

359359
// Rename
@@ -393,7 +393,7 @@ describe("db config store", () => {
393393

394394
await writeJSON(configPath, dbConfig);
395395

396-
const configStore = new DbConfigStore(app);
396+
const configStore = new DbConfigStore(app, false);
397397
await configStore.initialize();
398398

399399
// Remove
@@ -432,7 +432,7 @@ describe("db config store", () => {
432432

433433
await writeJSON(configPath, dbConfig);
434434

435-
const configStore = new DbConfigStore(app);
435+
const configStore = new DbConfigStore(app, false);
436436
await configStore.initialize();
437437

438438
// Remove
@@ -471,7 +471,7 @@ describe("db config store", () => {
471471

472472
await writeJSON(configPath, dbConfig);
473473

474-
const configStore = new DbConfigStore(app);
474+
const configStore = new DbConfigStore(app, false);
475475
await configStore.initialize();
476476

477477
// Remove

extensions/ql-vscode/test/unit-tests/databases/db-manager.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { createMockApp } from "../../__mocks__/appMock";
2020

2121
// Note: Although these are "unit tests" (i.e. not integrating with VS Code), they do
2222
// test the interaction/"integration" between the DbManager and the DbConfigStore.
23-
describe.skip("db manager", () => {
23+
describe("db manager", () => {
2424
let dbManager: DbManager;
2525
let dbConfigStore: DbConfigStore;
2626
let tempWorkspaceStoragePath: string;
@@ -35,7 +35,9 @@ describe.skip("db manager", () => {
3535
workspaceStoragePath: tempWorkspaceStoragePath,
3636
});
3737

38-
dbConfigStore = new DbConfigStore(app);
38+
// We don't need to watch changes to the config file in these tests, so we
39+
// pass `false` to the dbConfigStore constructor.
40+
dbConfigStore = new DbConfigStore(app, false);
3941
dbManager = new DbManager(app, dbConfigStore);
4042
await ensureDir(tempWorkspaceStoragePath);
4143

extensions/ql-vscode/test/vscode-tests/minimal-workspace/databases/db-panel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("db panel", () => {
4343

4444
const app = new ExtensionApp(extensionContext);
4545

46-
dbConfigStore = new DbConfigStore(app);
46+
dbConfigStore = new DbConfigStore(app, false);
4747
dbManager = new DbManager(app, dbConfigStore);
4848
});
4949

0 commit comments

Comments
 (0)