Testing JavaScript Web Workers

At work, we have an operation that takes about 200 ms in most browsers. We uploaded this operation to our own thread using web workers.

Our QA asked us how they can write a test to make sure that there are actually two threads when this 200 ms operation is disabled in its thread.

How can we do this? What can I do to prove that two threads are running at the same time?

+4
source share
1 answer

Can he write test code that runs setInterval in 10 ms or something else and check the current date while your other code is working. If your code loads the main thread, all interval calls will be queued until this is completed, so you will see a 200 ms window where the interval will not be called, and then 20 calls in fast branch mode after the 200 ms code is completed .

0
source

All Articles