Skip to content

Commit 78268cd

Browse files
committed
fixup: allow for failed metadata insertions
1 parent 5514654 commit 78268cd

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/mongodb-runner/src/mongoserver.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ interface SerializedServerProperties {
3030
port?: number;
3131
dbPath?: string;
3232
startTime: string;
33+
hasInsertedMetadataCollEntry: boolean;
3334
}
3435

3536
export class MongoServer {
@@ -41,6 +42,7 @@ export class MongoServer {
4142
private dbPath?: string;
4243
private closing = false;
4344
private startTime = new Date().toISOString();
45+
private hasInsertedMetadataCollEntry = false;
4446

4547
private constructor() {
4648
/* see .start() */
@@ -53,6 +55,7 @@ export class MongoServer {
5355
port: this.port,
5456
dbPath: this.dbPath,
5557
startTime: this.startTime,
58+
hasInsertedMetadataCollEntry: this.hasInsertedMetadataCollEntry,
5659
};
5760
}
5861

@@ -253,7 +256,7 @@ export class MongoServer {
253256
srv.port = port;
254257
const buildInfoError = await srv._populateBuildInfo('insert-new');
255258
if (buildInfoError) {
256-
throw buildInfoError;
259+
debug('failed to get buildInfo', buildInfoError);
257260
}
258261
} catch (err) {
259262
await srv.close();
@@ -305,12 +308,21 @@ export class MongoServer {
305308
]);
306309
const runnerColl = client
307310
.db(isMongoS ? 'config' : 'local')
308-
.collection<SerializedServerProperties>('mongodbrunner');
311+
.collection<
312+
Omit<SerializedServerProperties, 'hasInsertedMetadataCollEntry'>
313+
>('mongodbrunner');
309314
debug('ensuring metadata collection entry', insertedInfo, { isMongoS });
310315
if (mode === 'insert-new') {
311316
await runnerColl.insertOne(insertedInfo);
312317
debug('inserted metadata collection entry', insertedInfo);
318+
this.hasInsertedMetadataCollEntry = true;
313319
} else {
320+
if (!this.hasInsertedMetadataCollEntry) {
321+
debug(
322+
'skipping metadata collection match check as we never inserted metadata',
323+
);
324+
return;
325+
}
314326
const match = await runnerColl.findOne();
315327
debug('read metadata collection entry', insertedInfo, match);
316328
if (!match) {

0 commit comments

Comments
 (0)