Title: [148846] trunk/LayoutTests
- Revision
- 148846
- Author
- [email protected]
- Date
- 2013-04-21 13:28:04 -0700 (Sun, 21 Apr 2013)
Log Message
Rewrite fast/workers/dedicated-worker-lifecycle.html to verify that
the GC is able to reclaim orphaned Workers on a timely basis.
https://bugs.webkit.org/show_bug.cgi?id=114893.
Reviewed by Geoffrey Garen.
* fast/workers/resources/dedicated-worker-lifecycle.js:
(orphanAllWorkers):
(runTests.worker.onmessage):
(runTests):
(orphanedWorkerExited.worker.onmessage):
(orphanedWorkerExited):
* fast/workers/resources/worker-util.js:
(waitUntilThreadCountMatchesCondition):
(waitUntilThreadCountMatches):
(waitUntilThreadCountDoesNotExceed):
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (148845 => 148846)
--- trunk/LayoutTests/ChangeLog 2013-04-21 19:51:22 UTC (rev 148845)
+++ trunk/LayoutTests/ChangeLog 2013-04-21 20:28:04 UTC (rev 148846)
@@ -1,3 +1,22 @@
+2013-04-20 Mark Lam <[email protected]>
+
+ Rewrite fast/workers/dedicated-worker-lifecycle.html to verify that
+ the GC is able to reclaim orphaned Workers on a timely basis.
+ https://bugs.webkit.org/show_bug.cgi?id=114893.
+
+ Reviewed by Geoffrey Garen.
+
+ * fast/workers/resources/dedicated-worker-lifecycle.js:
+ (orphanAllWorkers):
+ (runTests.worker.onmessage):
+ (runTests):
+ (orphanedWorkerExited.worker.onmessage):
+ (orphanedWorkerExited):
+ * fast/workers/resources/worker-util.js:
+ (waitUntilThreadCountMatchesCondition):
+ (waitUntilThreadCountMatches):
+ (waitUntilThreadCountDoesNotExceed):
+
2013-04-21 Christophe Dumez <[email protected]>
Unreviewed EFL gardening.
Modified: trunk/LayoutTests/fast/workers/resources/dedicated-worker-lifecycle.js (148845 => 148846)
--- trunk/LayoutTests/fast/workers/resources/dedicated-worker-lifecycle.js 2013-04-21 19:51:22 UTC (rev 148845)
+++ trunk/LayoutTests/fast/workers/resources/dedicated-worker-lifecycle.js 2013-04-21 20:28:04 UTC (rev 148846)
@@ -1,5 +1,22 @@
description("This test checks whether orphaned workers exit under various conditions");
+// We create a large number of Workers and expect the GC to keep up and
+// reclaim a reasonable number of them in a timely manner so that the user
+// experience is not impacted.
+//
+// For this test, "a timely manner" means that we have an expectation that
+// before the test times out, we expect that no more than
+// maxRemainingOrphanedWorkers of the numberOfWorkers we created will survive
+// the GC.
+//
+// We use maxRemainingOrphanedWorkers as an approximation of the tolerable
+// amount of garbage in the system that won't impact the user experience.
+
+var numberOfWorkers = 100;
+var maxRemainingOrphanedWorkers = 10;
+var workers = [ ];
+var numberOfCreatedWorkers = 0;
+
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
@@ -9,53 +26,55 @@
runTests();
}
+function orphanAllWorkers(callback)
+{
+ var i;
+ for (i = 0; i < numberOfWorkers; i++) {
+ workers[i]._onmessage_ = 0;
+ workers[i] = 0;
+ }
+ workers = [ ];
+ waitUntilThreadCountDoesNotExceed(callback, maxRemainingOrphanedWorkers);
+}
+
// Contains tests for dedicated-worker-specific lifecycle functionality.
function runTests()
{
- // Start a worker, drop/GC our reference to it, make sure it exits.
- var worker = createWorker();
- worker.postMessage("ping");
- worker._onmessage_ = function(event) {
- if (window.testRunner) {
- if (internals.workerThreadCount == 1)
+ var i;
+ for (i = 0; i < numberOfWorkers; i++) {
+ var worker = createWorker();
+ workers[i] = worker;
+
+ worker.postMessage("ping");
+ worker._onmessage_ = function(event) {
+ if (internals.workerThreadCount == numberOfWorkers) {
testPassed("Orphaned worker thread created.");
- else
- testFailed("After thread creation: internals.workerThreadCount = " + internals.workerThreadCount);
+ orphanAllWorkers(orphanedWorkerExited);
+ }
}
-
- // Orphan our worker (no more references to it) and wait for it to exit.
- worker._onmessage_ = 0;
- worker = 0;
- // Allocating a Date object seems to scramble the stack and force the worker object to get GC'd.
- new Date();
- waitUntilWorkerThreadsExit(orphanedWorkerExited);
}
}
function orphanedWorkerExited()
{
testPassed("Orphaned worker thread exited.");
- // Start a worker, drop/GC our reference to it, make sure it exits.
- var worker = createWorker();
- worker.postMessage("ping");
- worker._onmessage_ = function(event) {
- if (window.testRunner) {
- if (internals.workerThreadCount == 1)
+
+ var i;
+ for (i = 0; i < numberOfWorkers; i++) {
+ var worker = createWorker();
+ workers[i] = worker;
+
+ worker.postMessage("ping");
+ worker._onmessage_ = function(event) {
+ // Send a message that starts up an async operation, to make sure the thread exits when it completes.
+ // FIXME: Disabled for now - re-enable when bug 28702 is fixed.
+ // worker.postMessage("eval setTimeout('', 10)");
+
+ if (internals.workerThreadCount >= numberOfWorkers) {
testPassed("Orphaned timeout worker thread created.");
- else
- testFailed("After thread creation: internals.workerThreadCount = " + internals.workerThreadCount);
+ orphanAllWorkers(orphanedTimeoutWorkerExited);
+ }
}
- // Send a message that starts up an async operation, to make sure the thread exits when it completes.
- // FIXME: Disabled for now - re-enable when bug 28702 is fixed.
- //worker.postMessage("eval setTimeout('', 10)");
-
- // Orphan our worker (no more references to it) and wait for it to exit.
- worker._onmessage_ = 0;
- worker = 0;
- // For some reason, the worker object does not get GC'd unless we allocate a new object here.
- // The conjecture is that there's a value on the stack that appears to point to the worker which this clobbers.
- new Date();
- waitUntilWorkerThreadsExit(orphanedTimeoutWorkerExited);
}
}
Modified: trunk/LayoutTests/fast/workers/resources/worker-util.js (148845 => 148846)
--- trunk/LayoutTests/fast/workers/resources/worker-util.js 2013-04-21 19:51:22 UTC (rev 148845)
+++ trunk/LayoutTests/fast/workers/resources/worker-util.js 2013-04-21 20:28:04 UTC (rev 148846)
@@ -28,7 +28,7 @@
waitUntilThreadCountMatches(callback, 0);
}
-function waitUntilThreadCountMatches(callback, count)
+function waitUntilThreadCountMatchesCondition(callback, condition)
{
// When running in a browser, just wait for one second then call the callback.
if (!window.testRunner) {
@@ -36,17 +36,27 @@
return;
}
- if (internals.workerThreadCount == count) {
+ if (condition()) {
// Worker threads have exited.
callback();
} else {
// Poll until worker threads have been GC'd/exited.
// Force a GC with a bunch of allocations to try to scramble the stack and force worker objects to be collected.
gc(true);
- setTimeout(function() { waitUntilThreadCountMatches(callback, count); }, 10);
+ setTimeout(function() { waitUntilThreadCountMatchesCondition(callback, condition); }, 10);
}
}
+function waitUntilThreadCountMatches(callback, count)
+{
+ waitUntilThreadCountMatchesCondition(callback, function() { return internals.workerThreadCount == count; });
+}
+
+function waitUntilThreadCountDoesNotExceed(callback, count)
+{
+ waitUntilThreadCountMatchesCondition(callback, function() { return internals.workerThreadCount <= count; });
+}
+
function ensureThreadCountMatches(callback, count)
{
// Just wait until the thread count matches, then wait another 100ms to see if it changes, then fire the callback.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes