Skip to content

Commit b29b36c

Browse files
committed
quic: Bring blob test closer to old spirit
1 parent 3991a58 commit b29b36c

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

test/parallel/test-blob.js

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -240,36 +240,33 @@ assert.throws(() => new Blob({}), {
240240
})().then(common.mustCall());
241241

242242
(async () => {
243-
const b = new Blob(Array(10).fill('hello'));
243+
const b = new Blob(Array(10).fill('hello'.repeat(3000)));
244244
const reader = b.stream().getReader();
245245
const chunks = [];
246-
let byteLength = 0;
247246
while (true) {
248247
const res = await reader.read();
249248
if (res.done) break;
250-
byteLength += res.value.byteLength;
251-
assert.ok(res.value.byteLength >= 5);
249+
assert.strictEqual(res.value.byteLength, 30000);
252250
chunks.push(res.value);
253251
}
254-
assert.strictEqual(byteLength, 50);
252+
assert.strictEqual(chunks.length, 5);
255253
})().then(common.mustCall());
256254

257255
(async () => {
258-
const b = new Blob(Array(10).fill('hello'));
256+
const b = new Blob(Array(10).fill('hello'.repeat(3000)));
259257
const reader = b.stream().getReader();
260258
const chunks = [];
261-
let byteLength = 0;
262259
while (true) {
263260
const res = await reader.read();
264-
byteLength += res.value.byteLength;
265-
if (byteLength >= 50) {
261+
if (chunks.length === 5) {
266262
reader.cancel('boom');
267263
break;
268264
}
269265
if (res.done) break;
270-
assert.ok(res.value.byteLength >= 5);
266+
assert.strictEqual(res.value.byteLength, 30000);
271267
chunks.push(res.value);
272268
}
269+
assert.strictEqual(chunks.length, 5);
273270
reader.closed.then(common.mustCall());
274271
})().then(common.mustCall());
275272

@@ -332,18 +329,18 @@ assert.throws(() => new Blob({}), {
332329
})().then(common.mustCall());
333330

334331
(async () => {
335-
const b = new Blob(Array(10).fill('hello'));
332+
const b = new Blob(Array(10).fill('hello'.repeat(3000)));
336333
const stream = b.stream();
337334
const reader = stream.getReader();
338335
assert.strictEqual(stream[kState].controller.desiredSize, 0);
339336
const { value, done } = await reader.read();
340-
assert.ok(value.byteLength >= 5);
341-
assert.ok(value.byteLength <= 50);
342-
assert(!done || value.byteLength === 50);
337+
assert.strictEqual(value.byteLength, 30000);
338+
assert(!done);
343339
setTimeout(common.mustCall(() => {
344340
// The blob stream is now a byte stream hence after the first read,
345341
// it should pull in the next 'hello' which is 5 bytes hence -5.
346342
// but recently, we coalesce if possible adjacent memory
343+
// the test code is adapted to the current limit for coalescing
347344
assert.strictEqual(stream[kState].controller.desiredSize, 0);
348345
}), 0);
349346
})().then(common.mustCall());
@@ -363,30 +360,28 @@ assert.throws(() => new Blob({}), {
363360
})().then(common.mustCall());
364361

365362
(async () => {
366-
const b = new Blob(Array(10).fill('hello'));
363+
const b = new Blob(Array(10).fill('hello'.repeat(3000)));
367364
const stream = b.stream();
368365
const reader = stream.getReader({ mode: 'byob' });
369366
assert.strictEqual(stream[kState].controller.desiredSize, 0);
370-
const { value, done } = await reader.read(new Uint8Array(100));
371-
assert.ok(value.byteLength >= 5);
372-
assert.ok(value.byteLength <= 50);
367+
const { value, done } = await reader.read(new Uint8Array(40000));
368+
assert.strictEqual(value.byteLength, 30000);
373369
assert(!done);
374370
setTimeout(common.mustCall(() => {
375371
assert.strictEqual(stream[kState].controller.desiredSize, 0);
376372
}), 0);
377373
})().then(common.mustCall());
378374

379375
(async () => {
380-
const b = new Blob(Array(10).fill('hello'));
376+
const b = new Blob(Array(10).fill('hello'.repeat(3000)));
381377
const stream = b.stream();
382378
const reader = stream.getReader({ mode: 'byob' });
383379
assert.strictEqual(stream[kState].controller.desiredSize, 0);
384380
const { value, done } = await reader.read(new Uint8Array(2));
385381
assert.strictEqual(value.byteLength, 2);
386382
assert(!done);
387383
setTimeout(common.mustCall(() => {
388-
assert.ok(stream[kState].controller.desiredSize <= -3,
389-
'desiredSize must be smaller or equal than -3');
384+
assert.strictEqual(stream[kState].controller.desiredSize, -29998);
390385
}), 0);
391386
})().then(common.mustCall());
392387

0 commit comments

Comments
 (0)