Modified: trunk/Tools/ChangeLog (277459 => 277460)
--- trunk/Tools/ChangeLog 2021-05-13 23:11:06 UTC (rev 277459)
+++ trunk/Tools/ChangeLog 2021-05-13 23:16:00 UTC (rev 277460)
@@ -1,3 +1,15 @@
+2021-05-13 Chris Dumez <cdu...@apple.com>
+
+ Tweak ServiceWorkers.SuspendServiceWorkerProcessBasedOnClientProcesses to find out source of timeout
+ https://bugs.webkit.org/show_bug.cgi?id=225770
+
+ Reviewed by Alexey Proskuryakov.
+
+ Wait for conditions with our own timeout so that the test fails with useful errors instead
+ of just a generic timeout. This just help us find out where in the test things go wrong.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
+
2021-05-13 Alex Christensen <achristen...@webkit.org>
Add unit test using WKHTTPCookieStoreObserver and cookies received from HTTP
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm (277459 => 277460)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm 2021-05-13 23:11:06 UTC (rev 277459)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm 2021-05-13 23:16:00 UTC (rev 277460)
@@ -1441,13 +1441,15 @@
done = false;
}
-void waitUntilServiceWorkerProcessCount(WKProcessPool *processPool, unsigned processCount)
+static bool waitUntilEvaluatesToTrue(const Function<bool()>& f)
{
+ unsigned timeout = 0;
do {
- if (processPool._serviceWorkerProcessCount == processCount)
- return;
- TestWebKitAPI::Util::spinRunLoop(1);
- } while (true);
+ if (f())
+ return true;
+ TestWebKitAPI::Util::sleep(0.1);
+ } while (++timeout < 100);
+ return false;
}
TEST(ServiceWorkers, ProcessPerSite)
@@ -1523,7 +1525,7 @@
NSURLRequest *aboutBlankRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]];
[webView4 loadRequest:aboutBlankRequest];
- waitUntilServiceWorkerProcessCount(processPool, 1);
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] { return [processPool _serviceWorkerProcessCount] == 1; }));
EXPECT_EQ(1U, processPool._serviceWorkerProcessCount);
[webView2 loadRequest:aboutBlankRequest];
@@ -1532,7 +1534,7 @@
[webView1 loadRequest:aboutBlankRequest];
[webView3 loadRequest:aboutBlankRequest];
- waitUntilServiceWorkerProcessCount(processPool, 0);
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] { return ![processPool _serviceWorkerProcessCount]; }));
EXPECT_EQ(0U, processPool._serviceWorkerProcessCount);
}
@@ -1570,7 +1572,7 @@
[webView1 loadRequest:server1.request()];
[webView2 loadRequest:server2.requestWithLocalhost()];
- waitUntilServiceWorkerProcessCount(processPool, 2);
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] { return [processPool _serviceWorkerProcessCount] == 2; }));
}
static size_t launchServiceWorkerProcess(bool useSeparateServiceWorkerProcess, bool loadAboutBlankBeforePage)
@@ -1613,7 +1615,7 @@
[webView loadRequest:server.request()];
- waitUntilServiceWorkerProcessCount(processPool, 1);
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] { return [processPool _serviceWorkerProcessCount] == 1; }));
return webView.get().configuration.processPool._webProcessCountIgnoringPrewarmed;
}
@@ -1649,24 +1651,6 @@
EXPECT_EQ(2u, launchServiceWorkerProcess(useSeparateServiceWorkerProcess, firstLoadAboutBlank));
}
-void waitUntilServiceWorkerProcessForegroundActivityState(WKWebView *page, bool shouldHaveActivity)
-{
- do {
- if (page._hasServiceWorkerForegroundActivityForTesting == shouldHaveActivity)
- return;
- TestWebKitAPI::Util::spinRunLoop(1);
- } while (true);
-}
-
-void waitUntilServiceWorkerProcessBackgroundActivityState(WKWebView *page, bool shouldHaveActivity)
-{
- do {
- if (page._hasServiceWorkerBackgroundActivityForTesting == shouldHaveActivity)
- return;
- TestWebKitAPI::Util::spinRunLoop(1);
- } while (true);
-}
-
enum class UseSeparateServiceWorkerProcess : bool { No, Yes };
void testSuspendServiceWorkerProcessBasedOnClientProcesses(UseSeparateServiceWorkerProcess useSeparateServiceWorkerProcess)
{
@@ -1696,7 +1680,7 @@
[webView loadRequest:server.request()];
- waitUntilServiceWorkerProcessCount(processPool, 1);
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] { return [processPool _serviceWorkerProcessCount] == 1; }));
auto webView2 = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
[webView2 loadRequest:server.request()];
@@ -1703,16 +1687,16 @@
auto webViewToUpdate = useSeparateServiceWorkerProcess == UseSeparateServiceWorkerProcess::Yes ? webView : webView2;
[webViewToUpdate _setAssertionTypeForTesting: 1];
- waitUntilServiceWorkerProcessForegroundActivityState(webViewToUpdate.get(), false);
- waitUntilServiceWorkerProcessBackgroundActivityState(webViewToUpdate.get(), true);
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] { return ![webViewToUpdate _hasServiceWorkerForegroundActivityForTesting]; }));
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] { return [webViewToUpdate _hasServiceWorkerBackgroundActivityForTesting]; }));
[webViewToUpdate _setAssertionTypeForTesting: 3];
- waitUntilServiceWorkerProcessForegroundActivityState(webViewToUpdate.get(), true);
- waitUntilServiceWorkerProcessBackgroundActivityState(webViewToUpdate.get(), false);
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] { return [webViewToUpdate _hasServiceWorkerForegroundActivityForTesting]; }));
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] { return ![webViewToUpdate _hasServiceWorkerBackgroundActivityForTesting]; }));
[webViewToUpdate _setAssertionTypeForTesting: 0];
- waitUntilServiceWorkerProcessBackgroundActivityState(webViewToUpdate.get(), false);
- waitUntilServiceWorkerProcessForegroundActivityState(webViewToUpdate.get(), false);
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] { return ![webViewToUpdate _hasServiceWorkerForegroundActivityForTesting]; }));
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] { return ![webViewToUpdate _hasServiceWorkerBackgroundActivityForTesting]; }));
[webView _close];
webView = nullptr;
@@ -1719,20 +1703,20 @@
// The service worker process should take activity based on webView2 process.
[webView2 _setAssertionTypeForTesting: 1];
- while (webView2.get()._hasServiceWorkerForegroundActivityForTesting || !webView2.get()._hasServiceWorkerBackgroundActivityForTesting) {
- [webView2 _setAssertionTypeForTesting: 1];
- TestWebKitAPI::Util::spinRunLoop(1);
- }
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] {
+ [webView2 _setAssertionTypeForTesting:1];
+ return ![webView2 _hasServiceWorkerForegroundActivityForTesting] && [webView2 _hasServiceWorkerBackgroundActivityForTesting];
+ }));
- while (!webView2.get()._hasServiceWorkerForegroundActivityForTesting || webView2.get()._hasServiceWorkerBackgroundActivityForTesting) {
- [webView2 _setAssertionTypeForTesting: 3];
- TestWebKitAPI::Util::spinRunLoop(1);
- }
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] {
+ [webView2 _setAssertionTypeForTesting:3];
+ return [webView2 _hasServiceWorkerForegroundActivityForTesting] && ![webView2 _hasServiceWorkerBackgroundActivityForTesting];
+ }));
- while (webView2.get()._hasServiceWorkerForegroundActivityForTesting || webView2.get()._hasServiceWorkerBackgroundActivityForTesting) {
- [webView2 _setAssertionTypeForTesting: 0];
- TestWebKitAPI::Util::spinRunLoop(1);
- }
+ EXPECT_TRUE(waitUntilEvaluatesToTrue([&] {
+ [webView2 _setAssertionTypeForTesting:0];
+ return ![webView2 _hasServiceWorkerForegroundActivityForTesting] && ![webView2 _hasServiceWorkerBackgroundActivityForTesting];
+ }));
}
TEST(ServiceWorkers, SuspendServiceWorkerProcessBasedOnClientProcessesWithSeparateServiceWorkerProcess)