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

prevent rubicon adapter from registering two bids on exceptions #854

Merged
merged 1 commit into from
Dec 16, 2016
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
20 changes: 13 additions & 7 deletions src/adapters/rubicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function RubiconAdapter() {
ajax(buildOptimizedCall(bid), bidCallback, undefined, {withCredentials: true});
} catch(err) {
utils.logError('Error sending rubicon request for placement code ' + bid.placementCode, null, err);
addErrorBid();
}

function bidCallback(responseText) {
Expand All @@ -64,14 +65,15 @@ function RubiconAdapter() {
} else {
utils.logError('Error processing rubicon response for placement code ' + bid.placementCode, null, err);
}

//indicate that there is no bid for this placement
let badBid = bidfactory.createBid(STATUS.NO_BID, bid);
badBid.bidderCode = bid.bidder;
badBid.error = err;
bidmanager.addBidResponse(bid.placementCode, badBid);
addErrorBid();
}
}

function addErrorBid() {
let badBid = bidfactory.createBid(STATUS.NO_BID, bid);
badBid.bidderCode = bid.bidder;
bidmanager.addBidResponse(bid.placementCode, badBid);
}
});
}

Expand Down Expand Up @@ -180,7 +182,11 @@ function RubiconAdapter() {
[bid.width, bid.height] = sizeMap[ad.size_id].split('x').map(num => Number(num));
bid.dealId = responseObj.deal;

bidmanager.addBidResponse(bidRequest.placementCode, bid);
try {
bidmanager.addBidResponse(bidRequest.placementCode, bid);
} catch (err) {
utils.logError('Error from addBidResponse', null, err);
}
});
}

Expand Down
58 changes: 53 additions & 5 deletions test/spec/adapters/rubicon_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,18 @@ describe('the rubicon adapter', () => {
describe('requests', () => {

let xhr,
screen;
bids;

beforeEach(() => {
rubiconAdapter = new RubiconAdapter();

bids = [];

xhr = sandbox.useFakeXMLHttpRequest();

sandbox.stub(bidManager, 'addBidResponse', (elemId, bid) => {
bids.push(bid);
});
});

afterEach(() => {
Expand Down Expand Up @@ -235,7 +241,7 @@ describe('the rubicon adapter', () => {

});

it('should not send a request if no valid sizes', () => {
it('should not send a request and register an error bid if no valid sizes', () => {

var sizesBidderRequest = clone(bidderRequest);
sizesBidderRequest.bids[0].sizes = [[620,250],[300,251]];
Expand All @@ -244,14 +250,19 @@ describe('the rubicon adapter', () => {

expect(xhr.requests.length).to.equal(0);

expect(bidManager.addBidResponse.calledOnce).to.equal(true);
expect(bids).to.be.lengthOf(1);
expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID);

});

});


describe('response handler', () => {
let bids,
server;
server,
addBidResponseAction;

beforeEach(() => {
bids = [];
Expand All @@ -260,6 +271,10 @@ describe('the rubicon adapter', () => {

sandbox.stub(bidManager, 'addBidResponse', (elemId, bid) => {
bids.push(bid);
if(addBidResponseAction) {
addBidResponseAction();
addBidResponseAction = undefined;
}
});
});

Expand Down Expand Up @@ -441,7 +456,40 @@ describe('the rubicon adapter', () => {
expect(bidManager.addBidResponse.calledOnce).to.equal(true);
expect(bids).to.be.lengthOf(1);
expect(bids[0].getStatusCode()).to.equal(CONSTANTS.STATUS.NO_BID);
expect(bids[0].error instanceof SyntaxError).to.equal(true);
});

it('should not register an error bid when a success call to addBidResponse throws an error', () => {

server.respondWith(JSON.stringify({
"status": "ok",
"account_id": 14062,
"site_id": 70608,
"zone_id": 530022,
"size_id": 15,
"alt_size_ids": [
43
],
"tracking": "",
"inventory": {},
"ads": [{
"status": "ok",
"cpm": .8,
"size_id": 15
}]
}));

addBidResponseAction = function() {
throw new Error("test error");
};

rubiconAdapter.callBids(bidderRequest);

server.respond();

// was calling twice for same bid, but should only call once
expect(bidManager.addBidResponse.calledOnce).to.equal(true);
expect(bids).to.be.lengthOf(1);

});

})
Expand All @@ -453,4 +501,4 @@ describe('the rubicon adapter', () => {

function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}
}