Skip to content

Commit

Permalink
Tests whether releaseLock() rejects all pending reads
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Dec 15, 2021
1 parent 13817e2 commit 5c4df18
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
26 changes: 13 additions & 13 deletions streams/readable-byte-streams/general.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,16 @@ promise_test(t => {
});
}, 'ReadableStream with byte source: Test that erroring a stream does not release a BYOB reader automatically');

test(() => {
promise_test(async t => {
const stream = new ReadableStream({
type: 'bytes'
});

const reader = stream.getReader();
reader.read();
assert_throws_js(TypeError, () => reader.releaseLock(), 'reader.releaseLock() must throw');
}, 'ReadableStream with byte source: releaseLock() on ReadableStreamDefaultReader with pending read() must throw');
const read = reader.read();
reader.releaseLock();
await promise_rejects_js(t, TypeError, read, 'pending read must reject');
}, 'ReadableStream with byte source: releaseLock() on ReadableStreamDefaultReader must reject pending read()');

promise_test(() => {
let pullCount = 0;
Expand Down Expand Up @@ -2111,7 +2112,7 @@ promise_test(() => {
});
}, 'calling respond() should throw when canceled');

promise_test(() => {
promise_test(async t => {
let resolvePullCalledPromise;
const pullCalledPromise = new Promise(resolve => {
resolvePullCalledPromise = resolve;
Expand All @@ -2127,14 +2128,13 @@ promise_test(() => {
type: 'bytes'
});
const reader = rs.getReader({ mode: 'byob' });
reader.read(new Uint8Array(16));
return pullCalledPromise.then(() => {
resolvePull();
return delay(0).then(() => {
assert_throws_js(TypeError, () => reader.releaseLock(), 'releaseLock() should throw');
});
});
}, 'pull() resolving should not make releaseLock() possible');
const read = reader.read(new Uint8Array(16));
await pullCalledPromise;
resolvePull();
await delay(0);
reader.releaseLock();
await promise_rejects_js(t, TypeError, read, 'pending read should reject');
}, 'pull() resolving should not resolve read()');

promise_test(() => {
// Tests https://github.com/whatwg/streams/issues/686
Expand Down
29 changes: 11 additions & 18 deletions streams/resources/rs-test-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,32 +251,25 @@ self.templatedRSEmptyReader = (label, factory) => {

}, label + ': getReader() again on the stream should fail');

promise_test(t => {
promise_test(async t => {

const streamAndReader = factory();
const stream = streamAndReader.stream;
const reader = streamAndReader.reader;

reader.read().then(
t.unreached_func('first read() should not fulfill'),
t.unreached_func('first read() should not reject')
);

reader.read().then(
t.unreached_func('second read() should not fulfill'),
t.unreached_func('second read() should not reject')
);
const read1 = reader.read();
const read2 = reader.read();
const closed = reader.closed;

reader.closed.then(
t.unreached_func('closed should not fulfill'),
t.unreached_func('closed should not reject')
);

assert_throws_js(TypeError, () => reader.releaseLock(), 'releaseLock should throw a TypeError');
reader.releaseLock();

assert_true(stream.locked, 'the stream should still be locked');
assert_false(stream.locked, 'the stream should be unlocked');

return delay(500);
await Promise.all([
promise_rejects_js(t, TypeError, read1, 'first read should reject'),
promise_rejects_js(t, TypeError, read2, 'second read should reject'),
promise_rejects_js(t, TypeError, closed, 'closed should reject')
]);

}, label + ': releasing the lock with pending read requests should throw but the read requests should stay pending');

Expand Down

0 comments on commit 5c4df18

Please sign in to comment.