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

test: deflake test-blob-file-backed #53920

Merged
merged 1 commit into from
Jul 20, 2024
Merged
Changes from all commits
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
28 changes: 17 additions & 11 deletions test/parallel/test-blob-file-backed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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 () => {
Expand Down
Loading