Skip to content

Do not return value from "cleanup" functions - #8742

Merged
foolip merged 2 commits into
web-platform-tests:masterfrom
bocoup:cleanup-return
Dec 20, 2017
Merged

foolip merged 2 commits into
web-platform-tests:masterfrom
bocoup:cleanup-return

Conversation

@jugglinmike

@jugglinmike jugglinmike commented Dec 19, 2017 •

Copy link
Copy Markdown
Contributor

Today, the return value of functions provided to the global
add_cleanup function has no effect on the behavior of the test runner.
An upcoming feature addition to testharness.js will cause the return
value to influence test results [1].

Despite this, some existing tests have already been authored to return a
value. Introducing the new test harness functionality may trigger
unexpected results in those contexts. To avoid this, refactor existing
tests to avoid returning a value.

[1] #6075


The Service Worker test I've modified returns a "thenable" which is actually
amenable to the proposed testharness.js extension. We could leave it as-is,
and when/if an implementation for gh-6075 lands, that test would become less
fragile automatically. Still, it seems safer to introduce the new functionality
with the confidence that it doesn't trigger any implicit opt-in, and then
incrementally begin to use it with intentional follow-up commits. (And for the
Service Worker test suite, this will entail updating many files besides the one
modified here.)

For those curious: I located these tests programatically by modifying the test
runner
and using that to run all tests that reference add_cleanup:

grep 'add_cleanup' . -rl --include '*.js' --include '*.html' | xargs ./wpt run chrome

And

grep 'add_cleanup' . -rl --include '*.js' --include '*.html' | xargs ./wpt run firefox

Both browsers identified the same usages.

Today, the return value of functions provided to the global
`add_cleanup` function has no effect on the behavior of the test runner.
An upcoming feature addition to `testharness.js` will cause the return
value to influence test results [1].

Despite this, some existing tests have already been authored to return a
value. Introducing the new test harness functionality may trigger
unexpected results in those contexts. To avoid this, refactor existing
tests to avoid returning a value.

[1] web-platform-tests#6075
@ghost

ghost commented Dec 19, 2017 •

Copy link
Copy Markdown

Build PASSED

Started: 2017-12-20 16:36:09
Finished: 2017-12-20 16:39:24

View more information about this build on:

@foolip foolip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM % tracking the remaining work.

return service_worker_unregister_and_register(t, script, scope)
.then(r => {
t.add_cleanup(() => r.unregister());
t.add_cleanup(() => { r.unregister(); });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a TODO here to revert it back when promise cleanup has landed?

return service_worker_unregister_and_register(t, script, scope)
.then(r => {
t.add_cleanup(() => r.unregister());
t.add_cleanup(() => { r.unregister(); });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure thing

@foolip
foolip merged commit 52ee88c into web-platform-tests:master Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants