-
Notifications
You must be signed in to change notification settings - Fork 748
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
Test for data race conditions in adapters #1756
Merged
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7074f58
Data race test first draft
cbcc293
Step out real quick
a4c6c4a
Rollback CopyWithOption
dde3442
Implemented bid request deep copy function instead of importing library
8dc32b2
merge recent modifications to adapters/adapterstest/test_json.go
e81eceb
resolved conflicts
015fc30
informative comment
e22ffd7
Merge branch 'master' into sharedMemoryTest
4ce81b9
resolved openrtb2 merge conflicts
eb75ee4
Rolled back to use the github.com/jinzhu/copier library
87d8461
step out real quick
4e81fcf
Scott's review and deep copy library switch
77d9a54
updated with latest master and resolved merge conflicts
e8d3a6a
Added slice assertions
6be78a1
Major corrections. Removed the assertNoDataRace functions entirely
f96f9e7
Merge branch 'master' into sharedMemoryTest
1023f30
go mod tidy-ed
5f81f1d
Scott's latest review. Improving error messages and reducing large co…
4138379
Merge branch 'master' into sharedMemoryTest
d0e5e70
Modified imp shallow copies comment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -318,7 +318,7 @@ func diffJson(t *testing.T, description string, actual []byte, expected []byte) | |
} | ||
} | ||
|
||
// testMakeBidsImpl asserts the results of the bidder MakeRequests implementation against the | ||
// testMakeRequestsImpl asserts the results of the bidder MakeRequests implementation against the | ||
// expected JSON-defined results and makes sure the adapter's implementations of MakeRequests do | ||
// not incurr in data races | ||
func testMakeRequestsImpl(t *testing.T, filename string, spec *testSpec, bidder adapters.Bidder, reqInfo *adapters.ExtraRequestInfo) []*adapters.RequestData { | ||
|
@@ -343,9 +343,9 @@ func testMakeRequestsImpl(t *testing.T, filename string, spec *testSpec, bidder | |
// compared inside assertNoDataRace() to verify no data races occur. | ||
// - The shallow copy is helpful because it provides reference values to shared memory that we don't want | ||
// adapters to modify. | ||
// - The deep copy will help us preserve all the original values, even those of the shared memory fields, that | ||
// will remain untouched by the adapter tests so we can compare the real shared memory fields (that can | ||
// be accessed via the shallow copy) to their original values | ||
// - The deep copy will help us preserve all the original values, even those of the shared memory fields that | ||
// will remain untouched by the adapter tests so we can compare the real shared memory (that can | ||
// be accessed via the shallow copy) to its original values | ||
func getDataRaceTestCopies(original *openrtb2.BidRequest) (*openrtb2.BidRequest, *openrtb2.BidRequest) { | ||
deepReqCopy := deepcopy.Copy(original).(*openrtb2.BidRequest) | ||
|
||
|
@@ -375,6 +375,16 @@ func assertNoDataRace(t *testing.T, bidRequestBefore *openrtb2.BidRequest, bidRe | |
assert.Equal(t, bidRequestBefore.Source, bidRequestAfter.Source, "Data race in BidRequest.Source field in file %s", filename) | ||
assert.Equal(t, bidRequestBefore.Regs, bidRequestAfter.Regs, "Data race in BidRequest.Regs field in file %s", filename) | ||
|
||
// Assert slice fields were not modified by bidder adapter MakeRequests implementation | ||
assert.Equal(t, bidRequestBefore.WSeat, bidRequestAfter.WSeat, "Data race in BidRequest.[]WSeat array") | ||
assert.Equal(t, bidRequestBefore.BSeat, bidRequestAfter.BSeat, "Data race in BidRequest.[]BSeat array") | ||
assert.Equal(t, bidRequestBefore.Cur, bidRequestAfter.Cur, "Data race in BidRequest.[]Cur array") | ||
assert.Equal(t, bidRequestBefore.WLang, bidRequestAfter.WLang, "Data race in BidRequest.[]WLang array") | ||
assert.Equal(t, bidRequestBefore.BCat, bidRequestAfter.BCat, "Data race in BidRequest.[]BCat array") | ||
assert.Equal(t, bidRequestBefore.BAdv, bidRequestAfter.BAdv, "Data race in BidRequest.[]BAdv array") | ||
assert.Equal(t, bidRequestBefore.BApp, bidRequestAfter.BApp, "Data race in BidRequest.[]BApp array") | ||
assert.Equal(t, bidRequestBefore.Ext, bidRequestAfter.Ext, "Data race in BidRequest.[]Ext array") | ||
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. This is a string, not a slice. It's ok for the bidder to modify it since strings in Go are immutable. |
||
|
||
// Assert Imps separately | ||
assertNoImpsDataRace(t, bidRequestBefore.Imp, bidRequestAfter.Imp, filename) | ||
} | ||
|
@@ -393,7 +403,8 @@ func assertNoImpsDataRace(t *testing.T, impsBefore []openrtb2.Imp, impsAfter []o | |
assert.Equal(t, impsBefore[i].Native, impsAfter[i].Native, "Data race in bidRequest.Imp[%d].Native field. File:%s", i, filename) | ||
assert.Equal(t, impsBefore[i].PMP, impsAfter[i].PMP, "Data race in bidRequest.Imp[%d].PMP field. File:%s", i, filename) | ||
assert.Equal(t, impsBefore[i].Secure, impsAfter[i].Secure, "Data race in bidRequest.Imp[%d].Secure field. File:%s", i, filename) | ||
assert.ElementsMatch(t, impsBefore[i].Metric, impsAfter[i].Metric, "Data race in bidRequest.Imp[%d].[]Metric array. File:%s", i) | ||
assert.Equal(t, impsBefore[i].Metric, impsAfter[i].Metric, "Data race in bidRequest.Imp[%d].[]Metric array. File:%s", i) | ||
assert.Equal(t, impsBefore[i].IframeBuster, impsAfter[i].IframeBuster, "Data race in bidRequest.Imp[%d].[]IframeBuster array", i) | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please add in this comment that the
Imp[]
slice is purposefully excluded.