From 4708487f73e73e9b8634f7d0b1e3e03f4702a17b Mon Sep 17 00:00:00 2001 From: Filip Stamenkovic Date: Fri, 23 Oct 2020 12:21:20 +0200 Subject: [PATCH 1/2] clearTimeout only after all submodules are done --- modules/userId/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/userId/index.js b/modules/userId/index.js index a5e5fd4eff1..9ef4da0f96f 100644 --- a/modules/userId/index.js +++ b/modules/userId/index.js @@ -319,7 +319,13 @@ function hasGDPRConsent(consentData) { * @param {function} cb - callback for after processing is done. */ function processSubmoduleCallbacks(submodules, cb) { - const done = cb ? utils.delayExecution(cb, submodules.length) : function () { }; + let done = () => {}; + if (cb) { + done = utils.delayExecution(() => { + clearTimeout(timeoutID); + cb(); + }, submodules.length); + } submodules.forEach(function (submodule) { submodule.callback(function callbackCompleted(idObj) { // if valid, id data should be saved to cookie/html storage @@ -338,7 +344,6 @@ function processSubmoduleCallbacks(submodules, cb) { // clear callback, this prop is used to test if all submodule callbacks are complete below submodule.callback = undefined; }); - clearTimeout(timeoutID); } /** From 9dfdb63a0449af054067450ccdce8b20c4207d13 Mon Sep 17 00:00:00 2001 From: Filip Stamenkovic Date: Mon, 2 Nov 2020 14:08:09 +0100 Subject: [PATCH 2/2] check that setTimeout function was not cleared --- test/spec/modules/userId_spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/spec/modules/userId_spec.js b/test/spec/modules/userId_spec.js index c5ab2e249fc..d5ed96a5bc1 100644 --- a/test/spec/modules/userId_spec.js +++ b/test/spec/modules/userId_spec.js @@ -611,6 +611,7 @@ describe('User ID', function () { beforeEach(function () { sandbox = sinon.createSandbox(); sandbox.stub(global, 'setTimeout').returns(2); + sandbox.stub(global, 'clearTimeout'); sandbox.stub(events, 'on'); sandbox.stub(coreStorage, 'getCookie'); @@ -662,6 +663,7 @@ describe('User ID', function () { requestBidsHook(auctionSpy, {adUnits}); // check auction was delayed + global.clearTimeout.calledOnce.should.equal(false); global.setTimeout.calledOnce.should.equal(true); global.setTimeout.calledWith(sinon.match.func, 33); auctionSpy.calledOnce.should.equal(false); @@ -696,6 +698,7 @@ describe('User ID', function () { // check auction was delayed // global.setTimeout.calledOnce.should.equal(true); + global.clearTimeout.calledOnce.should.equal(false); global.setTimeout.calledWith(sinon.match.func, 33); auctionSpy.calledOnce.should.equal(false);