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: update wpt test for streams #54129

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Last update:
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/17ebc3aea0/performance-timeline
- resource-timing: https://github.com/web-platform-tests/wpt/tree/22d38586d0/resource-timing
- resources: https://github.com/web-platform-tests/wpt/tree/1e140d63ec/resources
- streams: https://github.com/web-platform-tests/wpt/tree/9b03282a99/streams
- streams: https://github.com/web-platform-tests/wpt/tree/2bd26e124c/streams
- url: https://github.com/web-platform-tests/wpt/tree/6a39784534/url
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
Expand Down
40 changes: 40 additions & 0 deletions test/fixtures/wpt/streams/piping/abort.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,46 @@ for (const reason of [null, undefined, error1]) {
}, `(reason: '${reason}') all pending writes should complete on abort`);
}

for (const reason of [null, undefined, error1]) {
promise_test(async t => {
let rejectPull;
const pullPromise = new Promise((_, reject) => {
rejectPull = reject;
});
let rejectCancel;
const cancelPromise = new Promise((_, reject) => {
rejectCancel = reject;
});
const rs = recordingReadableStream({
async pull() {
await Promise.race([
pullPromise,
cancelPromise,
]);
},
cancel(reason) {
rejectCancel(reason);
},
});
const ws = new WritableStream();
const abortController = new AbortController();
const signal = abortController.signal;
const pipeToPromise = rs.pipeTo(ws, { signal });
pipeToPromise.catch(() => {}); // Prevent unhandled rejection.
await delay(0);
abortController.abort(reason);
rejectPull('should not catch pull rejection');
await delay(0);
assert_equals(rs.eventsWithoutPulls.length, 2, 'cancel should have been called');
assert_equals(rs.eventsWithoutPulls[0], 'cancel', 'first event should be cancel');
if (reason !== undefined) {
await promise_rejects_exactly(t, reason, pipeToPromise, 'pipeTo rejects with abort reason');
} else {
await promise_rejects_dom(t, 'AbortError', pipeToPromise, 'pipeTo rejects with AbortError');
}
}, `(reason: '${reason}') underlyingSource.cancel() should called when abort, even with pending pull`);
}

promise_test(t => {
const rs = new ReadableStream({
pull(controller) {
Expand Down
21 changes: 0 additions & 21 deletions test/fixtures/wpt/streams/piping/detached-context-crash.html

This file was deleted.

25 changes: 25 additions & 0 deletions test/fixtures/wpt/streams/readable-streams/cancel.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,28 @@ promise_test(() => {
return Promise.all([rs.cancel(), rs.getReader().closed]);

}, 'ReadableStream cancellation: cancelling before start finishes should prevent pull() from being called');

promise_test(async () => {

const events = [];

const pendingPromise = new Promise(() => {});

const rs = new ReadableStream({
pull() {
events.push('pull');
return pendingPromise;
},
cancel() {
events.push('cancel');
}
});

const reader = rs.getReader();
reader.read().catch(() => {}); // No await.
await delay(0);
await Promise.all([reader.cancel(), reader.closed]);

assert_array_equals(events, ['pull', 'cancel'], 'cancel should have been called');

}, 'ReadableStream cancellation: underlyingSource.cancel() should called, even with pending pull');
42 changes: 30 additions & 12 deletions test/fixtures/wpt/streams/readable-streams/from.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,44 +51,50 @@ const iterableFactories = [

['a sync iterable of values', () => {
const chunks = ['a', 'b'];
const it = {
const iterator = {
next() {
return {
done: chunks.length === 0,
value: chunks.shift()
};
},
[Symbol.iterator]: () => it
}
};
const iterable = {
[Symbol.iterator]: () => iterator
};
return it;
return iterable;
}],

['a sync iterable of promises', () => {
const chunks = ['a', 'b'];
const it = {
const iterator = {
next() {
return chunks.length === 0 ? { done: true } : {
done: false,
value: Promise.resolve(chunks.shift())
};
},
[Symbol.iterator]: () => it
}
};
const iterable = {
[Symbol.iterator]: () => iterator
};
return it;
return iterable;
}],

['an async iterable', () => {
const chunks = ['a', 'b'];
const it = {
const asyncIterator = {
next() {
return Promise.resolve({
done: chunks.length === 0,
value: chunks.shift()
})
},
[Symbol.asyncIterator]: () => it
}
};
const asyncIterable = {
[Symbol.asyncIterator]: () => asyncIterator
};
return it;
return asyncIterable;
}],

['a ReadableStream', () => {
Expand Down Expand Up @@ -186,6 +192,18 @@ test(t => {
assert_throws_exactly(theError, () => ReadableStream.from(iterable), 'from() should re-throw the error');
}, `ReadableStream.from ignores @@iterator if @@asyncIterator exists`);

test(() => {
const theError = new Error('a unique string');
const iterable = {
[Symbol.asyncIterator]: null,
[Symbol.iterator]() {
throw theError
}
};

assert_throws_exactly(theError, () => ReadableStream.from(iterable), 'from() should re-throw the error');
}, `ReadableStream.from ignores a null @@asyncIterator`);

promise_test(async () => {

const iterable = {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"path": "resources"
},
"streams": {
"commit": "9b03282a99ef2314c1c2d5050a105a74a2940019",
"commit": "2bd26e124cf17b2f0a25c150794d640b07b2a870",
"path": "streams"
},
"url": {
Expand Down
15 changes: 11 additions & 4 deletions test/wpt/status/streams.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
"readable-streams/cross-realm-crash.window.js": {
"skip": "Browser-specific test"
},
"readable-streams/from.any.js": {
"fail": {
"expected": [
"ReadableStream.from ignores a null @@asyncIterator"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to fix this in a follow-up PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MattiasBuelens I think we might need to address this issue. It seems like some basic error handling might be necessary. I'm also open to contributing to a follow-up PR to help resolve this.

]
}
},
"readable-streams/owning-type-message-port.any.js": {
"fail": {
"note": "Readable streams with type owning are not yet supported",
daeyeon marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -29,8 +36,8 @@
"skip": "Browser-specific test"
},
"readable-streams/owning-type.any.js": {
"note": "Readable streams with type owning are not yet supported",
daeyeon marked this conversation as resolved.
Show resolved Hide resolved
"fail": {
"note": "Readable streams with type owning are not yet supported",
"expected": [
"ReadableStream can be constructed with owning type",
"ReadableStream of type owning should call start with a ReadableStreamDefaultController",
Expand All @@ -40,6 +47,9 @@
]
}
},
"readable-streams/read-task-handling.window.js": {
"skip": "Browser-specific test"
},
"transferable/deserialize-error.window.js": {
"skip": "Browser-specific test"
},
Expand All @@ -56,8 +66,5 @@
},
"transform-streams/invalid-realm.tentative.window.js": {
"skip": "Browser-specific test"
},
"readable-streams/read-task-handling.window.js": {
"skip": "Browser-specific test"
}
}