-
Notifications
You must be signed in to change notification settings - Fork 693
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
bidRequest.Source.Ext wasn't cloned in prepareSource #2070
Changes from 4 commits
c878098
4eb11e5
a831f99
3d33426
46e5b47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2609,8 +2609,48 @@ func TestBuildXPrebidHeader(t *testing.T) { | |
} | ||
} | ||
|
||
func TestApplyFPD(t *testing.T) { | ||
func TestSourceExtSChainCopied(t *testing.T) { | ||
bidRequest := newBidRequest(t) | ||
|
||
bidderSchains := map[string]*openrtb_ext.ExtRequestPrebidSChainSChain{ | ||
"bidder1": { | ||
Ver: "1.0", | ||
Complete: 1, | ||
Nodes: []*openrtb_ext.ExtRequestPrebidSChainSChainNode{ | ||
{ | ||
ASI: "bidder1.com", | ||
SID: "0001", | ||
HP: 1, | ||
}, | ||
}, | ||
}, | ||
"bidder2": { | ||
Ver: "1.0", | ||
Complete: 1, | ||
Nodes: []*openrtb_ext.ExtRequestPrebidSChainSChainNode{ | ||
{ | ||
ASI: "bidder2.com", | ||
SID: "0002", | ||
HP: 1, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
copy1 := *bidRequest | ||
originalTid := copy1.Source.TID | ||
prepareSource(©1, "bidder1", bidderSchains) | ||
copy2 := *bidRequest | ||
copy2.Source.TID = "new TID" | ||
prepareSource(©2, "bidder2", bidderSchains) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, that would destroy the purpose of the test. It’s supposed to test that a sequence of calls to prepareSource will only modify the bidRequest being sent in. Maybe I wasn’t clear about what this bug is all about. Without the bug fix “copy1” would be affected by the second call with the “copy2” parameter. This causes bidder specific schains to not work at all and has probably never worked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i.e. the following would pass where complete is 2 in both cases (which is clearly wrong):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If newly added lines 307 to 309 get removed
And the newly added
Can we explicitly assert this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guscarreon You're right, the test was sloppy. Let me fix this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guscarreon please check latest commit |
||
|
||
assert.Equal(t, json.RawMessage(`{"schain":{"complete":1,"nodes":[{"asi":"bidder1.com","sid":"0001","hp":1}],"ver":"1.0"}}`), copy1.Source.Ext, "First schain was overwritten or not set") | ||
assert.Equal(t, originalTid, copy1.Source.TID, "Original TID was overwritten") | ||
assert.Equal(t, json.RawMessage(`{"schain":{"complete":1,"nodes":[{"asi":"bidder2.com","sid":"0002","hp":1}],"ver":"1.0"}}`), copy2.Source.Ext, "Second schain was overwritten or not set") | ||
assert.Equal(t, "new TID", copy2.Source.TID, "New TID was not set") | ||
} | ||
|
||
func TestApplyFPD(t *testing.T) { | ||
fpdBidderTest := map[openrtb_ext.BidderName]*firstpartydata.ResolvedFirstPartyData{} | ||
bidderTest := openrtb_ext.BidderName("test") | ||
fpdBidderTest[bidderTest] = &firstpartydata.ResolvedFirstPartyData{Site: nil, App: nil, User: nil} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch finding this bug. This test works but what are you thoughts on adding a higher level test instead that isn't specifically focused on the copy function but rather verifies schains are correctly added to the bid requests when there are multiple bidders:
I stole some of this setup from
TestCleanOpenRTBRequestsSChain
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bsardo I don't have a strong opinion on that, and I frankly don't know the code well enough to make a good decision :) I do however think a unit tests like the one I wrote is more to the point perhaps. But I don't mind at all replacing my test with the one you proposed if you think that is the better choice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried the test @bsardo proposes above in my local machine and it works as it is. @bjorn-lw can we add it as part of your PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guscarreon I tested it as well, it worked right away :) I can add it to the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guscarreon Github says I dismissed your review. I guess my new commit caused that..