Title: [209251] trunk/Tools
Revision
209251
Author
[email protected]
Date
2016-12-02 11:55:09 -0800 (Fri, 02 Dec 2016)

Log Message

IndexedDB.IndexedDBMultiProcess and IndexedDB.WebProcessKillIDBCleanup sometimes timeout.
https://bugs.webkit.org/show_bug.cgi?id=160780 and https://bugs.webkit.org/show_bug.cgi?id=161001

Reviewed by Alexey Proskuryakov.

These tests had "run-loop races."

The test spins the runloop waiting for one message.
Two messages might come in from the WebProcess in short succession, and both be delivered to the
UIProcess in the same spin of the runloop.

Therefore by the time the test stops spinning the runloop, notified that a message was received,
the first message has been overwritten by the second.

These tests are fixed by queueing the incoming messages instead of just storing one.

* TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess.mm:
(-[IndexedDBMPMessageHandler userContentController:didReceiveScriptMessage:]):
(getNextMessage):
(TEST):

* TestWebKitAPI/Tests/WebKit2Cocoa/WebProcessKillIDBCleanup.mm:
(-[IndexedDBWebProcessKillMessageHandler userContentController:didReceiveScriptMessage:]):
(getNextMessage):
(TEST):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (209250 => 209251)


--- trunk/Tools/ChangeLog	2016-12-02 19:34:31 UTC (rev 209250)
+++ trunk/Tools/ChangeLog	2016-12-02 19:55:09 UTC (rev 209251)
@@ -1,3 +1,31 @@
+2016-12-02  Brady Eidson  <[email protected]>
+
+        IndexedDB.IndexedDBMultiProcess and IndexedDB.WebProcessKillIDBCleanup sometimes timeout.
+        https://bugs.webkit.org/show_bug.cgi?id=160780 and https://bugs.webkit.org/show_bug.cgi?id=161001
+
+        Reviewed by Alexey Proskuryakov.
+
+        These tests had "run-loop races."
+        
+        The test spins the runloop waiting for one message.
+        Two messages might come in from the WebProcess in short succession, and both be delivered to the
+        UIProcess in the same spin of the runloop.
+
+        Therefore by the time the test stops spinning the runloop, notified that a message was received,
+        the first message has been overwritten by the second.
+
+        These tests are fixed by queueing the incoming messages instead of just storing one.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess.mm:
+        (-[IndexedDBMPMessageHandler userContentController:didReceiveScriptMessage:]):
+        (getNextMessage):
+        (TEST):
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WebProcessKillIDBCleanup.mm:
+        (-[IndexedDBWebProcessKillMessageHandler userContentController:didReceiveScriptMessage:]):
+        (getNextMessage):
+        (TEST):
+
 2016-12-01  Jiewen Tan  <[email protected]>
 
         Add a runtime flag for SubtleCrypto

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess.mm (209250 => 209251)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess.mm	2016-12-02 19:34:31 UTC (rev 209250)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBMultiProcess.mm	2016-12-02 19:55:09 UTC (rev 209251)
@@ -33,12 +33,13 @@
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/_WKProcessPoolConfiguration.h>
 #import <WebKit/_WKUserStyleSheet.h>
+#import <wtf/Deque.h>
 #import <wtf/RetainPtr.h>
 
 #if WK_API_ENABLED
 
 static bool receivedScriptMessage;
-static RetainPtr<WKScriptMessage> lastScriptMessage;
+static Deque<RetainPtr<WKScriptMessage>> scriptMessages;
 
 @interface IndexedDBMPMessageHandler : NSObject <WKScriptMessageHandler>
 @end
@@ -48,11 +49,21 @@
 - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
 {
     receivedScriptMessage = true;
-    lastScriptMessage = message;
+    scriptMessages.append(message);
 }
 
 @end
 
+static WKScriptMessage *getNextMessage()
+{
+    if (scriptMessages.isEmpty()) {
+        receivedScriptMessage = false;
+        TestWebKitAPI::Util::run(&receivedScriptMessage);
+    }
+
+    return [[scriptMessages.takeFirst() retain] autorelease];
+}
+
 TEST(IndexedDB, IndexedDBMultiProcess)
 {
     RetainPtr<IndexedDBMPMessageHandler> handler = adoptNS([[IndexedDBMPMessageHandler alloc] init]);
@@ -66,18 +77,10 @@
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"IndexedDBMultiProcess-1" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
 
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string1 = (NSString *)[lastScriptMessage body];
+    RetainPtr<NSString> string1 = (NSString *)[getNextMessage() body];
+    RetainPtr<NSString> string2 = (NSString *)[getNextMessage() body];
+    RetainPtr<NSString> string3 = (NSString *)[getNextMessage() body];
 
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string2 = (NSString *)[lastScriptMessage body];
-
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string3 = (NSString *)[lastScriptMessage body];
-
     // Make a new web view with a new web process to continue the test
     RetainPtr<WKWebView> webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
@@ -84,9 +87,7 @@
     request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"IndexedDBMultiProcess-2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView2 loadRequest:request];
 
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string4 = (NSString *)[lastScriptMessage body];
+    RetainPtr<NSString> string4 = (NSString *)[getNextMessage() body];
 
     EXPECT_WK_STREQ(@"UpgradeNeeded", string1.get());
     EXPECT_WK_STREQ(@"Transaction complete", string2.get());
@@ -93,9 +94,7 @@
     EXPECT_WK_STREQ(@"Open success", string3.get());
     EXPECT_WK_STREQ(@"Value of foo: bar", string4.get());
 
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string5 = (NSString *)[lastScriptMessage body];
+    RetainPtr<NSString> string5 = (NSString *)[getNextMessage() body];
     EXPECT_WK_STREQ(@"Get loops started", string5.get());
 
     // Make a new web view with a new web process to continue the test
@@ -103,17 +102,13 @@
     request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"IndexedDBMultiProcess-3" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView3 loadRequest:request];
 
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string6 = (NSString *)[lastScriptMessage body];
+    RetainPtr<NSString> string6 = (NSString *)[getNextMessage() body];
     EXPECT_WK_STREQ(@"Blocked!", string6.get());
 
     // Kill the blocking web process
     webView2 = nil;
 
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string7 = (NSString *)[lastScriptMessage body];
+    RetainPtr<NSString> string7 = (NSString *)[getNextMessage() body];
     EXPECT_WK_STREQ(@"Deleted!", string7.get());
 }
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebProcessKillIDBCleanup.mm (209250 => 209251)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebProcessKillIDBCleanup.mm	2016-12-02 19:34:31 UTC (rev 209250)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebProcessKillIDBCleanup.mm	2016-12-02 19:55:09 UTC (rev 209251)
@@ -34,12 +34,13 @@
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/_WKProcessPoolConfiguration.h>
 #import <WebKit/_WKUserStyleSheet.h>
+#import <wtf/Deque.h>
 #import <wtf/RetainPtr.h>
 
 #if WK_API_ENABLED
 
 static bool receivedScriptMessage;
-static RetainPtr<WKScriptMessage> lastScriptMessage;
+static Deque<RetainPtr<WKScriptMessage>> scriptMessages;
 
 @interface IndexedDBWebProcessKillMessageHandler : NSObject <WKScriptMessageHandler>
 @end
@@ -49,11 +50,21 @@
 - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
 {
     receivedScriptMessage = true;
-    lastScriptMessage = message;
+    scriptMessages.append(message);
 }
 
 @end
 
+static WKScriptMessage *getNextMessage()
+{
+    if (scriptMessages.isEmpty()) {
+        receivedScriptMessage = false;
+        TestWebKitAPI::Util::run(&receivedScriptMessage);
+    }
+
+    return [[scriptMessages.takeFirst() retain] autorelease];
+}
+
 TEST(IndexedDB, WebProcessKillIDBCleanup)
 {
     RetainPtr<IndexedDBWebProcessKillMessageHandler> handler = adoptNS([[IndexedDBWebProcessKillMessageHandler alloc] init]);
@@ -67,22 +78,11 @@
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"WebProcessKillIDBCleanup-1" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
 
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string1 = (NSString *)[lastScriptMessage body];
+    RetainPtr<NSString> string1 = (NSString *)[getNextMessage() body];
+    RetainPtr<NSString> string2 = (NSString *)[getNextMessage() body];
+    RetainPtr<NSString> string3 = (NSString *)[getNextMessage() body];
+    RetainPtr<NSString> string4 = (NSString *)[getNextMessage() body];
 
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string2 = (NSString *)[lastScriptMessage body];
-
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string3 = (NSString *)[lastScriptMessage body];
-
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string4 = (NSString *)[lastScriptMessage body];
-
     // Kill that web process
     webView = nil;
 
@@ -92,14 +92,9 @@
     request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"WebProcessKillIDBCleanup-2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView2 loadRequest:request];
 
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string5 = (NSString *)[lastScriptMessage body];
+    RetainPtr<NSString> string5 = (NSString *)[getNextMessage() body];
+    RetainPtr<NSString> string6 = (NSString *)[getNextMessage() body];
 
-    TestWebKitAPI::Util::run(&receivedScriptMessage);
-    receivedScriptMessage = false;
-    RetainPtr<NSString> string6 = (NSString *)[lastScriptMessage body];
-
     EXPECT_WK_STREQ(@"UpgradeNeeded", string1.get());
     EXPECT_WK_STREQ(@"Transaction complete", string2.get());
     EXPECT_WK_STREQ(@"Open success", string3.get());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to