Skip to content

Commit 48e77b2

Browse files
committed
tests(ios): Fix sporadic 100% CPU spike after workers tests
1 parent 9f94fbd commit 48e77b2

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

Workers/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,15 @@ describe("TNS Workers", () => {
486486
const numWorkers = (interop.sizeof(interop.types.id) == 4) ? 4 : 10;
487487
const timeout = DEFAULT_TIMEOUT_BEFORE_ASSERT*3.5;
488488

489-
let messageProducerTimeout = null;
489+
let messageProducerTimeout = true;
490490
let iteration = 0;
491491
const produceMessageInLoop = () => {
492492
NSNotificationCenter.defaultCenter.postNotificationNameObjectUserInfo('send-to-worker', { iteration }, null);
493493
iteration++;
494-
messageProducerTimeout = setTimeout(produceMessageInLoop, 1);
494+
// Prevent against rescheduling after we've been stopped
495+
if (messageProducerTimeout) {
496+
messageProducerTimeout = setTimeout(produceMessageInLoop, 1);
497+
}
495498
};
496499
produceMessageInLoop();
497500

@@ -512,6 +515,8 @@ describe("TNS Workers", () => {
512515

513516
setTimeout(() => {
514517
clearTimeout(messageProducerTimeout);
518+
// Signal we've stopped to prevent against rescheduling by an already queued timer tick
519+
messageProducerTimeout = null;
515520

516521
expect(onStartEvents).toBeGreaterThan(0, `At least 1 worker should have started in ${timeout} ms`);
517522
expect(onCloseEvents).toBeGreaterThan(0, `At least 1 worker should have finished in ${timeout} ms`);

0 commit comments

Comments
 (0)