Skip to content

Commit bc84698

Browse files
committed
quic: Adapt blob test to new behaviour
1 parent 83a50c8 commit bc84698

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

test/parallel/test-blob.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,30 +243,33 @@ assert.throws(() => new Blob({}), {
243243
const b = new Blob(Array(10).fill('hello'));
244244
const reader = b.stream().getReader();
245245
const chunks = [];
246+
let byteLength = 0;
246247
while (true) {
247248
const res = await reader.read();
248249
if (res.done) break;
249-
assert.strictEqual(res.value.byteLength, 5);
250+
byteLength += res.value.byteLength;
251+
assert.ok(res.value.byteLength >= 5);
250252
chunks.push(res.value);
251253
}
252-
assert.strictEqual(chunks.length, 10);
254+
assert.strictEqual(byteLength, 50);
253255
})().then(common.mustCall());
254256

255257
(async () => {
256258
const b = new Blob(Array(10).fill('hello'));
257259
const reader = b.stream().getReader();
258260
const chunks = [];
261+
let byteLength = 0;
259262
while (true) {
260263
const res = await reader.read();
261-
if (chunks.length === 5) {
264+
byteLength += res.value.byteLength;
265+
if (byteLength >= 50) {
262266
reader.cancel('boom');
263267
break;
264268
}
265269
if (res.done) break;
266-
assert.strictEqual(res.value.byteLength, 5);
270+
assert.ok(res.value.byteLength >= 5);
267271
chunks.push(res.value);
268272
}
269-
assert.strictEqual(chunks.length, 5);
270273
reader.closed.then(common.mustCall());
271274
})().then(common.mustCall());
272275

@@ -334,11 +337,13 @@ assert.throws(() => new Blob({}), {
334337
const reader = stream.getReader();
335338
assert.strictEqual(stream[kState].controller.desiredSize, 0);
336339
const { value, done } = await reader.read();
337-
assert.strictEqual(value.byteLength, 5);
338-
assert(!done);
340+
assert.ok(value.byteLength >= 5);
341+
assert.ok(value.byteLength <= 50);
342+
assert(!done || value.byteLength === 50);
339343
setTimeout(common.mustCall(() => {
340344
// The blob stream is now a byte stream hence after the first read,
341345
// it should pull in the next 'hello' which is 5 bytes hence -5.
346+
// but recently, we coalesce if possible adjacent memory
342347
assert.strictEqual(stream[kState].controller.desiredSize, 0);
343348
}), 0);
344349
})().then(common.mustCall());
@@ -363,7 +368,8 @@ assert.throws(() => new Blob({}), {
363368
const reader = stream.getReader({ mode: 'byob' });
364369
assert.strictEqual(stream[kState].controller.desiredSize, 0);
365370
const { value, done } = await reader.read(new Uint8Array(100));
366-
assert.strictEqual(value.byteLength, 5);
371+
assert.ok(value.byteLength >= 5);
372+
assert.ok(value.byteLength <= 50);
367373
assert(!done);
368374
setTimeout(common.mustCall(() => {
369375
assert.strictEqual(stream[kState].controller.desiredSize, 0);
@@ -379,7 +385,8 @@ assert.throws(() => new Blob({}), {
379385
assert.strictEqual(value.byteLength, 2);
380386
assert(!done);
381387
setTimeout(common.mustCall(() => {
382-
assert.strictEqual(stream[kState].controller.desiredSize, -3);
388+
assert.ok(stream[kState].controller.desiredSize <= -3,
389+
'desiredSize must be smaller or equal than -3');
383390
}), 0);
384391
})().then(common.mustCall());
385392

0 commit comments

Comments
 (0)