Skip to content

Commit

Permalink
Fix race condition in modularity test (#3421)
Browse files Browse the repository at this point in the history
  • Loading branch information
VeronikaSolovei9 authored Jan 23, 2024
1 parent ed5e887 commit 498955b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
39 changes: 26 additions & 13 deletions exchange/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5699,13 +5699,22 @@ func TestModulesCanBeExecutedForMultipleBiddersSimultaneously(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(noBidServer))
defer server.Close()

bidderImpl := &goodSingleBidder{
httpRequest: &adapters.RequestData{
Method: "POST",
Uri: server.URL,
Body: []byte(`{"key":"val"}`),
Headers: http.Header{},
},
reqBdy := []byte(`{"key":"val"}`)

bidderImplAppnexus := &goodSingleBidder{
httpRequest: &adapters.RequestData{Method: http.MethodPost, Uri: server.URL, Body: reqBdy, Headers: http.Header{}},
bidResponse: &adapters.BidderResponse{},
}
bidderImplTelaria := &goodSingleBidder{
httpRequest: &adapters.RequestData{Method: http.MethodPost, Uri: server.URL, Body: reqBdy, Headers: http.Header{}},
bidResponse: &adapters.BidderResponse{},
}
bidderImpl33Across := &goodSingleBidder{
httpRequest: &adapters.RequestData{Method: http.MethodPost, Uri: server.URL, Body: reqBdy, Headers: http.Header{}},
bidResponse: &adapters.BidderResponse{},
}
bidderImplAax := &goodSingleBidder{
httpRequest: &adapters.RequestData{Method: http.MethodPost, Uri: server.URL, Body: reqBdy, Headers: http.Header{}},
bidResponse: &adapters.BidderResponse{},
}

Expand Down Expand Up @@ -5744,10 +5753,10 @@ func TestModulesCanBeExecutedForMultipleBiddersSimultaneously(t *testing.T) {
}

e.adapterMap = map[openrtb_ext.BidderName]AdaptedBidder{
openrtb_ext.BidderAppnexus: AdaptBidder(bidderImpl, server.Client(), &config.Configuration{}, &metricsConfig.NilMetricsEngine{}, openrtb_ext.BidderAppnexus, &config.DebugInfo{}, ""),
openrtb_ext.BidderTelaria: AdaptBidder(bidderImpl, server.Client(), &config.Configuration{}, &metricsConfig.NilMetricsEngine{}, openrtb_ext.BidderAppnexus, &config.DebugInfo{}, ""),
openrtb_ext.Bidder33Across: AdaptBidder(bidderImpl, server.Client(), &config.Configuration{}, &metricsConfig.NilMetricsEngine{}, openrtb_ext.Bidder33Across, &config.DebugInfo{}, ""),
openrtb_ext.BidderAax: AdaptBidder(bidderImpl, server.Client(), &config.Configuration{}, &metricsConfig.NilMetricsEngine{}, openrtb_ext.BidderAax, &config.DebugInfo{}, ""),
openrtb_ext.BidderAppnexus: AdaptBidder(bidderImplAppnexus, server.Client(), &config.Configuration{}, &metricsConfig.NilMetricsEngine{}, openrtb_ext.BidderAppnexus, &config.DebugInfo{}, ""),
openrtb_ext.BidderTelaria: AdaptBidder(bidderImplTelaria, server.Client(), &config.Configuration{}, &metricsConfig.NilMetricsEngine{}, openrtb_ext.BidderTelaria, &config.DebugInfo{}, ""),
openrtb_ext.Bidder33Across: AdaptBidder(bidderImpl33Across, server.Client(), &config.Configuration{}, &metricsConfig.NilMetricsEngine{}, openrtb_ext.Bidder33Across, &config.DebugInfo{}, ""),
openrtb_ext.BidderAax: AdaptBidder(bidderImplAax, server.Client(), &config.Configuration{}, &metricsConfig.NilMetricsEngine{}, openrtb_ext.BidderAax, &config.DebugInfo{}, ""),
}
// Run test
_, err := e.HoldAuction(context.Background(), auctionRequest, &DebugLog{})
Expand Down Expand Up @@ -5805,12 +5814,16 @@ func (e mockUpdateBidRequestHook) HandleBidderRequestHook(_ context.Context, mct
c := hookstage.ChangeSet[hookstage.BidderRequestPayload]{}
c.AddMutation(
func(payload hookstage.BidderRequestPayload) (hookstage.BidderRequestPayload, error) {
payload.Request.Site.Name = "test"
site := ptrutil.Clone(payload.Request.Site)
site.Name = "test"
payload.Request.Site = site
return payload, nil
}, hookstage.MutationUpdate, "bidRequest", "site.name",
).AddMutation(
func(payload hookstage.BidderRequestPayload) (hookstage.BidderRequestPayload, error) {
payload.Request.Site.Domain = "test.com"
site := ptrutil.Clone(payload.Request.Site)
site.Domain = "test.com"
payload.Request.Site = site
return payload, nil
}, hookstage.MutationUpdate, "bidRequest", "site.domain",
)
Expand Down
9 changes: 7 additions & 2 deletions hooks/hookexecution/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/prebid/prebid-server/v2/hooks/hookstage"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/prebid/prebid-server/v2/util/ptrutil"
)

type mockUpdateHeaderEntrypointHook struct{}
Expand Down Expand Up @@ -330,12 +331,16 @@ func (e mockUpdateBidRequestHook) HandleBidderRequestHook(_ context.Context, _ h
c := hookstage.ChangeSet[hookstage.BidderRequestPayload]{}
c.AddMutation(
func(payload hookstage.BidderRequestPayload) (hookstage.BidderRequestPayload, error) {
payload.Request.User.Yob = 2000
user := ptrutil.Clone(payload.Request.User)
user.Yob = 2000
payload.Request.User = user
return payload, nil
}, hookstage.MutationUpdate, "bidRequest", "user.yob",
).AddMutation(
func(payload hookstage.BidderRequestPayload) (hookstage.BidderRequestPayload, error) {
payload.Request.User.Consent = "true"
user := ptrutil.Clone(payload.Request.User)
user.Consent = "true"
payload.Request.User = user
return payload, nil
}, hookstage.MutationUpdate, "bidRequest", "user.consent",
)
Expand Down

0 comments on commit 498955b

Please sign in to comment.