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

Commit cc9dc6b

Browse files
committed
[cookie-store] Deflake service worker registration
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.
1 parent c0b0a0d commit cc9dc6b

5 files changed

+20
-20
lines changed

cookie-store/serviceworker_cookieStore_arguments.tentative.https.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
(async () => {
1212
const scope = 'does/not/exist';
1313

14-
let registration = await navigator.serviceWorker.getRegistration(scope);
15-
if (registration)
16-
await registration.unregister();
17-
registration = await navigator.serviceWorker.register(
14+
const registration = await navigator.serviceWorker.register(
1815
'serviceworker_cookieStore_arguments.js', {scope});
16+
add_completion_callback(() => {
17+
registration.unregister();
18+
});
1919

2020
fetch_tests_from_worker(registration.installing);
2121
})();

cookie-store/serviceworker_cookieStore_basic.tentative.https.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
(async () => {
1212
const scope = 'does/not/exist';
1313

14-
let registration = await navigator.serviceWorker.getRegistration(scope);
15-
if (registration)
16-
await registration.unregister();
17-
registration = await navigator.serviceWorker.register(
14+
const registration = await navigator.serviceWorker.register(
1815
'serviceworker_cookieStore_basic.js', {scope});
16+
add_completion_callback(() => {
17+
registration.unregister();
18+
});
1919

2020
fetch_tests_from_worker(registration.installing);
2121
})();

cookie-store/serviceworker_cookieStore_subscriptions.tentative.https.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// Not using an explicit scope here in order for script URL to be in scope,
1313
// to cover implicit subscription URL construction.
1414

15-
let registration = await navigator.serviceWorker.getRegistration();
16-
if (registration)
17-
await registration.unregister();
18-
registration = await navigator.serviceWorker.register(
15+
const registration = await navigator.serviceWorker.register(
1916
'serviceworker_cookieStore_subscriptions.js');
17+
add_completion_callback(() => {
18+
registration.unregister();
19+
});
2020

2121
fetch_tests_from_worker(registration.installing);
2222
})();

cookie-store/serviceworker_cookieStore_subscriptions_basic.tentative.https.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
(async () => {
1212
const scope = 'scope';
1313

14-
let registration = await navigator.serviceWorker.getRegistration(scope);
15-
if (registration)
16-
await registration.unregister();
17-
registration = await navigator.serviceWorker.register(
14+
const registration = await navigator.serviceWorker.register(
1815
'serviceworker_cookieStore_subscriptions_basic.js', {scope});
16+
add_completion_callback(() => {
17+
registration.unregister();
18+
});
1919

2020
fetch_tests_from_worker(registration.installing);
2121
})();

cookie-store/serviceworker_cookieStore_subscriptions_empty.tentative.https.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
(async () => {
1111
const scope = 'scope';
1212

13-
let registration = await navigator.serviceWorker.getRegistration(scope);
14-
if (registration)
15-
await registration.unregister();
16-
registration = await navigator.serviceWorker.register(
13+
const registration = await navigator.serviceWorker.register(
1714
'serviceworker_cookieStore_subscriptions_empty.js', {scope});
15+
add_completion_callback(() => {
16+
registration.unregister();
17+
});
1818

1919
fetch_tests_from_worker(registration.installing);
2020
})();

0 commit comments

Comments
 (0)