Skip to content

Commit

Permalink
fix: Adds ReplSet shutdown to tests
Browse files Browse the repository at this point in the history
Based on advice from @hasezoey, this adds a shutdown step to the after()
cleanup to ensure all temp files are removed as part of the test
completion step.

ref: nodkz/mongodb-memory-server#666 (comment)
  • Loading branch information
jakobo committed Jun 26, 2022
1 parent 5965015 commit 416606f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion test/e2e.spec.ts
Expand Up @@ -22,6 +22,11 @@ test.before(async (t) => {
t.context.mongo = rs;
});

// shut down replset after test
test.after(async (t) => {
await t.context.mongo.stop();
});

test("Sanity - Can connect to local mongo", async (t) => {
const client = new MongoClient(t.context.mongo.getUri());
await client.connect();
Expand All @@ -45,7 +50,7 @@ test("Creates a queue, adds an item, and sees the result in a processor", async
resolve();
},
{
pollIntervalMs: 1,
pollInterval: 0.1,
}
);
});
Expand Down
9 changes: 7 additions & 2 deletions test/oplog.spec.ts
Expand Up @@ -21,6 +21,11 @@ test.before(async (t) => {
t.context.mongo = rs;
});

// shut down replset after test
test.after(async (t) => {
await t.context.mongo.stop();
});

// Makes sure the oplog is used to minimize polling load
// all other times, we'll a 1ms poll to move through tests as fast as possible
test("Leverages the oplog to minimize polling", async (t) => {
Expand All @@ -36,7 +41,7 @@ test("Leverages the oplog to minimize polling", async (t) => {
},
{
concurrency: 1,
pollIntervalMs: 40000,
pollInterval: 40,
}
);
});
Expand Down Expand Up @@ -65,7 +70,7 @@ test("Won't run without a replica set", async (t) => {
resolve();
},
{
pollIntervalMs: 1,
pollInterval: 0.1,
}
);
queue.events.on("error", (err) => {
Expand Down

0 comments on commit 416606f

Please sign in to comment.