Skip to content

Commit

Permalink
User ID auctionDelay timeout bugfix (prebid#4982)
Browse files Browse the repository at this point in the history
* auctiontimeout bugfix

* move clearTimeout outside forEach

* move setTimout above the function call

* increase auctionDelay
  • Loading branch information
Fawke authored and iggyfisk committed Jun 22, 2020
1 parent c4cdc66 commit a8d9038
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ let configRegistry = [];
/** @type {Submodule[]} */
let submoduleRegistry = [];

/** @type {(number|undefined)} */
let timeoutID;

/** @type {(number|undefined)} */
export let syncDelay;

Expand Down Expand Up @@ -256,6 +259,7 @@ function processSubmoduleCallbacks(submodules, cb) {
// clear callback, this prop is used to test if all submodule callbacks are complete below
submodule.callback = undefined;
});
clearTimeout(timeoutID);
}

/**
Expand Down Expand Up @@ -322,9 +326,9 @@ function initializeSubmodulesAndExecuteCallbacks(continueAuction) {
}
}
utils.logInfo(`${MODULE_NAME} - auction delayed by ${auctionDelay} at most to fetch ids`);
processSubmoduleCallbacks(submodulesWithCallbacks, continueCallback);

setTimeout(continueCallback, auctionDelay);
timeoutID = setTimeout(continueCallback, auctionDelay);
processSubmoduleCallbacks(submodulesWithCallbacks, continueCallback);
} else {
// wait for auction complete before processing submodule callbacks
events.on(CONSTANTS.EVENTS.AUCTION_END, function auctionEndHandler() {
Expand Down
6 changes: 3 additions & 3 deletions test/spec/modules/userId_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ describe('User ID', function() {

beforeEach(function() {
sandbox = sinon.createSandbox();
sandbox.stub(global, 'setTimeout');
sandbox.stub(global, 'setTimeout').returns(2);
sandbox.stub(events, 'on');

// remove cookie
Expand Down Expand Up @@ -597,8 +597,8 @@ describe('User ID', function() {
coreStorage.setCookie('MOCKID', JSON.stringify({'MOCKID': '123456778'}), new Date(Date.now() + 5000).toUTCString());

config.setConfig({
userSync: {
auctionDelay: 33,
usersync: {
auctionDelay: 200,
syncDelay: 77,
userIds: [{
name: 'mockId', storage: { name: 'MOCKID', type: 'cookie' }
Expand Down

0 comments on commit a8d9038

Please sign in to comment.