简体   繁体   中英

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.

How 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM