Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: Source/core/workers/WorkerThreadTest.cpp

Issue 1184833002: Fix a race condition during worker thread initialization (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: AnyNumber => AtMost Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/workers/WorkerThread.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/workers/WorkerThreadTest.cpp
diff --git a/Source/core/workers/WorkerThreadTest.cpp b/Source/core/workers/WorkerThreadTest.cpp
index e59b73d032e940f98f166b6adac665a05aa08a3f..9f92c4c565e775680737d8b60d08a2541f5a9a4a 100644
--- a/Source/core/workers/WorkerThreadTest.cpp
+++ b/Source/core/workers/WorkerThreadTest.cpp
@@ -15,6 +15,7 @@
#include <gtest/gtest.h>
using testing::_;
+using testing::AtMost;
using testing::Invoke;
using testing::Return;
using testing::Mock;
@@ -159,7 +160,6 @@ public:
m_workerThread = adoptRef(new WorkerThreadForTest(
m_mockWorkerLoaderProxyProvider.get(),
*m_mockWorkerReportingProxy));
- ExpectWorkerLifetimeReportingCalls();
}
void TearDown() override
@@ -167,10 +167,8 @@ public:
m_workerThread->workerLoaderProxy()->detachProvider(m_mockWorkerLoaderProxyProvider.get());
}
- void startAndWaitForInit()
+ void start()
{
- OwnPtr<WebWaitableEvent> completionEvent = adoptPtr(Platform::current()->createWaitableEvent());
-
OwnPtr<Vector<CSPHeaderAndType>> headers = adoptPtr(new Vector<CSPHeaderAndType>());
CSPHeaderAndType headerAndType("contentSecurityPolicy", ContentSecurityPolicyHeaderTypeReport);
headers->append(headerAndType);
@@ -187,6 +185,11 @@ public:
m_securityOrigin.get(),
clients.release(),
V8CacheOptionsDefault));
+ }
+
+ void waitForInit()
+ {
+ OwnPtr<WebWaitableEvent> completionEvent = adoptPtr(Platform::current()->createWaitableEvent());
m_workerThread->backingThread().postTask(FROM_HERE, new SignalTask(completionEvent.get()));
completionEvent->wait();
}
@@ -203,7 +206,7 @@ public:
}
protected:
- void ExpectWorkerLifetimeReportingCalls()
+ void expectWorkerLifetimeReportingCalls()
{
EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Times(1);
EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(true)).Times(1);
@@ -219,7 +222,19 @@ protected:
TEST_F(WorkerThreadTest, StartAndStop)
{
- startAndWaitForInit();
+ expectWorkerLifetimeReportingCalls();
+ start();
+ waitForInit();
+ m_workerThread->terminateAndWait();
+}
+
+TEST_F(WorkerThreadTest, StartAndStopImmediately)
+{
+ EXPECT_CALL(*m_mockWorkerReportingProxy, workerGlobalScopeStarted(_)).Times(AtMost(1));
+ EXPECT_CALL(*m_mockWorkerReportingProxy, didEvaluateWorkerScript(true)).Times(AtMost(1));
+ EXPECT_CALL(*m_mockWorkerReportingProxy, workerThreadTerminated()).Times(AtMost(1));
+ EXPECT_CALL(*m_mockWorkerReportingProxy, willDestroyWorkerGlobalScope()).Times(AtMost(1));
+ start();
m_workerThread->terminateAndWait();
}
@@ -236,7 +251,9 @@ TEST_F(WorkerThreadTest, GcOccursWhileIdle)
EXPECT_CALL(*m_workerThread, doIdleGc(_)).Times(testing::AtLeast(1));
- startAndWaitForInit();
+ expectWorkerLifetimeReportingCalls();
+ start();
+ waitForInit();
postWakeUpTask(500ul);
gcDone->wait();
@@ -280,7 +297,9 @@ TEST_F(WorkerThreadTest, GcDoesNotOccurWhenNotIdle)
EXPECT_CALL(*m_workerThread, doIdleGc(_)).Times(0);
- startAndWaitForInit();
+ expectWorkerLifetimeReportingCalls();
+ start();
+ waitForInit();
WebScheduler* scheduler = m_workerThread->backingThread().platformThread().scheduler();
« no previous file with comments | « Source/core/workers/WorkerThread.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698