Skip to content

Commit

Permalink
ServiceWorker: Deflake update-with-script-type.https.html
Browse files Browse the repository at this point in the history
To sheriff: Please re-disable the test if it's still flaky.

In this test file, some tests start re-registering the second service worker
before the first service worker gets activated. In my theory, this sometimes
squashes the second registration job into the first registration job, and
results in test flakiness. This CL makes sure the second register runs after
the first service worker gets activated.

Note that it would be the correct behavior that the second registration job
isn't squashed when the script type is changed. There is a spec issue about
this: w3c/ServiceWorker#1358

Bug: 901317
Change-Id: I7ce379071a35ef9aeb98e4492d651ee6fc4714ec
Reviewed-on: https://chromium-review.googlesource.com/c/1328546
Reviewed-by: Makoto Shimazu <[email protected]>
Commit-Queue: Hiroki Nakagawa <[email protected]>
Cr-Commit-Position: refs/heads/master@{#607494}
  • Loading branch information
nhiroki authored and foolip committed Nov 13, 2018
1 parent 5abc7ea commit 3571d11
Showing 1 changed file with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,30 @@
const script = `resources/update-registration-with-type.py?classic_first=1&key=${key}`;
const scope = 'resources/update-registration-with-type';
await service_worker_unregister(t, scope);
t.add_cleanup(() => service_worker_unregister(t, scope));

// Register with classic script type.
const firstRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'classic'
});
firstRegistration.installing.postMessage(' ');
let msgEvent = await new Promise(resolve => {
navigator.serviceWorker.onmessage = resolve;
});
const firstWorker = firstRegistration.installing;
await wait_for_state(t, firstWorker, 'activated');
firstWorker.postMessage(' ');
let msgEvent = await new Promise(r => navigator.serviceWorker.onmessage = r);
assert_equals(msgEvent.data, 'A classic script.');

// Re-register with module script type.
const secondRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'module'
});
secondRegistration.installing.postMessage(' ');
msgEvent = await new Promise(resolve => {
navigator.serviceWorker.onmessage = resolve;
});
const secondWorker = secondRegistration.installing;
secondWorker.postMessage(' ');
msgEvent = await new Promise(r => navigator.serviceWorker.onmessage = r);
assert_equals(msgEvent.data, 'A module script.');

assert_not_equals(firstWorker, secondWorker);
assert_equals(firstRegistration, secondRegistration);
}, 'Update the registration with a different script type (classic => module).');

Expand All @@ -46,28 +48,30 @@
const script = `resources/update-registration-with-type.py?classic_first=0&key=${key}`;
const scope = 'resources/update-registration-with-type';
await service_worker_unregister(t, scope);
t.add_cleanup(() => service_worker_unregister(t, scope));

// Register with module script type.
const firstRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'module'
});
firstRegistration.installing.postMessage(' ');
let msgEvent = await new Promise(resolve => {
navigator.serviceWorker.onmessage = resolve;
});
const firstWorker = firstRegistration.installing;
await wait_for_state(t, firstWorker, 'activated');
firstWorker.postMessage(' ');
let msgEvent = await new Promise(r => navigator.serviceWorker.onmessage = r);
assert_equals(msgEvent.data, 'A module script.');

// Re-register with classic script type.
const secondRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'classic'
});
secondRegistration.installing.postMessage(' ');
msgEvent = await new Promise(resolve => {
navigator.serviceWorker.onmessage = resolve;
});
const secondWorker = secondRegistration.installing;
secondWorker.postMessage(' ');
msgEvent = await new Promise(r => navigator.serviceWorker.onmessage = r);
assert_equals(msgEvent.data, 'A classic script.');

assert_not_equals(firstWorker, secondWorker);
assert_equals(firstRegistration, secondRegistration);
}, 'Update the registration with a different script type (module => classic).');

Expand All @@ -84,18 +88,17 @@
scope: scope,
type: 'classic'
});
await wait_for_state(t, firstRegistration.installing, 'activated');
const firstActiveWorker = firstRegistration.active;
const firstWorker = firstRegistration.installing;
await wait_for_state(t, firstWorker, 'activated');

// Re-register with module script type.
const secondRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'module'
});
await wait_for_state(t, secondRegistration.installing, 'activated');
const secondActiveWorker = secondRegistration.active;
const secondWorker = secondRegistration.installing;

assert_not_equals(firstActiveWorker, secondActiveWorker);
assert_not_equals(firstWorker, secondWorker);
assert_equals(firstRegistration, secondRegistration);
}, 'Update the registration with a different script type (classic => module) '
+ 'and with a same main script.');
Expand All @@ -111,18 +114,17 @@
scope: scope,
type: 'module'
});
await wait_for_state(t, firstRegistration.installing, 'activated');
const firstActiveWorker = firstRegistration.active;
const firstWorker = firstRegistration.installing;
await wait_for_state(t, firstWorker, 'activated');

// Re-register with classic script type.
const secondRegistration = await navigator.serviceWorker.register(script, {
scope: scope,
type: 'classic'
});
await wait_for_state(t, secondRegistration.installing, 'activated');
const secondActiveWorker = secondRegistration.active;
const secondWorker = secondRegistration.installing;

assert_not_equals(firstActiveWorker, secondActiveWorker);
assert_not_equals(firstWorker, secondWorker);
assert_equals(firstRegistration, secondRegistration);
}, 'Update the registration with a different script type (module => classic) '
+ 'and with a same main script.');
Expand Down Expand Up @@ -168,6 +170,7 @@
type: 'classic'
});
assert_not_equals(firstRegistration.installing, null);
await wait_for_state(t, firstRegistration.installing, 'activated');

// Re-register with module script type and expect TypeError.
return promise_rejects(t, new TypeError, navigator.serviceWorker.register(script, {
Expand All @@ -192,6 +195,7 @@
type: 'module'
});
assert_not_equals(firstRegistration.installing, null);
await wait_for_state(t, firstRegistration.installing, 'activated');

// Re-register with classic script type and expect TypeError.
return promise_rejects(t, new TypeError, navigator.serviceWorker.register(script, {
Expand Down

0 comments on commit 3571d11

Please sign in to comment.