Make sure service workers get terminated between tests
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Nov 2017 02:32:12 +0000 (02:32 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 17 Nov 2017 02:32:12 +0000 (02:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=179774

Reviewed by Alex Christensen.

Make sure service workers get terminated between tests. Previously, we
would merely clear all registrations and job queues but it would not
cause the registrations' service workers to get terminated.

* workers/service/context/ServiceWorkerThread.cpp:
(WebCore::ServiceWorkerThread::updateExtendedEventsSet):
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::clearAll):
* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::scriptFetchFinished):
(WebCore::SWServerJobQueue::scriptContextFailedToStart):
(WebCore::SWServerJobQueue::didFinishInstall):
(WebCore::SWServerJobQueue::tryClearRegistration):
(WebCore::SWServerJobQueue::clearRegistration):
* workers/service/server/SWServerJobQueue.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224955 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/workers/service/context/ServiceWorkerThread.cpp
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebCore/workers/service/server/SWServerJobQueue.cpp
Source/WebCore/workers/service/server/SWServerJobQueue.h

index dad75df..776132c 100644 (file)
@@ -1,3 +1,26 @@
+2017-11-16  Chris Dumez  <cdumez@apple.com>
+
+        Make sure service workers get terminated between tests
+        https://bugs.webkit.org/show_bug.cgi?id=179774
+
+        Reviewed by Alex Christensen.
+
+        Make sure service workers get terminated between tests. Previously, we
+        would merely clear all registrations and job queues but it would not
+        cause the registrations' service workers to get terminated.
+
+        * workers/service/context/ServiceWorkerThread.cpp:
+        (WebCore::ServiceWorkerThread::updateExtendedEventsSet):
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::clearAll):
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::scriptFetchFinished):
+        (WebCore::SWServerJobQueue::scriptContextFailedToStart):
+        (WebCore::SWServerJobQueue::didFinishInstall):
+        (WebCore::SWServerJobQueue::tryClearRegistration):
+        (WebCore::SWServerJobQueue::clearRegistration):
+        * workers/service/server/SWServerJobQueue.h:
+
 2017-11-16  Youenn Fablet  <youenn@apple.com>
 
         FetchLoader should unregister its blob URL
index 1beae9f..8aaff31 100644 (file)
@@ -175,6 +175,9 @@ void ServiceWorkerThread::updateExtendedEventsSet(ExtendableEvent* newEvent)
         newEvent->whenAllExtendLifetimePromisesAreSettled([this](auto&&) {
             updateExtendedEventsSet();
         });
+        // Clear out the event's target as it is the WorkerGlobalScope and we do not want to keep it
+        // alive unnecessarily.
+        newEvent->setTarget(nullptr);
     }
 
     bool hasPendingEvents = this->hasPendingEvents();
index 8f005ad..a1c58fc 100644 (file)
@@ -130,9 +130,9 @@ Vector<ServiceWorkerRegistrationData> SWServer::getRegistrations(const SecurityO
 void SWServer::clearAll()
 {
     m_jobQueues.clear();
-    m_registrations.clear();
+    while (!m_registrations.isEmpty())
+        SWServerJobQueue::clearRegistration(*this, *m_registrations.begin()->value);
     m_originStore->clearAll();
-    // FIXME: We should probably ask service workers to terminate.
 }
 
 void SWServer::clear(const SecurityOrigin& origin)
index 16aa9f3..0267e43 100644 (file)
@@ -73,7 +73,7 @@ void SWServerJobQueue::scriptFetchFinished(SWServer::Connection& connection, con
 
         // If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
         if (!newestWorker)
-            clearRegistration(*registration);
+            clearRegistration(m_server, *registration);
 
         // Invoke Finish Job with job and abort these steps.
         finishCurrentJob();
@@ -102,7 +102,7 @@ void SWServerJobQueue::scriptContextFailedToStart(ServiceWorkerIdentifier, const
 
     // If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
     if (!registration->getNewestWorker())
-        clearRegistration(*registration);
+        clearRegistration(m_server, *registration);
 
     // Invoke Finish Job with job and abort these steps.
     finishCurrentJob();
@@ -166,7 +166,7 @@ void SWServerJobQueue::didFinishInstall(ServiceWorkerIdentifier identifier, bool
 
         // If newestWorker is null, invoke Clear Registration algorithm passing registration as its argument.
         if (!registration->getNewestWorker())
-            clearRegistration(*registration);
+            clearRegistration(m_server, *registration);
         // Invoke Finish Job with job and abort these steps.
         finishCurrentJob();
         return;
@@ -349,7 +349,7 @@ void SWServerJobQueue::tryClearRegistration(SWServerRegistration& registration)
     if (registration.activeWorker() && registration.activeWorker()->hasPendingEvents())
         return;
 
-    clearRegistration(registration);
+    clearRegistration(m_server, registration);
 }
 
 // https://w3c.github.io/ServiceWorker/#clear-registration
@@ -364,14 +364,14 @@ static void clearRegistrationWorker(SWServerRegistration& registration, SWServer
 }
 
 // https://w3c.github.io/ServiceWorker/#clear-registration
-void SWServerJobQueue::clearRegistration(SWServerRegistration& registration)
+void SWServerJobQueue::clearRegistration(SWServer& server, SWServerRegistration& registration)
 {
     clearRegistrationWorker(registration, registration.installingWorker(), ServiceWorkerRegistrationState::Installing);
     clearRegistrationWorker(registration, registration.waitingWorker(), ServiceWorkerRegistrationState::Waiting);
     clearRegistrationWorker(registration, registration.activeWorker(), ServiceWorkerRegistrationState::Active);
 
     // Remove scope to registration map[scopeString].
-    m_server.removeRegistration(registration.key());
+    server.removeRegistration(registration.key());
 }
 
 // https://w3c.github.io/ServiceWorker/#update-algorithm
index d6628b6..800d7c8 100644 (file)
@@ -54,6 +54,8 @@ public:
     static void didFinishActivation(SWServerRegistration&, ServiceWorkerIdentifier);
     void didResolveRegistrationPromise();
 
+    static void clearRegistration(SWServer&, SWServerRegistration&);
+
 private:
     void jobTimerFired();
     void runNextJobSynchronously();
@@ -65,7 +67,6 @@ private:
     void runUpdateJob(const ServiceWorkerJobData&);
 
     void tryClearRegistration(SWServerRegistration&);
-    void clearRegistration(SWServerRegistration&);
     void install(SWServerRegistration&, ServiceWorkerIdentifier);
     static void tryActivate(SWServer&, SWServerRegistration&);
     static void activate(SWServer&, SWServerRegistration&);