serialize test db shutdown

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2023-09-18 14:31:19 +02:00
parent 474cd71ab8
commit eb1594da58
3 changed files with 53 additions and 34 deletions
@@ -276,19 +276,28 @@ export class TestDatabases {
private async shutdown() {
const instances = [...this.instanceById.values()];
await Promise.all(
instances.map(async ({ stopContainer, connections }) => {
this.instanceById.clear();
for (const { stopContainer, connections, databaseManager } of instances) {
for (const connection of connections) {
try {
await Promise.all(connections.map(c => c.destroy()));
} catch {
// ignore
await connection.destroy();
} catch (error) {
console.warn(`TestDatabases: Failed to destroy connection`, {
connection,
error,
});
}
try {
await stopContainer?.();
} catch {
// ignore
}
}),
);
}
try {
await stopContainer?.();
} catch (error) {
console.warn(`TestDatabases: Failed to stop container`, {
databaseManager,
error,
});
}
}
}
}