Bug 181499 - [iOS WK2] Layout Test imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html is a flaky failure
Summary: [iOS WK2] Layout Test imported/w3c/web-platform-tests/service-workers/service...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-01-10 14:48 PST by Ryan Haddad
Modified: 2018-05-24 11:10 PDT (History)
7 users (show)

See Also:


Attachments
Patch (9.26 KB, patch)
2018-05-23 15:09 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (9.38 KB, patch)
2018-05-23 16:43 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews106 for mac-sierra-wk2 (3.45 MB, application/zip)
2018-05-23 17:45 PDT, EWS Watchlist
no flags Details
Patch (10.10 KB, patch)
2018-05-24 10:15 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Haddad 2018-01-10 14:48:33 PST
The following layout test is flaky on iOS Release WK2

imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html

Probable cause:

The first failure visible on the dashboard blames https://trac.webkit.org/changeset/226275/webkit

Flakiness Dashboard:

https://webkit-test-results.webkit.org/dashboards/flakiness_dashboard.html#showAllRuns=true&tests=imported%2Fw3c%2Fweb-platform-tests%2Fservice-workers%2Fservice-worker%2Fupdate-after-navigation-fetch-event.https.html

--- /Volumes/Data/slave/ios-simulator-11-release-tests-wk2/build/layout-test-results/imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https-expected.txt
+++ /Volumes/Data/slave/ios-simulator-11-release-tests-wk2/build/layout-test-results/imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https-actual.txt
@@ -1,3 +1,6 @@
 
-PASS Update should be triggered after a navigation fetch event. 
 
+Harness Error (TIMEOUT), message = null
+
+TIMEOUT Update should be triggered after a navigation fetch event. Test timed out
+
Comment 1 Radar WebKit Bug Importer 2018-01-11 10:59:40 PST
<rdar://problem/36443428>
Comment 2 Ryan Haddad 2018-01-18 20:26:14 PST
Marked test as flaky in https://trac.webkit.org/changeset/227179/webkit.
Comment 3 Chris Dumez 2018-05-22 15:12:06 PDT
Looking at the flakiness dashboard, it is almost all green. There is exactly one failure and it is a TEXT one, not a TIMEOUT:
--- /Volumes/Data/slave/ios-simulator-11-debug-tests-wk2/build/layout-test-results/imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https-expected.txt
+++ /Volumes/Data/slave/ios-simulator-11-debug-tests-wk2/build/layout-test-results/imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https-actual.txt
@@ -1,3 +1,3 @@
 
-PASS Update should be triggered after a navigation fetch event. 
+FAIL Update should be triggered after a navigation fetch event. promise_test: Unhandled rejection with value: object "Error: wait_for_state must be passed a ServiceWorker"
Comment 4 Chris Dumez 2018-05-22 15:23:31 PDT
(In reply to Chris Dumez from comment #3)
> Looking at the flakiness dashboard, it is almost all green. There is exactly
> one failure and it is a TEXT one, not a TIMEOUT:
> ---
> /Volumes/Data/slave/ios-simulator-11-debug-tests-wk2/build/layout-test-
> results/imported/w3c/web-platform-tests/service-workers/service-worker/
> update-after-navigation-fetch-event.https-expected.txt
> +++
> /Volumes/Data/slave/ios-simulator-11-debug-tests-wk2/build/layout-test-
> results/imported/w3c/web-platform-tests/service-workers/service-worker/
> update-after-navigation-fetch-event.https-actual.txt
> @@ -1,3 +1,3 @@
>  
> -PASS Update should be triggered after a navigation fetch event. 
> +FAIL Update should be triggered after a navigation fetch event.
> promise_test: Unhandled rejection with value: object "Error: wait_for_state
> must be passed a ServiceWorker"

The test looks like:
return service_worker_unregister_and_register(t, parsed_url, scope)
      .then(function(r) {
          registration = r;
          return wait_for_state(t, registration.installing, 'activated');
        })

wait_for_state() is given null so registration.installing is null. I believe this means that the worker is already active. This can happen when registering a service worker that is already registered. The test attempts to unregister *then* register. However, because of the "Try Clear Registration" algorithm, the registration might be kept, simply marked as uninstalling.
Comment 5 Chris Dumez 2018-05-22 15:25:50 PDT
(In reply to Chris Dumez from comment #4)
> (In reply to Chris Dumez from comment #3)
> > Looking at the flakiness dashboard, it is almost all green. There is exactly
> > one failure and it is a TEXT one, not a TIMEOUT:
> > ---
> > /Volumes/Data/slave/ios-simulator-11-debug-tests-wk2/build/layout-test-
> > results/imported/w3c/web-platform-tests/service-workers/service-worker/
> > update-after-navigation-fetch-event.https-expected.txt
> > +++
> > /Volumes/Data/slave/ios-simulator-11-debug-tests-wk2/build/layout-test-
> > results/imported/w3c/web-platform-tests/service-workers/service-worker/
> > update-after-navigation-fetch-event.https-actual.txt
> > @@ -1,3 +1,3 @@
> >  
> > -PASS Update should be triggered after a navigation fetch event. 
> > +FAIL Update should be triggered after a navigation fetch event.
> > promise_test: Unhandled rejection with value: object "Error: wait_for_state
> > must be passed a ServiceWorker"
> 
> The test looks like:
> return service_worker_unregister_and_register(t, parsed_url, scope)
>       .then(function(r) {
>           registration = r;
>           return wait_for_state(t, registration.installing, 'activated');
>         })
> 
> wait_for_state() is given null so registration.installing is null. I believe
> this means that the worker is already active. This can happen when
> registering a service worker that is already registered. The test attempts
> to unregister *then* register. However, because of the "Try Clear
> Registration" algorithm, the registration might be kept, simply marked as
> uninstalling.

Interestingly, this service worker is indeed used by several tests:
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/multiple-update.https.html:    var script = 'resources/update-nocookie-worker.py';
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html:    var script = 'resources/update-nocookie-worker.py';
LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update-after-oneday.https.html:    var script = 'resources/update-nocookie-worker.py';
Comment 6 Chris Dumez 2018-05-23 09:00:26 PDT
(In reply to Chris Dumez from comment #5)
> (In reply to Chris Dumez from comment #4)
> > (In reply to Chris Dumez from comment #3)
> > > Looking at the flakiness dashboard, it is almost all green. There is exactly
> > > one failure and it is a TEXT one, not a TIMEOUT:
> > > ---
> > > /Volumes/Data/slave/ios-simulator-11-debug-tests-wk2/build/layout-test-
> > > results/imported/w3c/web-platform-tests/service-workers/service-worker/
> > > update-after-navigation-fetch-event.https-expected.txt
> > > +++
> > > /Volumes/Data/slave/ios-simulator-11-debug-tests-wk2/build/layout-test-
> > > results/imported/w3c/web-platform-tests/service-workers/service-worker/
> > > update-after-navigation-fetch-event.https-actual.txt
> > > @@ -1,3 +1,3 @@
> > >  
> > > -PASS Update should be triggered after a navigation fetch event. 
> > > +FAIL Update should be triggered after a navigation fetch event.
> > > promise_test: Unhandled rejection with value: object "Error: wait_for_state
> > > must be passed a ServiceWorker"
> > 
> > The test looks like:
> > return service_worker_unregister_and_register(t, parsed_url, scope)
> >       .then(function(r) {
> >           registration = r;
> >           return wait_for_state(t, registration.installing, 'activated');
> >         })
> > 
> > wait_for_state() is given null so registration.installing is null. I believe
> > this means that the worker is already active. This can happen when
> > registering a service worker that is already registered. The test attempts
> > to unregister *then* register. However, because of the "Try Clear
> > Registration" algorithm, the registration might be kept, simply marked as
> > uninstalling.
> 
> Interestingly, this service worker is indeed used by several tests:
> LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/
> multiple-update.https.html:    var script =
> 'resources/update-nocookie-worker.py';
> LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/
> update-after-navigation-fetch-event.https.html:    var script =
> 'resources/update-nocookie-worker.py';
> LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/
> update-after-oneday.https.html:    var script =
> 'resources/update-nocookie-worker.py';

Looks like I may have been wrong that the issue is with tryClear not calling clear in some cases. I was able to reproduce the test failure without having a register job reusing an existing registration.
Comment 7 Chris Dumez 2018-05-23 15:09:42 PDT
Created attachment 341134 [details]
Patch
Comment 8 Chris Dumez 2018-05-23 16:43:00 PDT
Created attachment 341145 [details]
Patch
Comment 9 EWS Watchlist 2018-05-23 17:45:33 PDT
Comment on attachment 341145 [details]
Patch

Attachment 341145 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/7782552

New failing tests:
accessibility/smart-invert-reference.html
Comment 10 EWS Watchlist 2018-05-23 17:45:34 PDT
Created attachment 341153 [details]
Archive of layout-test-results from ews106 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 11 Chris Dumez 2018-05-24 08:47:27 PDT
Comment on attachment 341153 [details]
Archive of layout-test-results from ews106 for mac-sierra-wk2

failure is unrelated.
Comment 12 youenn fablet 2018-05-24 09:17:22 PDT
Comment on attachment 341145 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=341145&action=review

> Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp:73
> +void DeferredPromise::whenSettled(std::function<void()>&& callback)

This is more or less the same code as DOMPromise::whenSettled.
Could we try to share it?

> Source/WebCore/workers/service/ServiceWorkerContainer.cpp:453
> +        });

whenSettled call is not needed if shouldNotifyWhenResolved == ShouldNotifyWhenResolved::No.
Maybe notifyWhenResolvedIfNeeded should be an optional<std::function>
Comment 13 Chris Dumez 2018-05-24 10:15:05 PDT
Created attachment 341202 [details]
Patch
Comment 14 WebKit Commit Bot 2018-05-24 11:10:11 PDT
Comment on attachment 341202 [details]
Patch

Clearing flags on attachment: 341202

Committed r232156: <https://trac.webkit.org/changeset/232156>
Comment 15 WebKit Commit Bot 2018-05-24 11:10:13 PDT
All reviewed patches have been landed.  Closing bug.