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

Fix #3813 move auctionEnd events so it always executes when auction completes #3841

Merged
merged 2 commits into from
Jun 18, 2019
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
25 changes: 13 additions & 12 deletions src/auction.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
clearTimeout(_timer);
}

if (_callback != null) {
if (_auctionEnd === undefined) {
let timedOutBidders = [];
if (timedOut) {
utils.logMessage(`Auction ${_auctionId} timedOut`);
Expand All @@ -150,17 +150,19 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
}
}

try {
_auctionStatus = AUCTION_COMPLETED;
_auctionEnd = Date.now();

events.emit(CONSTANTS.EVENTS.AUCTION_END, getProperties());
_auctionStatus = AUCTION_COMPLETED;
_auctionEnd = Date.now();

const adUnitCodes = _adUnitCodes;
const bids = _bidsReceived
.filter(utils.bind.call(adUnitsFilter, this, adUnitCodes))
.reduce(groupByPlacement, {});
_callback.apply($$PREBID_GLOBAL$$, [bids, timedOut]);
events.emit(CONSTANTS.EVENTS.AUCTION_END, getProperties());
try {
if (_callback != null) {
const adUnitCodes = _adUnitCodes;
const bids = _bidsReceived
.filter(utils.bind.call(adUnitsFilter, this, adUnitCodes))
.reduce(groupByPlacement, {});
_callback.apply($$PREBID_GLOBAL$$, [bids, timedOut]);
_callback = null;
}
} catch (e) {
utils.logError('Error executing bidsBackHandler', null, e);
} finally {
Expand All @@ -175,7 +177,6 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a
syncUsers(userSyncConfig.syncDelay);
}
}
_callback = null;
}
}

Expand Down
11 changes: 9 additions & 2 deletions test/spec/auctionmanager_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getKeyValueTargetingPairs, auctionCallbacks } from 'src/auction';
import { getKeyValueTargetingPairs, auctionCallbacks, AUCTION_COMPLETED } from 'src/auction';
import CONSTANTS from 'src/constants.json';
import { adjustBids } from 'src/auction';
import * as auctionModule from 'src/auction';
Expand Down Expand Up @@ -783,7 +783,8 @@ describe('auctionmanager.js', function () {
server.restore();
events.emit.restore();
});
it('should emit BID_TIMEOUT for timed out bids', function (done) {

it('should emit BID_TIMEOUT and AUCTION_END for timed out bids', function (done) {
const spec1 = mockBidder(BIDDER_CODE, [bids[0]]);
registerBidder(spec1);
const spec2 = mockBidder(BIDDER_CODE1, [bids[1]]);
Expand All @@ -797,6 +798,12 @@ describe('auctionmanager.js', function () {
const timedOutBids = bidTimeoutCall.args[1];
assert.equal(timedOutBids.length, 1);
assert.equal(timedOutBids[0].bidder, BIDDER_CODE1);

const auctionEndCall = eventsEmitSpy.withArgs(CONSTANTS.EVENTS.AUCTION_END).getCalls()[0];
const auctionProps = auctionEndCall.args[1];
assert.equal(auctionProps.adUnits, adUnits);
assert.equal(auctionProps.timeout, 20);
assert.equal(auctionProps.auctionStatus, AUCTION_COMPLETED)
done();
}
auction = auctionModule.newAuction({adUnits, adUnitCodes, callback: auctionCallback, cbTimeout: 20});
Expand Down