JavaScript testing Web Workers
At work, we've got an operation that takes up about 200 ms on most browsers. We've offloaded this operation to its own thread using Web Workers.
Our QA has asked us how they can write a test to verify that there are actually two threads running when this 200 ms operation is fired off in its own thread.
Ho开发者_如何学Pythonw can we do this? What can I do to prove that two threads are executing concurrently?
Could write test code that does a setInterval of 10ms or something and checks the current date while your other code is running. If your code is hogging the main thread, all the interval calls will queue up until it's done, so you'll see a 200ms window where the interval doesn't get called, then 20 calls in rapid secession after the 200ms code is completed.
精彩评论