Skip to content

Commit 60f3262

Browse files
committed
add test to ensure that temp directory is created and removed
1 parent a9a0893 commit 60f3262

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

packages/bson-bench/test/unit/task.test.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,71 @@ describe('Task', function () {
115115
expect(maybeError).to.be.instanceOf(Error);
116116
expect(maybeError).to.have.property('message', 'failed to serialize input object');
117117
});
118+
119+
it('deletes the temp directory', async function () {
120+
const task = new Task({
121+
documentPath: 'test/documents/array.json',
122+
library: 'bson@5',
123+
operation: 'deserialize',
124+
warmup: 100,
125+
iterations: 100,
126+
options: {}
127+
});
128+
129+
// bson throws error when passed array as top-level input
130+
const maybeError = await task.run().catch(e => e);
131+
132+
expect(maybeError).to.be.instanceOf(Error);
133+
expect(maybeError).to.have.property('message', 'failed to serialize input object');
134+
135+
const tmpdirExists = await exists(Task.packageInstallLocation);
136+
expect(tmpdirExists).to.be.false;
137+
});
138+
});
139+
140+
it('creates a temp directory for packages', async function () {
141+
const task = new Task({
142+
documentPath: 'test/documents/long_largeArray.json',
143+
library: 'bson@5',
144+
operation: 'deserialize',
145+
warmup: 100,
146+
iterations: 10000,
147+
options: {}
148+
});
149+
150+
const checkForDirectory = async () => {
151+
for (let i = 0; i < 10; i++) {
152+
if (await exists(Task.packageInstallLocation)) return true;
153+
}
154+
return false;
155+
};
156+
const taskRunPromise = task.run().catch(e => e);
157+
158+
const result = await Promise.race([checkForDirectory(), taskRunPromise]);
159+
expect(typeof result).to.equal('boolean');
160+
expect(result).to.be.true;
161+
162+
const taskRunResult = await taskRunPromise;
163+
expect(taskRunResult).to.not.be.instanceOf(Error);
164+
});
165+
166+
context('after completing successfully', function () {
167+
it('deletes the temp directory', async function () {
168+
const task = new Task({
169+
documentPath: 'test/documents/long_largeArray.json',
170+
library: 'bson@5',
171+
operation: 'deserialize',
172+
warmup: 100,
173+
iterations: 100,
174+
options: {}
175+
});
176+
177+
const maybeError = await task.run().catch(e => e);
178+
expect(maybeError).to.not.be.instanceOf(Error);
179+
180+
const tmpdirExists = await exists(Task.packageInstallLocation);
181+
expect(tmpdirExists).to.be.false;
182+
});
118183
});
119184
});
120185

0 commit comments

Comments
 (0)