Skip to content

Commit be94e47

Browse files
lpincamarco-ippolito
authored andcommitted
test: deflake test-blob-file-backed
Avoid race conditions by using a different file for each subtest. Fixes: #51860 PR-URL: #53920 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent c667fbd commit be94e47

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

test/parallel/test-blob-file-backed.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ const tmpdir = require('../common/tmpdir');
2121
const testfile = tmpdir.resolve('test-file-backed-blob.txt');
2222
const testfile2 = tmpdir.resolve('test-file-backed-blob2.txt');
2323
const testfile3 = tmpdir.resolve('test-file-backed-blob3.txt');
24+
const testfile4 = tmpdir.resolve('test-file-backed-blob4.txt');
25+
const testfile5 = tmpdir.resolve('test-file-backed-blob5.txt');
2426
tmpdir.refresh();
2527

2628
const data = `${'a'.repeat(1000)}${'b'.repeat(2000)}`;
2729

2830
writeFileSync(testfile, data);
29-
writeFileSync(testfile2, data.repeat(100));
30-
writeFileSync(testfile3, '');
31+
writeFileSync(testfile2, data);
32+
writeFileSync(testfile3, data.repeat(100));
33+
writeFileSync(testfile4, '');
34+
writeFileSync(testfile5, '');
3135

3236
(async () => {
3337
const blob = await openAsBlob(testfile);
@@ -69,7 +73,7 @@ writeFileSync(testfile3, '');
6973

7074
(async () => {
7175
// Refs: https://github.com/nodejs/node/issues/47683
72-
const blob = await openAsBlob(testfile);
76+
const blob = await openAsBlob(testfile2);
7377
const res = blob.slice(10, 20);
7478
const ab = await res.arrayBuffer();
7579
strictEqual(res.size, ab.byteLength);
@@ -82,39 +86,41 @@ writeFileSync(testfile3, '');
8286

8387
const res1 = blob.slice(995, 1005);
8488
strictEqual(await res1.text(), data.slice(995, 1005));
89+
await unlink(testfile2);
8590
})().then(common.mustCall());
8691

8792
(async () => {
88-
const blob = await openAsBlob(testfile2);
93+
const blob = await openAsBlob(testfile3);
8994
const stream = blob.stream();
9095
const read = async () => {
9196
// eslint-disable-next-line no-unused-vars
9297
for await (const _ of stream) {
93-
writeFileSync(testfile2, data + 'abc');
98+
writeFileSync(testfile3, data + 'abc');
9499
}
95100
};
96101

97102
await rejects(read(), { name: 'NotReadableError' });
98103

99-
await unlink(testfile2);
104+
await unlink(testfile3);
100105
})().then(common.mustCall());
101106

102107
(async () => {
103-
const blob = await openAsBlob(testfile3);
108+
const blob = await openAsBlob(testfile4);
104109
strictEqual(blob.size, 0);
105110
strictEqual(await blob.text(), '');
106-
writeFileSync(testfile3, 'abc');
111+
writeFileSync(testfile4, 'abc');
107112
await rejects(blob.text(), { name: 'NotReadableError' });
108-
await unlink(testfile3);
113+
await unlink(testfile4);
109114
})().then(common.mustCall());
110115

111116
(async () => {
112-
const blob = await openAsBlob(testfile3);
117+
const blob = await openAsBlob(testfile5);
113118
strictEqual(blob.size, 0);
114-
writeFileSync(testfile3, 'abc');
119+
writeFileSync(testfile5, 'abc');
115120
const stream = blob.stream();
116121
const reader = stream.getReader();
117122
await rejects(() => reader.read(), { name: 'NotReadableError' });
123+
await unlink(testfile5);
118124
})().then(common.mustCall());
119125

120126
(async () => {

0 commit comments

Comments
 (0)