Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delaying removal of floor data for 3 seconds #5360

Merged
merged 1 commit into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
});
});