Bug 221848

Summary: REGRESSION (r268421): TestWebKitAPI.WebKit.PreferenceChanges* tests are flaky failures
Product: WebKit Reporter: Ryan Haddad <ryanhaddad>
Component: New BugsAssignee: Per Arne Vollan <pvollan>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, bfulgham, cdumez, jenner, pvollan, webkit-bot-watchers-bugzilla, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=222825
Attachments:
Description Flags
Patch
none
Patch none

Description Ryan Haddad 2021-02-12 13:57:59 PST
REGRESSION (r268421): TestWebKitAPI.WebKit.PreferenceChanges* tests are flaky failures

TestWebKitAPI.WebKit.PreferenceChangesDate
TestWebKitAPI.WebKit.PreferenceChangesArray
TestWebKitAPI.WebKit.PreferenceChangesData
TestWebKitAPI.WebKit.PreferenceChangesNil
Comment 1 Ryan Haddad 2021-02-12 13:58:10 PST
These tests were disabled in https://trac.webkit.org/changeset/270510/webkit
Comment 2 Ryan Haddad 2021-02-12 13:58:43 PST
<rdar://problem/70966379>
Comment 3 Ryan Haddad 2021-03-22 14:51:27 PDT
*** Bug 221781 has been marked as a duplicate of this bug. ***
Comment 4 Ryan Haddad 2021-03-22 14:53:41 PDT
I also disabled TestWebKitAPI.WebKit.GlobalPreferenceChangesUsingDefaultsWrite in https://commits.webkit.org/234051@main
Comment 5 Per Arne Vollan 2021-11-01 17:10:50 PDT
Created attachment 443038 [details]
Patch
Comment 6 Brent Fulgham 2021-11-01 20:44:21 PDT
Comment on attachment 443038 [details]
Patch

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

> Tools/TestWebKitAPI/Tests/WebKit/PreferenceChanges.mm:191
> +        TestWebKitAPI::Util::spinRunLoop();

This will potentially slow down the process. Is it possible to wait until a sync has happened (perhaps using an event or completion handler)?

> Tools/TestWebKitAPI/Tests/WebKit/PreferenceChanges.mm:223
> +    for (;;) {

It seems like this could hang the test.
Comment 7 Per Arne Vollan 2021-11-02 10:17:04 PDT
Created attachment 443103 [details]
Patch
Comment 8 Per Arne Vollan 2021-11-02 10:26:15 PDT
(In reply to Brent Fulgham from comment #6)
> Comment on attachment 443038 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=443038&action=review
> 
> > Tools/TestWebKitAPI/Tests/WebKit/PreferenceChanges.mm:191
> > +        TestWebKitAPI::Util::spinRunLoop();
> 
> This will potentially slow down the process. Is it possible to wait until a
> sync has happened (perhaps using an event or completion handler)?
> 

That is a good point. I think we for example could post a notification in the WebContent process when a preference is set, which TestWebKitAPI could then subscribe to. There is some ambiguity to this approach, however, since we're not using WebKit API to set the preference, but using NSUserDefaults directly. This means it is not trivial to match the preference change made by TestWebKitAPI with the corresponding notification, since the preference change could also have come from elsewhere. Due to this ambiguity, I did not go down this road, but added a sleep interval to the loop in order to avoid using too much CPU. Would you be OK with that approach?

> > Tools/TestWebKitAPI/Tests/WebKit/PreferenceChanges.mm:223
> > +    for (;;) {
> 
> It seems like this could hang the test.

Fixed in the latest patch by exiting the loop after N number of iterations.

Thanks for reviewing!
Comment 9 Brent Fulgham 2021-11-02 10:32:41 PDT
Comment on attachment 443038 [details]
Patch

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

>>> Tools/TestWebKitAPI/Tests/WebKit/PreferenceChanges.mm:191
>>> +        TestWebKitAPI::Util::spinRunLoop();
>> 
>> This will potentially slow down the process. Is it possible to wait until a sync has happened (perhaps using an event or completion handler)?
> 
> That is a good point. I think we for example could post a notification in the WebContent process when a preference is set, which TestWebKitAPI could then subscribe to. There is some ambiguity to this approach, however, since we're not using WebKit API to set the preference, but using NSUserDefaults directly. This means it is not trivial to match the preference change made by TestWebKitAPI with the corresponding notification, since the preference change could also have come from elsewhere. Due to this ambiguity, I did not go down this road, but added a sleep interval to the loop in order to avoid using too much CPU. Would you be OK with that approach?

Is there no notification sent when NSUserDefaults changes a value? I believe that a process can subscribe to notifications so that when a user changes a preference the app can react. It might be that we receive notifications for unrelated preference changes, so we would want to see what preference changed and ignore unrelated ones.
Comment 10 Per Arne Vollan 2021-11-02 12:52:50 PDT
(In reply to Brent Fulgham from comment #9)
> Comment on attachment 443038 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=443038&action=review
> 
> >>> Tools/TestWebKitAPI/Tests/WebKit/PreferenceChanges.mm:191
> >>> +        TestWebKitAPI::Util::spinRunLoop();
> >> 
> >> This will potentially slow down the process. Is it possible to wait until a sync has happened (perhaps using an event or completion handler)?
> > 
> > That is a good point. I think we for example could post a notification in the WebContent process when a preference is set, which TestWebKitAPI could then subscribe to. There is some ambiguity to this approach, however, since we're not using WebKit API to set the preference, but using NSUserDefaults directly. This means it is not trivial to match the preference change made by TestWebKitAPI with the corresponding notification, since the preference change could also have come from elsewhere. Due to this ambiguity, I did not go down this road, but added a sleep interval to the loop in order to avoid using too much CPU. Would you be OK with that approach?
> 
> Is there no notification sent when NSUserDefaults changes a value? I believe
> that a process can subscribe to notifications so that when a user changes a
> preference the app can react. It might be that we receive notifications for
> unrelated preference changes, so we would want to see what preference
> changed and ignore unrelated ones.

I believe it is possible to use KVO to listen to changes for a specific preference key. Since this requires sandbox access to the preference daemon, which is blocked in the WebContent process, it might not be applicable in this case. Should we create a custom notification that we post from WP when a preference change message is received? TestWebKitAPI could then listen to this notification, and we could avoid the loop in the test.

Thanks for reviewing!
Comment 11 Brent Fulgham 2021-11-02 14:09:38 PDT
Comment on attachment 443038 [details]
Patch

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

>>>>> Tools/TestWebKitAPI/Tests/WebKit/PreferenceChanges.mm:191
>>>>> +        TestWebKitAPI::Util::spinRunLoop();
>>>> 
>>>> This will potentially slow down the process. Is it possible to wait until a sync has happened (perhaps using an event or completion handler)?
>>> 
>>> That is a good point. I think we for example could post a notification in the WebContent process when a preference is set, which TestWebKitAPI could then subscribe to. There is some ambiguity to this approach, however, since we're not using WebKit API to set the preference, but using NSUserDefaults directly. This means it is not trivial to match the preference change made by TestWebKitAPI with the corresponding notification, since the preference change could also have come from elsewhere. Due to this ambiguity, I did not go down this road, but added a sleep interval to the loop in order to avoid using too much CPU. Would you be OK with that approach?
>> 
>> Is there no notification sent when NSUserDefaults changes a value? I believe that a process can subscribe to notifications so that when a user changes a preference the app can react. It might be that we receive notifications for unrelated preference changes, so we would want to see what preference changed and ignore unrelated ones.
> 
> I believe it is possible to use KVO to listen to changes for a specific preference key. Since this requires sandbox access to the preference daemon, which is blocked in the WebContent process, it might not be applicable in this case. Should we create a custom notification that we post from WP when a preference change message is received? TestWebKitAPI could then listen to this notification, and we could avoid the loop in the test.
> 
> Thanks for reviewing!

Ah! That's a great reason to not use KVO. Thanks for clarifying.
Comment 12 Brent Fulgham 2021-11-02 14:10:09 PDT
Comment on attachment 443103 [details]
Patch

r=me
Comment 13 Per Arne Vollan 2021-11-02 14:13:02 PDT
Comment on attachment 443103 [details]
Patch

Thanks for reviewing!
Comment 14 EWS 2021-11-02 14:48:30 PDT
Committed r285184 (243813@main): <https://commits.webkit.org/243813@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 443103 [details].