Changeset 244251 in webkit


Ignore:
Timestamp:
Apr 14, 2019 9:47:39 PM (5 years ago)
Author:
Wenson Hsieh
Message:

API test WKAttachmentTests.AddAttachmentToConnectedImageElement is a flaky failure on Mac Release builds
https://bugs.webkit.org/show_bug.cgi?id=196905
<rdar://problem/49886096>

Reviewed by Tim Horton.

This flaky test exercises a race condition between when attachment insertion updates are dispatched from the web
process to the UI process, and when script is executed via -[WKWebView evaluateJavaScript:completionHandler:].
Since attachment insertion and removal updates from the web process to the UI process are scheduled on a zero-
delay timer, we end up with this sequence of events in the problematic (failure) case:

(a) [UI] Run script #1 (which calls HTMLAttachmentElement.getAttachmentIdentifier)

...IPC from UI to web process...

(b) [Web] Evaluate script #1 in the web process, which schedules attachment updates on a zero-delay timer

...IPC from web to UI process...

(c) [UI] Invoke completion handler for script #1
(d) [UI] Run script #2 (which calls document.querySelector('img').attachmentIdentifier)

...IPC from UI to web process...

(e) [Web] Evaluate script #2 in the web process
(f) [Web] Zero-delay timer fires and dispatches attachment updates to the UI process

...which means that script #2 will complete before the UI process has received the attachment updates sent in
step (f). However, in the case where the flaky test succeeds, the zero-delay timer in (f) fires *before* script
#2 is run in step (e).

This patch fixes the flaky test by waiting until attachment insertion updates are guaranteed to be received in
the UI process by waiting on a script message posted by the web process, after attachment updates are
dispatched.

  • TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:

(TestWebKitAPI::TEST):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r244249 r244251  
     12019-04-14  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        API test WKAttachmentTests.AddAttachmentToConnectedImageElement is a flaky failure on Mac Release builds
     4        https://bugs.webkit.org/show_bug.cgi?id=196905
     5        <rdar://problem/49886096>
     6
     7        Reviewed by Tim Horton.
     8
     9        This flaky test exercises a race condition between when attachment insertion updates are dispatched from the web
     10        process to the UI process, and when script is executed via -[WKWebView evaluateJavaScript:completionHandler:].
     11        Since attachment insertion and removal updates from the web process to the UI process are scheduled on a zero-
     12        delay timer, we end up with this sequence of events in the problematic (failure) case:
     13
     14        (a) [UI]    Run script #1 (which calls `HTMLAttachmentElement.getAttachmentIdentifier`)
     15            ...IPC from UI to web process...
     16        (b) [Web]   Evaluate script #1 in the web process, which schedules attachment updates on a zero-delay timer
     17            ...IPC from web to UI process...
     18        (c) [UI]    Invoke completion handler for script #1
     19        (d) [UI]    Run script #2 (which calls `document.querySelector('img').attachmentIdentifier`)
     20            ...IPC from UI to web process...
     21        (e) [Web]   Evaluate script #2 in the web process
     22        (f) [Web]   Zero-delay timer fires and dispatches attachment updates to the UI process
     23
     24        ...which means that script #2 will complete before the UI process has received the attachment updates sent in
     25        step (f). However, in the case where the flaky test succeeds, the zero-delay timer in (f) fires *before* script
     26        #2 is run in step (e).
     27
     28        This patch fixes the flaky test by waiting until attachment insertion updates are guaranteed to be received in
     29        the UI process by waiting on a script message posted by the web process, after attachment updates are
     30        dispatched.
     31
     32        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
     33        (TestWebKitAPI::TEST):
     34
    1352019-04-14  Aakash Jain  <aakash_jain@apple.com>
    236
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm

    r244249 r244251  
    13471347}
    13481348
    1349 TEST(WKAttachmentTests, DISABLED_AddAttachmentToConnectedImageElement)
     1349TEST(WKAttachmentTests, AddAttachmentToConnectedImageElement)
    13501350{
    13511351    auto webView = webViewForTestingAttachments();
    13521352    [webView _synchronouslyExecuteEditCommand:@"InsertHTML" argument:@"<img></img>"];
    13531353
     1354    __block bool doneWaitingForAttachmentInsertion = false;
     1355    [webView performAfterReceivingMessage:@"inserted" action:^{
     1356        doneWaitingForAttachmentInsertion = true;
     1357    }];
     1358
     1359    const char *scriptForEnsuringAttachmentIdentifier = \
     1360        "const identifier = HTMLAttachmentElement.getAttachmentIdentifier(document.querySelector('img'));"
     1361        "setTimeout(() => webkit.messageHandlers.testHandler.postMessage('inserted'), 0);"
     1362        "identifier";
     1363
    13541364    ObserveAttachmentUpdatesForScope observer(webView.get());
    1355     NSString *attachmentIdentifier = [webView stringByEvaluatingJavaScript:@"HTMLAttachmentElement.getAttachmentIdentifier(document.querySelector('img'))"];
     1365    NSString *attachmentIdentifier = [webView stringByEvaluatingJavaScript:@(scriptForEnsuringAttachmentIdentifier)];
    13561366    auto attachment = retainPtr([webView _attachmentForIdentifier:attachmentIdentifier]);
    13571367    EXPECT_WK_STREQ(attachmentIdentifier, [attachment uniqueIdentifier]);
    13581368    EXPECT_WK_STREQ(attachmentIdentifier, [webView stringByEvaluatingJavaScript:@"document.querySelector('img').attachmentIdentifier"]);
     1369    Util::run(&doneWaitingForAttachmentInsertion);
    13591370    observer.expectAttachmentUpdates(@[ ], @[ attachment.get() ]);
    13601371
Note: See TracChangeset for help on using the changeset viewer.