Skip to content

Commit

Permalink
Delaying removal of floor data for 3 seconds (#5360)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrmartinez authored Jun 12, 2020
1 parent 18fc232 commit e7a34e9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
6 changes: 4 additions & 2 deletions modules/priceFloors.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,10 @@ export function handleSetFloorsConfig(config) {

if (!addedFloorsHook) {
// register hooks / listening events
// when auction finishes remove it's associated floor data
events.on(CONSTANTS.EVENTS.AUCTION_END, (args) => delete _floorDataForAuction[args.auctionId]);
// when auction finishes remove it's associated floor data after 3 seconds so we stil have it for latent responses
events.on(CONSTANTS.EVENTS.AUCTION_END, (args) => {
setTimeout(() => delete _floorDataForAuction[args.auctionId], 3000);
});

// we want our hooks to run after the currency hooks
getGlobal().requestBids.before(requestBidsHook, 50);
Expand Down
31 changes: 24 additions & 7 deletions test/spec/modules/priceFloors_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import {
fieldMatchingFunctions,
allowedFields
} from 'modules/priceFloors.js';
import events from 'src/events.js';

describe('the price floors module', function () {
let logErrorSpy;
let logWarnSpy;
let sandbox;
let clock;
const basicFloorData = {
modelVersion: 'basic model',
currency: 'USD',
Expand Down Expand Up @@ -58,12 +60,14 @@ describe('the price floors module', function () {
};
}
beforeEach(function() {
clock = sinon.useFakeTimers();
sandbox = sinon.sandbox.create();
logErrorSpy = sinon.spy(utils, 'logError');
logWarnSpy = sinon.spy(utils, 'logWarn');
});

afterEach(function() {
clock.restore();
handleSetFloorsConfig({enabled: false});
sandbox.restore();
utils.logError.restore();
Expand Down Expand Up @@ -288,17 +292,10 @@ describe('the price floors module', function () {
});
};
let fakeFloorProvider;
let clock;
let actualAllowedFields = allowedFields;
let actualFieldMatchingFunctions = fieldMatchingFunctions;
const defaultAllowedFields = [...allowedFields];
const defaultMatchingFunctions = {...fieldMatchingFunctions};
before(function () {
clock = sinon.useFakeTimers();
});
after(function () {
clock.restore();
});
beforeEach(function() {
fakeFloorProvider = sinon.fakeServer.create();
});
Expand Down Expand Up @@ -1056,4 +1053,24 @@ describe('the price floors module', function () {
expect(returnedBidResponse.cpm).to.equal(7.5);
});
});

describe('Post Auction Tests', function () {
let AUCTION_END_EVENT;
beforeEach(function () {
AUCTION_END_EVENT = {
auctionId: '123-45-6789'
};
});
it('should wait 3 seconds before deleting auction floor data', function () {
handleSetFloorsConfig({enabled: true});
_floorDataForAuction[AUCTION_END_EVENT.auctionId] = utils.deepClone(basicFloorConfig);
events.emit(CONSTANTS.EVENTS.AUCTION_END, AUCTION_END_EVENT);
// should still be here
expect(_floorDataForAuction[AUCTION_END_EVENT.auctionId]).to.not.be.undefined;
// tick for 4 seconds
clock.tick(4000);
// should be undefined now
expect(_floorDataForAuction[AUCTION_END_EVENT.auctionId]).to.be.undefined;
});
});
});

0 comments on commit e7a34e9

Please sign in to comment.