loadPersistedState should happen outside of dbm constructor

Also, add stub to logger in tests.

This fixes some occasionally failing tests on main.
This commit is contained in:
Andrew Eisenberg
2022-10-14 09:25:11 -07:00
parent 0354b1caac
commit 0885a22984
4 changed files with 17 additions and 5 deletions

View File

@@ -559,9 +559,6 @@ export class DatabaseManager extends DisposableObject {
super();
qs.onStart(this.reregisterDatabases.bind(this));
// Let this run async.
void this.loadPersistedState();
}
public async openDatabase(
@@ -691,7 +688,7 @@ export class DatabaseManager extends DisposableObject {
return item;
}
private async loadPersistedState(): Promise<void> {
public async loadPersistedState(): Promise<void> {
return withProgress({
location: vscode.ProgressLocation.Notification
},

View File

@@ -452,6 +452,10 @@ async function activateWithInstalledDistribution(
void logger.log('Initializing database manager.');
const dbm = new DatabaseManager(ctx, qs, cliServer, logger);
// Let this run async.
void dbm.loadPersistedState();
ctx.subscriptions.push(dbm);
void logger.log('Initializing database panel.');
const databaseUI = new DatabaseUI(

View File

@@ -77,7 +77,9 @@ describe('databases', () => {
},
resolveDatabase: resolveDatabaseSpy
} as unknown as CodeQLCliServer,
{} as Logger,
{
log: () => { /**/ }
} as unknown as Logger,
);
// Unfortunately, during a test it is not possible to convert from

View File

@@ -12,3 +12,12 @@ chai.use(sinonChai);
export function run(): Promise<void> {
return runTestsInDirectory(__dirname);
}
process.addListener('unhandledRejection', (reason) => {
if (reason instanceof Error && reason.message === 'Canceled') {
console.log('Cancellation requested after the test has ended.');
process.exit(0);
} else {
fail(String(reason));
}
});