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
async_test
with async function produces undesirable results
#21435
Comments
Lines 550 to 562 in 1e489ab
It would make sense for |
I would like to work on this if that's ok. I (locally) applied a patch to Should I just wait out the test results or is there a more efficient way of finding all the places that need to be corrected? (e.g. I did a search for |
@frehner that would be great! If you can create a pull request with your patch, I can set off a 'trigger' run for you which will run all the tests in the suite and should give us good coverage (see https://web-platform-tests.org/running-tests/from-ci.html). Then we can iterate on the patch to fixup the problematic tests. EDIT: Note that I suspect that a naive grep for |
Thanks, I should be able to get a PR up around the weekend and we can go from there. |
Forgive me for my newness / ignorance, I'm still trying to fully understand test harness's api: I wanted to be sure I was migrating the tests in the right way; after playing around with various methods, this is the way that I've found that works - but I'm not sure if it's the "best" way. Say we have this test: Lines 19 to 34 in c99723a
The way it appears to me that it should be updated is like the following - note that I'm still using async_test(t => {
t.step(async () => {
const iframe = document.querySelector('iframe');
const iframeLoadPromise = new Promise(resolve => iframe.onload = resolve);
iframe.src = '/';
await iframeLoadPromise;
const anchor = document.getElementById('anchor');
anchor.href = '/#';
t.step(() => anchor.click());
window.onmessage = t.step_func(event => {
if (typeof event.data === 'string' && event.data.includes('navigation')) {
assert_equals(event.data, 'form navigation laskjdf');
t.done();
}
});
})
}); Why this way? Well, I tried changing it to Anyway, when you have a second, if you don't mind letting me know if I'm going down the right path or if I've missed something. Thank you :) |
Hey @frehner, thanks for looking at this :) The reason that test wouldn't work (as written) as a promise test is that the promise isn't going to wait for window.onmessage. So: promise_test(async t => {
const iframe = document.querySelector('iframe');
const iframeLoadPromise = new Promise(resolve => iframe.onload = resolve);
iframe.src = '/';
await iframeLoadPromise; // <--- promise 'waits' for this to finish
const anchor = document.getElementById('anchor');
anchor.href = '/#';
t.step(() => anchor.click());
window.onmessage = t.step_func(event => { // <-- promise doesn't wait for this!
if (typeof event.data === 'string' && event.data.includes('navigation')) {
assert_equals(event.data, 'form navigation');
t.done();
}
});
// <--- there's an implicit return new Promise() here, which won't wait for the window.onmessage above.
}); The tricky part here is that the test is written to handle multiple Instead, I think we shoud keep it async. But unfortunately your solution isn't quite right - I don't think I think I would probably rewrite the test like this: async_test(t => {
const iframe = document.querySelector('iframe');
iframe.onload = t.step_func(() => {
const anchor = document.getElementById('anchor');
anchor.href = '/#';
anchor.click(); // NOTE: I removed the t.step() around this function, because I don't believe its doing anything.
window.onmessage = t.step_func(event => {
if (typeof event.data === 'string' && event.data.includes('navigation')) {
assert_equals(event.data, 'form navigation');
t.done();
}
});
});
iframe.src = '/';
}); |
Ah that makes sense - removing the awaits with t.step_func where possible and just removing the async func. Thanks. |
Ok, so, based on your feedback above, I went ahead and tried to fix another test that had this issue, and created a draft PR #24021 I'm still not very confident in my understanding of the test framework - though my confidence is growing - so I wanted to push this one up to see if you think I've done it right. If so, then I'll feel good about progressing without asking for as much feedback. I just didn't want to get really far into the PR just to find out that I've been doing it wrong the whole time. In summary - sorry to bother you again, but how does this look so far? |
@frehner Hi Anthony; just wanted to check in and see if you're still working on this issue. If not, no worries, we just want to make sure it doesn't accidentally get double-work on it :) |
Not currently working on it, no. :) |
I keep seeing This is a very natural thing to attempt given the naming, and plenty of cases of it have slipped through code review. The string "async_test(async" appears in these tests:content-security-policy/frame-src/frame-src-same-document-meta.sub.html I think we'll keep accumulating cases like this until there's a lint or runtime error that prevents it. I'm removing the "good first issue" label as this won't be straightforward due to the existing tests and needing to test run changes in downstream users of WPT (Chromium, Gecko, WebKit). |
…st in webrtc/, a=testonly Automatic update from web-platform-tests Fix tests that return values to async_test in webrtc/ (#25719) These tests are written correctly, they just need to not return the promises they use as part of the flow. They could be rewritten to use promise_tests if desired, but that would have performance implications (as it changes them from concurrent to sequential) so leaving that for now. See web-platform-tests/wpt#21435 -- wpt-commits: db9d339c441f03b2b89b00bce3662fb6e043c6fb wpt-pr: 25719
…tion to `async_test`, a=testonly Automatic update from web-platform-tests Convert async_test to promise_test in webcodecs/video-track-reader.html See web-platform-tests/wpt#21435 -- Convert await-using async tests to promise_test in reporting/ See web-platform-tests/wpt#21435 -- Fix a few cases of await-using async_test in css/ and html/ See web-platform-tests/wpt#21435 -- wpt-commits: 33e3f6e95100e5d409099ecbdbeb07c0827b0058, 80ccc18f3f5b1e0fc933d8ce806ddbf5475ad2e1, e0020b8951abeb3b1c809b1073712a96ce037e7b wpt-pr: 25517 UltraBlame original commit: 883c461469ed232bf63951c5579259fa4cb71569
…e promise_test, a=testonly Automatic update from web-platform-tests Change some async_tests in webrtc/ to use promise_test (#25659) See web-platform-tests/wpt#21435 -- wpt-commits: bed7a2397d50c90694d2ab67b9cf33c274c2e75a wpt-pr: 25659 UltraBlame original commit: b89ec30a8daf57b40e7079b633b0d196e3ad4fc7
…ation/ to use promise_test, a=testonly Automatic update from web-platform-tests Change some async_tests in screen_enumeration/ to use promise_test (#25660) See web-platform-tests/wpt#21435 -- wpt-commits: 316892ab1896f95e9548a63ae2ff84c1120f30af wpt-pr: 25660 UltraBlame original commit: 5e96ed0fcca517d4d8b6f97555154fabb01d71ff
…ar-window-name.https.html, a=testonly Automatic update from web-platform-tests Change async_test to promise_test in clear-window-name.https.html (#25572) These all appear to be straight-forward promise tests, not async tests. See web-platform-tests/wpt#21435 -- wpt-commits: d8e451a277b65aeb573845bbbd900a6cb87e1798 wpt-pr: 25572 UltraBlame original commit: 46df596cc6b9d310c3f6894c9bb7c8b455b6f239
…st in encrypted-media/, a=testonly Automatic update from web-platform-tests Fix tests that return values to async_test in encrypted-media/ (#25717) In both cases here, the test was correctly written for async_test, they just didn't need to return the promise they used as part of the test flow. See web-platform-tests/wpt#21435 -- wpt-commits: d0804458e8797790f61efc73ab2446c6e507a30f wpt-pr: 25717 UltraBlame original commit: abc4def732890fbde3883f10356af6a255958062
…st in webrtc/, a=testonly Automatic update from web-platform-tests Fix tests that return values to async_test in webrtc/ (#25719) These tests are written correctly, they just need to not return the promises they use as part of the flow. They could be rewritten to use promise_tests if desired, but that would have performance implications (as it changes them from concurrent to sequential) so leaving that for now. See web-platform-tests/wpt#21435 -- wpt-commits: db9d339c441f03b2b89b00bce3662fb6e043c6fb wpt-pr: 25719 UltraBlame original commit: 5f39aad86e2e243034fef317378cf1c9f094c6b4
…tion to `async_test`, a=testonly Automatic update from web-platform-tests Convert async_test to promise_test in webcodecs/video-track-reader.html See web-platform-tests/wpt#21435 -- Convert await-using async tests to promise_test in reporting/ See web-platform-tests/wpt#21435 -- Fix a few cases of await-using async_test in css/ and html/ See web-platform-tests/wpt#21435 -- wpt-commits: 33e3f6e95100e5d409099ecbdbeb07c0827b0058, 80ccc18f3f5b1e0fc933d8ce806ddbf5475ad2e1, e0020b8951abeb3b1c809b1073712a96ce037e7b wpt-pr: 25517 UltraBlame original commit: 883c461469ed232bf63951c5579259fa4cb71569
…e promise_test, a=testonly Automatic update from web-platform-tests Change some async_tests in webrtc/ to use promise_test (#25659) See web-platform-tests/wpt#21435 -- wpt-commits: bed7a2397d50c90694d2ab67b9cf33c274c2e75a wpt-pr: 25659 UltraBlame original commit: b89ec30a8daf57b40e7079b633b0d196e3ad4fc7
…ation/ to use promise_test, a=testonly Automatic update from web-platform-tests Change some async_tests in screen_enumeration/ to use promise_test (#25660) See web-platform-tests/wpt#21435 -- wpt-commits: 316892ab1896f95e9548a63ae2ff84c1120f30af wpt-pr: 25660 UltraBlame original commit: 5e96ed0fcca517d4d8b6f97555154fabb01d71ff
…ar-window-name.https.html, a=testonly Automatic update from web-platform-tests Change async_test to promise_test in clear-window-name.https.html (#25572) These all appear to be straight-forward promise tests, not async tests. See web-platform-tests/wpt#21435 -- wpt-commits: d8e451a277b65aeb573845bbbd900a6cb87e1798 wpt-pr: 25572 UltraBlame original commit: 46df596cc6b9d310c3f6894c9bb7c8b455b6f239
…st in encrypted-media/, a=testonly Automatic update from web-platform-tests Fix tests that return values to async_test in encrypted-media/ (#25717) In both cases here, the test was correctly written for async_test, they just didn't need to return the promise they used as part of the test flow. See web-platform-tests/wpt#21435 -- wpt-commits: d0804458e8797790f61efc73ab2446c6e507a30f wpt-pr: 25717 UltraBlame original commit: abc4def732890fbde3883f10356af6a255958062
…st in webrtc/, a=testonly Automatic update from web-platform-tests Fix tests that return values to async_test in webrtc/ (#25719) These tests are written correctly, they just need to not return the promises they use as part of the flow. They could be rewritten to use promise_tests if desired, but that would have performance implications (as it changes them from concurrent to sequential) so leaving that for now. See web-platform-tests/wpt#21435 -- wpt-commits: db9d339c441f03b2b89b00bce3662fb6e043c6fb wpt-pr: 25719 UltraBlame original commit: 5f39aad86e2e243034fef317378cf1c9f094c6b4
…tion to `async_test`, a=testonly Automatic update from web-platform-tests Convert async_test to promise_test in webcodecs/video-track-reader.html See web-platform-tests/wpt#21435 -- Convert await-using async tests to promise_test in reporting/ See web-platform-tests/wpt#21435 -- Fix a few cases of await-using async_test in css/ and html/ See web-platform-tests/wpt#21435 -- wpt-commits: 33e3f6e95100e5d409099ecbdbeb07c0827b0058, 80ccc18f3f5b1e0fc933d8ce806ddbf5475ad2e1, e0020b8951abeb3b1c809b1073712a96ce037e7b wpt-pr: 25517 UltraBlame original commit: 883c461469ed232bf63951c5579259fa4cb71569
…e promise_test, a=testonly Automatic update from web-platform-tests Change some async_tests in webrtc/ to use promise_test (#25659) See web-platform-tests/wpt#21435 -- wpt-commits: bed7a2397d50c90694d2ab67b9cf33c274c2e75a wpt-pr: 25659 UltraBlame original commit: b89ec30a8daf57b40e7079b633b0d196e3ad4fc7
…ation/ to use promise_test, a=testonly Automatic update from web-platform-tests Change some async_tests in screen_enumeration/ to use promise_test (#25660) See web-platform-tests/wpt#21435 -- wpt-commits: 316892ab1896f95e9548a63ae2ff84c1120f30af wpt-pr: 25660 UltraBlame original commit: 5e96ed0fcca517d4d8b6f97555154fabb01d71ff
…ar-window-name.https.html, a=testonly Automatic update from web-platform-tests Change async_test to promise_test in clear-window-name.https.html (#25572) These all appear to be straight-forward promise tests, not async tests. See web-platform-tests/wpt#21435 -- wpt-commits: d8e451a277b65aeb573845bbbd900a6cb87e1798 wpt-pr: 25572 UltraBlame original commit: 46df596cc6b9d310c3f6894c9bb7c8b455b6f239
…st in encrypted-media/, a=testonly Automatic update from web-platform-tests Fix tests that return values to async_test in encrypted-media/ (#25717) In both cases here, the test was correctly written for async_test, they just didn't need to return the promise they used as part of the test flow. See web-platform-tests/wpt#21435 -- wpt-commits: d0804458e8797790f61efc73ab2446c6e507a30f wpt-pr: 25717 UltraBlame original commit: abc4def732890fbde3883f10356af6a255958062
…st in webrtc/, a=testonly Automatic update from web-platform-tests Fix tests that return values to async_test in webrtc/ (#25719) These tests are written correctly, they just need to not return the promises they use as part of the flow. They could be rewritten to use promise_tests if desired, but that would have performance implications (as it changes them from concurrent to sequential) so leaving that for now. See web-platform-tests/wpt#21435 -- wpt-commits: db9d339c441f03b2b89b00bce3662fb6e043c6fb wpt-pr: 25719 UltraBlame original commit: 5f39aad86e2e243034fef317378cf1c9f094c6b4
… returns a value, a=testonly Automatic update from web-platform-tests Set harness error if async_test function returns a value (#25703) Cherry-picks and modifies work done by frehner@ in web-platform-tests/wpt#24021 Fixes web-platform-tests/wpt#21435 Co-authored-by: Anthony Frehner <afrehner.work@gmail.com> Co-authored-by: Philip Jägenstedt <philip@foolip.org> -- wpt-commits: 2966c80c8e0006a8f6d275187b40d6892d38dce6 wpt-pr: 25703
… returns a value, a=testonly Automatic update from web-platform-tests Set harness error if async_test function returns a value (#25703) Cherry-picks and modifies work done by frehner@ in web-platform-tests/wpt#24021 Fixes web-platform-tests/wpt#21435 Co-authored-by: Anthony Frehner <afrehner.work@gmail.com> Co-authored-by: Philip Jägenstedt <philip@foolip.org> -- wpt-commits: 2966c80c8e0006a8f6d275187b40d6892d38dce6 wpt-pr: 25703
…e promise_test, a=testonly Automatic update from web-platform-tests Change some async_tests in webrtc/ to use promise_test (#25659) See web-platform-tests/wpt#21435 -- wpt-commits: bed7a2397d50c90694d2ab67b9cf33c274c2e75a wpt-pr: 25659
…ation/ to use promise_test, a=testonly Automatic update from web-platform-tests Change some async_tests in screen_enumeration/ to use promise_test (#25660) See web-platform-tests/wpt#21435 -- wpt-commits: 316892ab1896f95e9548a63ae2ff84c1120f30af wpt-pr: 25660
…ar-window-name.https.html, a=testonly Automatic update from web-platform-tests Change async_test to promise_test in clear-window-name.https.html (#25572) These all appear to be straight-forward promise tests, not async tests. See web-platform-tests/wpt#21435 -- wpt-commits: d8e451a277b65aeb573845bbbd900a6cb87e1798 wpt-pr: 25572
…st in encrypted-media/, a=testonly Automatic update from web-platform-tests Fix tests that return values to async_test in encrypted-media/ (#25717) In both cases here, the test was correctly written for async_test, they just didn't need to return the promise they used as part of the test flow. See web-platform-tests/wpt#21435 -- wpt-commits: d0804458e8797790f61efc73ab2446c6e507a30f wpt-pr: 25717
…st in webrtc/, a=testonly Automatic update from web-platform-tests Fix tests that return values to async_test in webrtc/ (#25719) These tests are written correctly, they just need to not return the promises they use as part of the flow. They could be rewritten to use promise_tests if desired, but that would have performance implications (as it changes them from concurrent to sequential) so leaving that for now. See web-platform-tests/wpt#21435 -- wpt-commits: db9d339c441f03b2b89b00bce3662fb6e043c6fb wpt-pr: 25719
Passing an async function to async_test will soon be disallowed in WPT, as any asserts thrown will be turned into unhandled promise rejections and the test will timeout. If a test needs async functions it should use promise_test instead. (The naming conflict is a sad historical legacy; WPT had async_test long before EcmaScript spec'd promises!) Bug: web-platform-tests/wpt#21435 Change-Id: I6082d03b6821781ed62d274dc0ca0b2741d2d285 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414675 Reviewed-by: Alex Turner <alexmt@chromium.org> Commit-Queue: Stephen McGruer <smcgruer@chromium.org> Cr-Commit-Position: refs/heads/master@{#807908} GitOrigin-RevId: f68671e4933f33666af5db04a50166bdbbf433ef
Passing an async function to async_test will soon be disallowed in WPT, as any asserts thrown will be turned into unhandled promise rejections and the test will timeout. If a test needs async functions it should use promise_test instead. (The naming conflict is a sad historical legacy; WPT had async_test long before EcmaScript spec'd promises!) Bug: web-platform-tests/wpt#21435 Change-Id: I0a31872525844a1540aea548e329929e8097663e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414923 Reviewed-by: John Rummell <jrummell@chromium.org> Reviewed-by: Philip Jägenstedt <foolip@chromium.org> Commit-Queue: Stephen McGruer <smcgruer@chromium.org> Cr-Commit-Position: refs/heads/master@{#809464} GitOrigin-RevId: 21648f3fe545f82c59ae2b9826d8c99d649e9cd8
Passing an async function to async_test will soon be disallowed in WPT, as any asserts thrown will be turned into unhandled promise rejections and the test will timeout. If a test needs async functions it should use promise_test instead. (The naming conflict is a sad historical legacy; WPT had async_test long before EcmaScript spec'd promises!) Bug: web-platform-tests/wpt#21435 Change-Id: I6082d03b6821781ed62d274dc0ca0b2741d2d285 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414675 Reviewed-by: Alex Turner <alexmt@chromium.org> Commit-Queue: Stephen McGruer <smcgruer@chromium.org> Cr-Commit-Position: refs/heads/master@{#807908} Former-commit-id: f68671e4933f33666af5db04a50166bdbbf433ef
Passing an async function to async_test will soon be disallowed in WPT, as any asserts thrown will be turned into unhandled promise rejections and the test will timeout. If a test needs async functions it should use promise_test instead. (The naming conflict is a sad historical legacy; WPT had async_test long before EcmaScript spec'd promises!) Bug: web-platform-tests/wpt#21435 Change-Id: I0a31872525844a1540aea548e329929e8097663e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414923 Reviewed-by: John Rummell <jrummell@chromium.org> Reviewed-by: Philip Jägenstedt <foolip@chromium.org> Commit-Queue: Stephen McGruer <smcgruer@chromium.org> Cr-Commit-Position: refs/heads/master@{#809464} Former-commit-id: 21648f3fe545f82c59ae2b9826d8c99d649e9cd8
This was reported on https://groups.google.com/a/chromium.org/forum/#!topic/ecosystem-infra/2dpo_NDYOgc. If you have a test file which passes an
async
function toasync_test
, and thatasync
function throws an exception, the sub-test will TIMEOUT and the harness will get an exception.For example:
Harness status ERROR and test status TIMEOUT
Harness status PRECONDITION_FAILED (misleading...?!) and test status TIMEOUT.
In some ways this is working as intended; nothing has told the test object that it is finished, so it is reasonable for it to still be waiting. It is a bit weird that PRECONDITION_FAILED ends up being propagated to the test harness. In either case, however, I cannot see a use for passing an async function to
async_test
, so perhaps we should guard against it?Naively I think
async_test
could check the return type oftest_obj.step(
and fail in some way if its a Promise, but I don't know testharness.js that well so that may be nonsense.The text was updated successfully, but these errors were encountered: