From c24758259127f6b582dd3a2ca11ad637ec98e76c Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sat, 20 Jul 2024 15:16:23 +0200 Subject: [PATCH] test: deflake test-blob-file-backed Avoid race conditions by using a different file for each subtest. Fixes: https://github.com/nodejs/node/issues/51860 PR-URL: https://github.com/nodejs/node/pull/53920 Reviewed-By: Richard Lau Reviewed-By: Michael Dawson --- test/parallel/test-blob-file-backed.js | 28 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/test/parallel/test-blob-file-backed.js b/test/parallel/test-blob-file-backed.js index 0532bda07b6e80..24560d9215178c 100644 --- a/test/parallel/test-blob-file-backed.js +++ b/test/parallel/test-blob-file-backed.js @@ -21,13 +21,17 @@ const tmpdir = require('../common/tmpdir'); const testfile = tmpdir.resolve('test-file-backed-blob.txt'); const testfile2 = tmpdir.resolve('test-file-backed-blob2.txt'); const testfile3 = tmpdir.resolve('test-file-backed-blob3.txt'); +const testfile4 = tmpdir.resolve('test-file-backed-blob4.txt'); +const testfile5 = tmpdir.resolve('test-file-backed-blob5.txt'); tmpdir.refresh(); const data = `${'a'.repeat(1000)}${'b'.repeat(2000)}`; writeFileSync(testfile, data); -writeFileSync(testfile2, data.repeat(100)); -writeFileSync(testfile3, ''); +writeFileSync(testfile2, data); +writeFileSync(testfile3, data.repeat(100)); +writeFileSync(testfile4, ''); +writeFileSync(testfile5, ''); (async () => { const blob = await openAsBlob(testfile); @@ -69,7 +73,7 @@ writeFileSync(testfile3, ''); (async () => { // Refs: https://github.com/nodejs/node/issues/47683 - const blob = await openAsBlob(testfile); + const blob = await openAsBlob(testfile2); const res = blob.slice(10, 20); const ab = await res.arrayBuffer(); strictEqual(res.size, ab.byteLength); @@ -82,39 +86,41 @@ writeFileSync(testfile3, ''); const res1 = blob.slice(995, 1005); strictEqual(await res1.text(), data.slice(995, 1005)); + await unlink(testfile2); })().then(common.mustCall()); (async () => { - const blob = await openAsBlob(testfile2); + const blob = await openAsBlob(testfile3); const stream = blob.stream(); const read = async () => { // eslint-disable-next-line no-unused-vars for await (const _ of stream) { - writeFileSync(testfile2, data + 'abc'); + writeFileSync(testfile3, data + 'abc'); } }; await rejects(read(), { name: 'NotReadableError' }); - await unlink(testfile2); + await unlink(testfile3); })().then(common.mustCall()); (async () => { - const blob = await openAsBlob(testfile3); + const blob = await openAsBlob(testfile4); strictEqual(blob.size, 0); strictEqual(await blob.text(), ''); - writeFileSync(testfile3, 'abc'); + writeFileSync(testfile4, 'abc'); await rejects(blob.text(), { name: 'NotReadableError' }); - await unlink(testfile3); + await unlink(testfile4); })().then(common.mustCall()); (async () => { - const blob = await openAsBlob(testfile3); + const blob = await openAsBlob(testfile5); strictEqual(blob.size, 0); - writeFileSync(testfile3, 'abc'); + writeFileSync(testfile5, 'abc'); const stream = blob.stream(); const reader = stream.getReader(); await rejects(() => reader.read(), { name: 'NotReadableError' }); + await unlink(testfile5); })().then(common.mustCall()); (async () => {