| OLD | NEW |
| 1 <html> | |
| 2 <head> | |
| 3 <script src='resources/worker-util.js'></script> | |
| 4 <script> | |
| 5 var workersStarted; | 1 var workersStarted; |
| 6 var workersClosed; | 2 var workersClosed; |
| 7 | |
| 8 var testNumber = -1; | |
| 9 var syncOperationTests = new Array('openDatabaseSync', 'requestFileSystemSync',
'fileSyncOperations'); | |
| 10 | |
| 11 // 30 workers seemed to cause the crash to happen frequently. | 3 // 30 workers seemed to cause the crash to happen frequently. |
| 12 var workers = new Array(30); | 4 var workers = new Array(30); |
| 13 | 5 |
| 14 function startNextTest() | 6 function startWorkers(operationName) |
| 15 { | 7 { |
| 16 testNumber++; | 8 log('Testing interrupting: ' + operationName); |
| 17 log('Waiting for all workers to exit.'); | |
| 18 if (testNumber >= syncOperationTests.length) { | |
| 19 waitUntilWorkerThreadsExit(done) | |
| 20 return; | |
| 21 } | |
| 22 waitUntilWorkerThreadsExit(startWorkers) | |
| 23 } | |
| 24 | |
| 25 function startWorkers() | |
| 26 { | |
| 27 log('Testing interrupting: ' + syncOperationTests[testNumber]); | |
| 28 log('Starting workers.'); | 9 log('Starting workers.'); |
| 29 workersStarted = 0; | 10 workersStarted = 0; |
| 30 workersClosed = 0; | 11 workersClosed = 0; |
| 31 for (var i = 0; i < workers.length; ++i) { | 12 for (var i = 0; i < workers.length; ++i) { |
| 32 workers[i] = new Worker('resources/sync-operations.js?arg=' + i) | 13 workers[i] = new Worker('resources/sync-operations.js?arg=' + i) |
| 33 workers[i].onmessage = onWorkerStarted; | 14 workers[i].onmessage = onWorkerStarted.bind(null, operationName); |
| 34 } | 15 } |
| 35 } | 16 } |
| 36 | 17 |
| 37 // Do our best to try to interrupt the database open | 18 // Do our best to try to interrupt the database open |
| 38 // call by waiting for the worker to start and then | 19 // call by waiting for the worker to start and then |
| 39 // telling it to do the open database call (and | 20 // telling it to do the open database call (and |
| 40 // then terminate the worker). | 21 // then terminate the worker). |
| 41 function onWorkerStarted() | 22 function onWorkerStarted(operationName) |
| 42 { | 23 { |
| 43 workersStarted++; | 24 workersStarted++; |
| 44 log('Started worker count: ' + workersStarted); | 25 log('Started worker count: ' + workersStarted); |
| 45 if (workersStarted < workers.length) | 26 if (workersStarted < workers.length) |
| 46 return; | 27 return; |
| 47 | 28 |
| 48 log('Running operation.'); | 29 log('Running operation.'); |
| 49 for (var i = 0; i < workers.length; ++i) | 30 for (var i = 0; i < workers.length; ++i) |
| 50 workers[i].postMessage(syncOperationTests[testNumber]); | 31 workers[i].postMessage(operationName); |
| 51 | 32 |
| 52 setTimeout('closeWorker()', 0); | 33 setTimeout('closeWorker()', 0); |
| 53 } | 34 } |
| 54 | 35 |
| 55 function closeWorker() | 36 function closeWorker() |
| 56 { | 37 { |
| 57 workers[workersClosed].terminate(); | 38 workers[workersClosed].terminate(); |
| 58 workersClosed++; | 39 workersClosed++; |
| 59 log('Closed worker count: ' + workersClosed); | 40 log('Closed worker count: ' + workersClosed); |
| 60 if (workersClosed < workers.length) | 41 if (workersClosed < workers.length) |
| 61 setTimeout('closeWorker()', 3); | 42 setTimeout('closeWorker()', 3); |
| 62 else | 43 else |
| 63 startNextTest(); | 44 waitUntilWorkerThreadsExit(done) |
| 64 } | 45 } |
| 65 | 46 |
| 66 function runTest() | 47 function runTest(operationName) |
| 67 { | 48 { |
| 68 log('Starting test run.'); | 49 log('Starting test run.'); |
| 69 if (window.testRunner) { | 50 if (window.testRunner) { |
| 70 testRunner.dumpAsText(); | 51 testRunner.dumpAsText(); |
| 71 testRunner.waitUntilDone(); | 52 testRunner.waitUntilDone(); |
| 72 } | 53 } |
| 73 startNextTest(); | 54 startWorkers(operationName); |
| 74 } | 55 } |
| 75 </script> | |
| 76 </head> | |
| 77 <body onload='runTest()'> | |
| 78 <p>Test that terminating the worker while it is performing synchronous file or d
atabase operations will not cause any crashes, asserts, etc.</p> | |
| 79 <div id='result'> | |
| 80 </div> | |
| 81 </body> | |
| 82 </html> | |
| OLD | NEW |