Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
[cookie-store] Deflake service worker registration
Browse files Browse the repository at this point in the history
Instead of attempting to unregister previously installed service workers
at the beginning of a test, use `add_completion_callback` to unregister
them at test completion. This will deflake the tests when they are run
multiple times without restarts (`--rerun`).

The alternative is to do what many tests in service-workers do:
unregister service workers at the start, but wait for newly installed
service workers to become activated and use `registration.active`
instead of `registration.installing`, which is a bit more complex.
  • Loading branch information
Hexcles committed Aug 8, 2019
1 parent c0b0a0d commit cc9dc6b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
(async () => {
const scope = 'does/not/exist';

let registration = await navigator.serviceWorker.getRegistration(scope);
if (registration)
await registration.unregister();
registration = await navigator.serviceWorker.register(
const registration = await navigator.serviceWorker.register(
'serviceworker_cookieStore_arguments.js', {scope});
add_completion_callback(() => {
registration.unregister();
});

fetch_tests_from_worker(registration.installing);
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
(async () => {
const scope = 'does/not/exist';

let registration = await navigator.serviceWorker.getRegistration(scope);
if (registration)
await registration.unregister();
registration = await navigator.serviceWorker.register(
const registration = await navigator.serviceWorker.register(
'serviceworker_cookieStore_basic.js', {scope});
add_completion_callback(() => {
registration.unregister();
});

fetch_tests_from_worker(registration.installing);
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// Not using an explicit scope here in order for script URL to be in scope,
// to cover implicit subscription URL construction.

let registration = await navigator.serviceWorker.getRegistration();
if (registration)
await registration.unregister();
registration = await navigator.serviceWorker.register(
const registration = await navigator.serviceWorker.register(
'serviceworker_cookieStore_subscriptions.js');
add_completion_callback(() => {
registration.unregister();
});

fetch_tests_from_worker(registration.installing);
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
(async () => {
const scope = 'scope';

let registration = await navigator.serviceWorker.getRegistration(scope);
if (registration)
await registration.unregister();
registration = await navigator.serviceWorker.register(
const registration = await navigator.serviceWorker.register(
'serviceworker_cookieStore_subscriptions_basic.js', {scope});
add_completion_callback(() => {
registration.unregister();
});

fetch_tests_from_worker(registration.installing);
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
(async () => {
const scope = 'scope';

let registration = await navigator.serviceWorker.getRegistration(scope);
if (registration)
await registration.unregister();
registration = await navigator.serviceWorker.register(
const registration = await navigator.serviceWorker.register(
'serviceworker_cookieStore_subscriptions_empty.js', {scope});
add_completion_callback(() => {
registration.unregister();
});

fetch_tests_from_worker(registration.installing);
})();
Expand Down

0 comments on commit cc9dc6b

Please sign in to comment.