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

service workers: Simplified tests with async/await - Part 1 #13103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wanghongjuan
Copy link
Contributor

[NewObject] Promise unregister();
unregister() method must run these steps:

  1. Let promise be a promise.
    ...
  2. Return promise.

@ghost
Copy link

ghost commented Sep 20, 2018

No Taskcluster jobs started for this pull request
The `allowPullRequests` configuration for this repository (in `.taskcluster.yml` on the
default branch) does not allow starting tasks for this pull request.

@wanghongjuan
Copy link
Contributor Author

It's a common issue regarding to the usage of t. add_cleanup() and unregister(), which will produce a big PR that is not easy to review, so I intent to split this task into a piece of PRs. If this one is OK for you reviewers, I will continue the rest work.

@foolip
Copy link
Member

foolip commented Sep 20, 2018

The failing Travis build in this PR was due to #13112, which has now been resolved. To recover, rebase the PR on master and push. (Simply restarting the Travis jobs may also work, not tested.)

@wanghongjuan wanghongjuan force-pushed the fix-cleanup-unregister-1 branch from 8112f5a to 43fabbf Compare September 21, 2018 00:59
@ghost
Copy link

ghost commented Sep 21, 2018

No Taskcluster jobs started for this pull request
The `allowPullRequests` configuration for this repository (in `.taskcluster.yml` on the
default branch) does not allow starting tasks for this pull request.

@wanghongjuan
Copy link
Contributor Author

@foolip Thanks for your reminder, this PR was rebased and passed on Travis.

@wanghongjuan wanghongjuan force-pushed the fix-cleanup-unregister-1 branch from 43fabbf to 489bcb1 Compare September 21, 2018 03:13
@ghost
Copy link

ghost commented Sep 21, 2018

No Taskcluster jobs started for this pull request
The `allowPullRequests` configuration for this repository (in `.taskcluster.yml` on the
default branch) does not allow starting tasks for this pull request.

@wanghongjuan wanghongjuan force-pushed the fix-cleanup-unregister-1 branch from 489bcb1 to 545cd4f Compare September 25, 2018 03:17
@ghost
Copy link

ghost commented Sep 25, 2018

No Taskcluster jobs started for this pull request
The `allowPullRequests` configuration for this repository (in `.taskcluster.yml` on the
default branch) does not allow starting tasks for this pull request.

@wanghongjuan
Copy link
Contributor Author

@jugglinmike It seems that we are doing some same things for the method Test#add_cleanup and unregister(), your PRs #13164 and #13165 have covered this work, the only rest of thing is simplified tests with async/await using ES6 standard. @mkruisselbrink What do you think about this point? If it is meaningless, I will close this PR.

@foolip
Copy link
Member

foolip commented Oct 1, 2018

@wanghongjuan, see #13280 for why you're getting these comments about taskcluster. I've sent you an invite to the org which should fix this, please visit https://github.com/orgs/web-platform-tests if you can't find the invite in your email.

@wanghongjuan
Copy link
Contributor Author

@foolip Thanks for your reminder, I just find the invite and join the org.

@wanghongjuan
Copy link
Contributor Author

@mattto could you please take a look this pr?

Copy link
Member

@mfalken mfalken left a comment

Choose a reason for hiding this comment

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

Thanks, I like this change as long as it doesn't conflict with @jugglinmike's in-flight PRs.

await wait_for_state(t, worker, 'activated');
const frame = await with_iframe(SCOPE);

add_completion_callback(async() => {
Copy link
Member

Choose a reason for hiding this comment

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

add_cleanup() seems better (same comment throughout)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

if (registration)
await registration.unregister();
if (frame)
frame.remove();
Copy link
Member

Choose a reason for hiding this comment

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

It's preferable to remove the frame before unregistering, since unregister doesn't actually remove the registration until the frames are closed. (same comment throughout)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the code in latest commit.

await wait_for_state(t, worker, 'activated');
let data = await post_and_wait_for_reply(worker, 'getState');
let states = await Promise.all([data,
registration.navigationPreload.getState()]);
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer registration to line up with data rather than the opening brace.

It's personal preference, but I tend to format like the Google style guide:
"Multiline array initializers and object initializers are indented 2 spaces, with the braces on their own line, just like blocks."

So this becomes:

let states = await Promise.all([
  data,
  registration.navigationPreload.getState()
]);

You might also just run all JavaScript through prettier.io and use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your recommendation, I have updated all of code in latest commit, PTAL.

data = await post_and_wait_for_reply(worker, 'setHeaderValue');
states = await Promise.all([
post_and_wait_for_reply(worker, 'getState'),
registration.navigationPreload.getState()]);
Copy link
Member

Choose a reason for hiding this comment

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

This formatting is inconsistent with 121-123. To save time, I'd just run this through prettier.io.

});
if (result)
result.remove();
})
Copy link
Member

Choose a reason for hiding this comment

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

add semicolon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

.concat(with_iframe(scope)));
const result = results[expected_urls.length];

add_completion_callback(async() => {
Copy link
Member

Choose a reason for hiding this comment

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

add_cleanup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced with add_cleanup.

@jugglinmike
Copy link
Contributor

Thanks, I like this change as long as it doesn't conflict with @jugglinmike's in-flight PRs.

Thanks for watching out for that, @mattto! I can never resist an opportunity to answer a question with a shell script.

#!/bin/bash

(
for pr_number in "$@"; do
  curl \
    --silent \
    https://patch-diff.githubusercontent.com/raw/web-platform-tests/wpt/pull/$pr_number.patch | \
    grep -E '^[+-]{3} [ab]/' | \
    sed 's/^.\{6\}//g' | \
    sort | \
    uniq
done
) | sort | uniq -c | sort -n

The invocation

$ compare-modified.sh 13042 13164 13165 13103
1 service-workers/service-worker/about-blank-replacement.https.html
1 service-workers/service-worker/activate-event-after-install-state-change.https.html
1 service-workers/service-worker/activation-after-registration.https.html
1 service-workers/service-worker/appcache-ordering-main.https.html
1 service-workers/service-worker/claim-fetch.https.html
1 service-workers/service-worker/claim-not-using-registration.https.html
1 service-workers/service-worker/claim-shared-worker-fetch.https.html
1 service-workers/service-worker/claim-using-registration.https.html
1 service-workers/service-worker/client-id.https.html
1 service-workers/service-worker/clients-matchall-client-types.https.html
1 service-workers/service-worker/clients-matchall-exact-controller.https.html
1 service-workers/service-worker/clients-matchall.https.html
1 service-workers/service-worker/clients-matchall-include-uncontrolled.https.html
1 service-workers/service-worker/clients-matchall-order.https.html
1 service-workers/service-worker/controller-on-disconnect.https.html
1 service-workers/service-worker/controller-on-load.https.html
1 service-workers/service-worker/controller-on-reload.https.html
1 service-workers/service-worker/extendable-event-async-waituntil.https.html
1 service-workers/service-worker/extendable-event-waituntil.https.html
1 service-workers/service-worker/fetch-csp.https.html
1 service-workers/service-worker/fetch-event-after-navigation-within-page.https.html
1 service-workers/service-worker/fetch-event-async-respond-with.https.html
1 service-workers/service-worker/fetch-event-network-error.https.html
1 service-workers/service-worker/fetch-event-referrer-policy.https.html
1 service-workers/service-worker/fetch-event-respond-with-argument.https.html
1 service-workers/service-worker/fetch-event-respond-with-stops-propagation.https.html
1 service-workers/service-worker/fetch-event-throws-after-respond-with.https.html
1 service-workers/service-worker/fetch-frame-resource.https.html
1 service-workers/service-worker/fetch-header-visibility.https.html
1 service-workers/service-worker/fetch-request-css-base-url.https.html
1 service-workers/service-worker/fetch-request-css-images.https.html
1 service-workers/service-worker/fetch-request-html-imports.https.html
1 service-workers/service-worker/fetch-request-no-freshness-headers.https.html
1 service-workers/service-worker/fetch-request-redirect.https.html
1 service-workers/service-worker/fetch-response-xhr.https.html
1 service-workers/service-worker/fetch-waits-for-activate.https.html
1 service-workers/service-worker/getregistration.https.html
1 service-workers/service-worker/invalid-blobtype.https.html
1 service-workers/service-worker/invalid-header.https.html
1 service-workers/service-worker/iso-latin1-header.https.html
1 service-workers/service-worker/multiple-update.https.html
1 service-workers/service-worker/navigation-preload/broken-chunked-encoding.https.html
1 service-workers/service-worker/navigation-preload/chunked-encoding.https.html
1 service-workers/service-worker/navigation-preload/empty-preload-response-body.https.html
1 service-workers/service-worker/navigation-preload/get-state.https.html
1 service-workers/service-worker/navigation-preload/redirect.https.html
1 service-workers/service-worker/navigation-preload/request-headers.https.html
1 service-workers/service-worker/navigation-preload/resource-timing.https.html
1 service-workers/service-worker/performance-timeline.https.html
1 service-workers/service-worker/postmessage-blob-url.https.html
1 service-workers/service-worker/postmessage-from-waiting-serviceworker.https.html
1 service-workers/service-worker/postmessage.https.html
1 service-workers/service-worker/postmessage-msgport-to-client.https.html
1 service-workers/service-worker/postmessage-to-client.https.html
1 service-workers/service-worker/referer.https.html
1 service-workers/service-worker/register-default-scope.https.html
1 service-workers/service-worker/register-wait-forever-in-install-worker.https.html
1 service-workers/service-worker/registration-events.https.html
1 service-workers/service-worker/ServiceWorkerGlobalScope/postmessage.https.html
1 service-workers/service-worker/ServiceWorkerGlobalScope/unregister.https.html
1 service-workers/service-worker/ServiceWorkerGlobalScope/update.https.html
1 service-workers/service-worker/serviceworker-message-event-historical.https.html
1 service-workers/service-worker/shared-worker-controlled.https.html
1 service-workers/service-worker/skip-waiting.https.html
1 service-workers/service-worker/skip-waiting-installed.https.html
1 service-workers/service-worker/state.https.html
1 service-workers/service-worker/synced-state.https.html
1 service-workers/service-worker/uncontrolled-page.https.html
1 service-workers/service-worker/unregister-then-register.https.html
1 service-workers/service-worker/update-after-oneday.https.html
1 service-workers/service-worker/update-bytecheck.https.html
1 service-workers/service-worker/update-recovery.https.html
1 service-workers/service-worker/windowclient-navigate.https.html
1 service-workers/service-worker/worker-interception.https.html
2 service-workers/service-worker/fetch-cors-xhr.https.html
2 service-workers/service-worker/websocket.https.html

shows 2 common files between the pull requests, but neither are touched by this
pull request, so that's my problem.

@wanghongjuan
Copy link
Contributor Author

@mattto PTAL

@wanghongjuan wanghongjuan force-pushed the fix-cleanup-unregister-1 branch from 98b186e to e245813 Compare April 11, 2019 08:10
- Fix a couple of tests with function t.add_cleanup() as it supports promise, see detail in web-platform-tests#8748.
- The usage of unregister() method in some tests is not rigorous.  As [spec]\(https://w3c.github.io/ServiceWorker/#dom-serviceworkerregistration-unregister):
>>   [NewObject] Promise<boolean> unregister();
  unregister() method must run these steps:
>> 1. Let promise be a promise.
...
>> 4. Return promise.
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.

5 participants