Commit 4fc0c9e9 authored by nhiroki's avatar nhiroki Committed by Commit bot

Worker: Shorten running time of DedicatedWorkerTests

DedicatedWorkerTests are very slow compared to other tests. According to the
report (https://crbug.com/650346), these take 20% of the running time of
webkit_unit_tests. This CL saves the running time by shortening delays for
postDelayedTask(), setInterval() etc used in the tests.

Before this CL (Linux Debug Build):

[1/10] MainThreadHeap/DedicatedWorkerTest.PendingActivity_NoActivity/0 (197 ms)
[2/10] MainThreadHeap/DedicatedWorkerTest.PendingActivity_SetTimeout/0 (194 ms)
[3/10] MainThreadHeap/DedicatedWorkerTest.PendingActivity_SetInterval/0 (195 ms)
[4/10] MainThreadHeap/DedicatedWorkerTest.PendingActivity_SetTimeoutOnMessageEvent/0 (1202 ms)
[5/10] MainThreadHeap/DedicatedWorkerTest.PendingActivity_SetIntervalOnMessageEvent/0 (1409 ms)
[6/10] PerThreadHeap/DedicatedWorkerTest.PendingActivity_NoActivity/0 (155 ms)
[7/10] PerThreadHeap/DedicatedWorkerTest.PendingActivity_SetTimeout/0 (169 ms)
[8/10] PerThreadHeap/DedicatedWorkerTest.PendingActivity_SetInterval/0 (160 ms)
[9/10] PerThreadHeap/DedicatedWorkerTest.PendingActivity_SetTimeoutOnMessageEvent/0 (1187 ms)
[10/10] PerThreadHeap/DedicatedWorkerTest.PendingActivity_SetIntervalOnMessageEvent/0 (1374 ms)

After this CL (Linux Debug Build):

[1/10] MainThreadHeap/DedicatedWorkerTest.PendingActivity_NoActivity/0 (116 ms)
[2/10] MainThreadHeap/DedicatedWorkerTest.PendingActivity_SetTimeout/0 (105 ms)
[3/10] MainThreadHeap/DedicatedWorkerTest.PendingActivity_SetInterval/0 (109 ms)
[4/10] MainThreadHeap/DedicatedWorkerTest.PendingActivity_SetTimeoutOnMessageEvent/0 (120 ms)
[5/10] MainThreadHeap/DedicatedWorkerTest.PendingActivity_SetIntervalOnMessageEvent/0 (139 ms)
[6/10] PerThreadHeap/DedicatedWorkerTest.PendingActivity_NoActivity/0 (68 ms)
[7/10] PerThreadHeap/DedicatedWorkerTest.PendingActivity_SetTimeout/0 (74 ms)
[8/10] PerThreadHeap/DedicatedWorkerTest.PendingActivity_SetInterval/0 (77 ms)
[9/10] PerThreadHeap/DedicatedWorkerTest.PendingActivity_SetTimeoutOnMessageEvent/0 (94 ms)
[10/10] PerThreadHeap/DedicatedWorkerTest.PendingActivity_SetIntervalOnMessageEvent/0 (104 ms)

BUG=650346

Review-Url: https://codereview.chromium.org/2384723002
Cr-Commit-Position: refs/heads/master@{#423789}
parent 56d8f0dc
...@@ -18,6 +18,19 @@ ...@@ -18,6 +18,19 @@
namespace blink { namespace blink {
namespace {
// These are chosen by trial-and-error. Making these intervals smaller causes
// test flakiness. The main thread needs to wait until message confirmation and
// activity report separately. If the intervals are very short, they are
// notified to the main thread almost at the same time and the thread may miss
// the second notification.
const double kDefaultIntervalInSec = 0.01;
const double kNextIntervalInSec = 0.01;
const double kMaxIntervalInSec = 0.02;
} // namespace
class DedicatedWorkerThreadForTest final : public DedicatedWorkerThread { class DedicatedWorkerThreadForTest final : public DedicatedWorkerThread {
public: public:
DedicatedWorkerThreadForTest( DedicatedWorkerThreadForTest(
...@@ -49,8 +62,9 @@ class InProcessWorkerMessagingProxyForTest ...@@ -49,8 +62,9 @@ class InProcessWorkerMessagingProxyForTest
: InProcessWorkerMessagingProxy(executionContext, : InProcessWorkerMessagingProxy(executionContext,
nullptr /* workerObject */, nullptr /* workerObject */,
nullptr /* workerClients */) { nullptr /* workerClients */) {
workerObjectProxy().m_nextIntervalInSec = 0.1; workerObjectProxy().m_defaultIntervalInSec = kDefaultIntervalInSec;
workerObjectProxy().m_maxIntervalInSec = 0.2; workerObjectProxy().m_nextIntervalInSec = kNextIntervalInSec;
workerObjectProxy().m_maxIntervalInSec = kMaxIntervalInSec;
m_mockWorkerLoaderProxyProvider = m_mockWorkerLoaderProxyProvider =
wrapUnique(new MockWorkerLoaderProxyProvider()); wrapUnique(new MockWorkerLoaderProxyProvider());
...@@ -214,7 +228,7 @@ TEST_P(DedicatedWorkerTest, PendingActivity_NoActivity) { ...@@ -214,7 +228,7 @@ TEST_P(DedicatedWorkerTest, PendingActivity_NoActivity) {
TEST_P(DedicatedWorkerTest, PendingActivity_SetTimeout) { TEST_P(DedicatedWorkerTest, PendingActivity_SetTimeout) {
// Start an oneshot timer on initial script evaluation. // Start an oneshot timer on initial script evaluation.
const String sourceCode = "setTimeout(function() {}, 50);"; const String sourceCode = "setTimeout(function() {}, 0);";
startWithSourceCode(sourceCode); startWithSourceCode(sourceCode);
// Worker initialization should be counted as a pending activity. // Worker initialization should be counted as a pending activity.
...@@ -229,7 +243,8 @@ TEST_P(DedicatedWorkerTest, PendingActivity_SetTimeout) { ...@@ -229,7 +243,8 @@ TEST_P(DedicatedWorkerTest, PendingActivity_SetTimeout) {
TEST_P(DedicatedWorkerTest, PendingActivity_SetInterval) { TEST_P(DedicatedWorkerTest, PendingActivity_SetInterval) {
// Start a repeated timer on initial script evaluation, and stop it when a // Start a repeated timer on initial script evaluation, and stop it when a
// message is received. // message is received. The timer needs a non-zero delay or else worker
// activities would not run.
const String sourceCode = const String sourceCode =
"var id = setInterval(function() {}, 50);" "var id = setInterval(function() {}, 50);"
"addEventListener('message', function(event) { clearInterval(id); });"; "addEventListener('message', function(event) { clearInterval(id); });";
...@@ -259,7 +274,7 @@ TEST_P(DedicatedWorkerTest, PendingActivity_SetTimeoutOnMessageEvent) { ...@@ -259,7 +274,7 @@ TEST_P(DedicatedWorkerTest, PendingActivity_SetTimeoutOnMessageEvent) {
// Start an oneshot timer on a message event. // Start an oneshot timer on a message event.
const String sourceCode = const String sourceCode =
"addEventListener('message', function(event) {" "addEventListener('message', function(event) {"
" setTimeout(function() {}, 50);" " setTimeout(function() {}, 0);"
"});"; "});";
startWithSourceCode(sourceCode); startWithSourceCode(sourceCode);
...@@ -289,7 +304,8 @@ TEST_P(DedicatedWorkerTest, PendingActivity_SetTimeoutOnMessageEvent) { ...@@ -289,7 +304,8 @@ TEST_P(DedicatedWorkerTest, PendingActivity_SetTimeoutOnMessageEvent) {
TEST_P(DedicatedWorkerTest, PendingActivity_SetIntervalOnMessageEvent) { TEST_P(DedicatedWorkerTest, PendingActivity_SetIntervalOnMessageEvent) {
// Start a repeated timer on a message event, and stop it when another // Start a repeated timer on a message event, and stop it when another
// message is received. // message is received. The timer needs a non-zero delay or else worker
// activities would not run.
const String sourceCode = const String sourceCode =
"var count = 0;" "var count = 0;"
"var id;" "var id;"
...@@ -321,8 +337,11 @@ TEST_P(DedicatedWorkerTest, PendingActivity_SetIntervalOnMessageEvent) { ...@@ -321,8 +337,11 @@ TEST_P(DedicatedWorkerTest, PendingActivity_SetIntervalOnMessageEvent) {
workerMessagingProxy()->workerGlobalScopeMayHavePendingActivity()); workerMessagingProxy()->workerGlobalScopeMayHavePendingActivity());
// Run the message loop for a while to make sure the timer is counted as a // Run the message loop for a while to make sure the timer is counted as a
// pending activity until it's stopped. // pending activity until it's stopped. The delay is equal to the max
testing::runDelayedTasks(1000); // interval so that the pending activity timer may be able to have a chance
// to run before the next expectation check.
const double kDelayInMs = kMaxIntervalInSec * 1000;
testing::runDelayedTasks(kDelayInMs);
EXPECT_TRUE( EXPECT_TRUE(
workerMessagingProxy()->workerGlobalScopeMayHavePendingActivity()); workerMessagingProxy()->workerGlobalScopeMayHavePendingActivity());
......
...@@ -181,6 +181,7 @@ void InProcessWorkerObjectProxy::didTerminateWorkerThread() { ...@@ -181,6 +181,7 @@ void InProcessWorkerObjectProxy::didTerminateWorkerThread() {
InProcessWorkerObjectProxy::InProcessWorkerObjectProxy( InProcessWorkerObjectProxy::InProcessWorkerObjectProxy(
InProcessWorkerMessagingProxy* messagingProxy) InProcessWorkerMessagingProxy* messagingProxy)
: m_messagingProxy(messagingProxy), : m_messagingProxy(messagingProxy),
m_defaultIntervalInSec(kDefaultIntervalInSec),
m_nextIntervalInSec(kDefaultIntervalInSec), m_nextIntervalInSec(kDefaultIntervalInSec),
m_maxIntervalInSec(kMaxIntervalInSec) {} m_maxIntervalInSec(kMaxIntervalInSec) {}
...@@ -209,7 +210,7 @@ void InProcessWorkerObjectProxy::checkPendingActivity(TimerBase*) { ...@@ -209,7 +210,7 @@ void InProcessWorkerObjectProxy::checkPendingActivity(TimerBase*) {
// Don't schedule a timer. It will be started again when a message event // Don't schedule a timer. It will be started again when a message event
// is dispatched. // is dispatched.
m_nextIntervalInSec = kDefaultIntervalInSec; m_nextIntervalInSec = m_defaultIntervalInSec;
return; return;
} }
......
...@@ -107,8 +107,12 @@ class CORE_EXPORT InProcessWorkerObjectProxy : public WorkerReportingProxy { ...@@ -107,8 +107,12 @@ class CORE_EXPORT InProcessWorkerObjectProxy : public WorkerReportingProxy {
// cancelled when the worker global scope is destroyed. // cancelled when the worker global scope is destroyed.
std::unique_ptr<Timer<InProcessWorkerObjectProxy>> m_timer; std::unique_ptr<Timer<InProcessWorkerObjectProxy>> m_timer;
// The default interval duration of the timer. This is usually
// kDefaultIntervalInSec but made as a member variable for testing.
double m_defaultIntervalInSec;
// The next interval duration of the timer. This is initially set to // The next interval duration of the timer. This is initially set to
// kDefaultIntervalInSec and exponentially increased up to // |m_defaultIntervalInSec| and exponentially increased up to
// |m_maxIntervalInSec|. // |m_maxIntervalInSec|.
double m_nextIntervalInSec; double m_nextIntervalInSec;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment