Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(NODE-6559): add 22 to matrix and test on latest #26

Merged
merged 7 commits into from
Dec 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test to ensure that temp directory is created and removed
  • Loading branch information
W-A-James committed Dec 5, 2024
commit 60f3262751d1f3c84d2baecb254e1dcb3510ea16
65 changes: 65 additions & 0 deletions packages/bson-bench/test/unit/task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,71 @@ describe('Task', function () {
expect(maybeError).to.be.instanceOf(Error);
expect(maybeError).to.have.property('message', 'failed to serialize input object');
});

it('deletes the temp directory', async function () {
const task = new Task({
documentPath: 'test/documents/array.json',
library: 'bson@5',
operation: 'deserialize',
warmup: 100,
iterations: 100,
options: {}
});

// bson throws error when passed array as top-level input
const maybeError = await task.run().catch(e => e);

expect(maybeError).to.be.instanceOf(Error);
expect(maybeError).to.have.property('message', 'failed to serialize input object');

const tmpdirExists = await exists(Task.packageInstallLocation);
expect(tmpdirExists).to.be.false;
});
});

it('creates a temp directory for packages', async function () {
const task = new Task({
documentPath: 'test/documents/long_largeArray.json',
library: 'bson@5',
operation: 'deserialize',
warmup: 100,
iterations: 10000,
options: {}
});

const checkForDirectory = async () => {
for (let i = 0; i < 10; i++) {
if (await exists(Task.packageInstallLocation)) return true;
}
return false;
};
const taskRunPromise = task.run().catch(e => e);

const result = await Promise.race([checkForDirectory(), taskRunPromise]);
expect(typeof result).to.equal('boolean');
expect(result).to.be.true;

const taskRunResult = await taskRunPromise;
expect(taskRunResult).to.not.be.instanceOf(Error);
});

context('after completing successfully', function () {
it('deletes the temp directory', async function () {
const task = new Task({
documentPath: 'test/documents/long_largeArray.json',
library: 'bson@5',
operation: 'deserialize',
warmup: 100,
iterations: 100,
options: {}
});

const maybeError = await task.run().catch(e => e);
expect(maybeError).to.not.be.instanceOf(Error);

const tmpdirExists = await exists(Task.packageInstallLocation);
expect(tmpdirExists).to.be.false;
});
});
});

Expand Down
Loading