Skip to content

Commit

Permalink
Streams: pipeTo error flushing pending writes test
Browse files Browse the repository at this point in the history
Add a test for what happens when an error occurs flushing pending writes in
pipeTo after the readable closes.

This clarifies behaviour that is not obvious from the standard.

Related to whatwg/streams#939
  • Loading branch information
ricea authored and domenic committed Jul 11, 2018
1 parent 2305706 commit 828cbf6
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions streams/piping/close-propagation-forward.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,36 @@ promise_test(() => {

}, 'Closing must be propagated forward: shutdown must not occur until the final write completes; becomes closed after first write; preventClose = true');


promise_test(t => {
const rs = recordingReadableStream({
start(c) {
c.enqueue('a');
c.enqueue('b');
c.close();
}
});
let rejectWritePromise;
const ws = recordingWritableStream({
write() {
return new Promise((resolve, reject) => {
rejectWritePromise = reject;
});
}
}, { highWaterMark: 3 });
const pipeToPromise = rs.pipeTo(ws);
return delay(0).then(() => {
rejectWritePromise(error1);
return promise_rejects(t, error1, pipeToPromise, 'pipeTo should reject');
}).then(() => {
assert_array_equals(rs.events, []);
assert_array_equals(ws.events, ['write', 'a']);

return Promise.all([
rs.getReader().closed,
promise_rejects(t, error1, ws.getWriter().closed, 'ws should be errored')
]);
});
}, 'Closing must be propagated forward: erroring the writable while flushing pending writes should error pipeTo');

done();

0 comments on commit 828cbf6

Please sign in to comment.