From 51fe124a5393c7c9d07c948aa2c8008b7030be11 Mon Sep 17 00:00:00 2001 From: Veronika Solovei Date: Mon, 11 May 2020 16:40:16 -0700 Subject: [PATCH 1/3] Bugfix for missing fields in imp.video --- endpoints/openrtb2/video_auction.go | 10 +++------- endpoints/openrtb2/video_auction_test.go | 25 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/endpoints/openrtb2/video_auction.go b/endpoints/openrtb2/video_auction.go index c7316604d73..d3ac2000472 100644 --- a/endpoints/openrtb2/video_auction.go +++ b/endpoints/openrtb2/video_auction.go @@ -350,7 +350,7 @@ func (deps *endpointDeps) createImpressions(videoReq *openrtb_ext.BidRequestVide impsArray := make([]openrtb.Imp, numImps) for impInd := range impsArray { - newImp := createImpressionTemplate(storedImp, videoData) + newImp := createImpressionTemplate(storedImp, *videoData) impsArray[impInd] = newImp if reqExactDur { //floor := int(math.Floor(ind/impDivNumber)) @@ -380,12 +380,8 @@ func max(a, b int) int { return b } -func createImpressionTemplate(imp openrtb.Imp, video *openrtb.Video) openrtb.Imp { - imp.Video = &openrtb.Video{} - imp.Video.W = video.W - imp.Video.H = video.H - imp.Video.Protocols = video.Protocols - imp.Video.MIMEs = video.MIMEs +func createImpressionTemplate(imp openrtb.Imp, video openrtb.Video) openrtb.Imp { + imp.Video = &video return imp } diff --git a/endpoints/openrtb2/video_auction_test.go b/endpoints/openrtb2/video_auction_test.go index ec525c6ff08..562cf27d215 100644 --- a/endpoints/openrtb2/video_auction_test.go +++ b/endpoints/openrtb2/video_auction_test.go @@ -1005,6 +1005,31 @@ func TestHandleErrorDebugLog(t *testing.T) { assert.NotEmpty(t, debugLog.CacheKey, "DebugLog CacheKey value should have been set") } +func TestCreateImpressionTemplate(t *testing.T) { + + imp := openrtb.Imp{} + imp.Video = &openrtb.Video{} + imp.Video.Protocols = []openrtb.Protocol{1, 2} + imp.Video.MIMEs = []string{"video/mp4"} + imp.Video.H = 200 + imp.Video.W = 400 + imp.Video.PlaybackMethod = []openrtb.PlaybackMethod{5, 6} + + video := openrtb.Video{} + video.Protocols = []openrtb.Protocol{3, 4} + video.MIMEs = []string{"video/flv"} + video.H = 300 + video.W = 0 + video.PlaybackMethod = []openrtb.PlaybackMethod{7, 8} + + res := createImpressionTemplate(imp, video) + assert.Equal(t, res.Video.Protocols, []openrtb.Protocol{3, 4}, "") + assert.Equal(t, res.Video.MIMEs, []string{"video/flv"}, "") + assert.Equal(t, int(res.Video.H), 300, "") + assert.Equal(t, int(res.Video.W), 0, "") + assert.Equal(t, res.Video.PlaybackMethod, []openrtb.PlaybackMethod{7, 8}, "") +} + func mockDepsWithMetrics(t *testing.T, ex *mockExchangeVideo) (*endpointDeps, *pbsmetrics.Metrics, *mockAnalyticsModule) { theMetrics := pbsmetrics.NewMetrics(metrics.NewRegistry(), openrtb_ext.BidderList(), config.DisabledMetrics{}) mockModule := &mockAnalyticsModule{} From 15489eb505439f0ad46c73213e67c6280a7028e2 Mon Sep 17 00:00:00 2001 From: Veronika Solovei Date: Tue, 12 May 2020 12:10:38 -0700 Subject: [PATCH 2/3] Minor refactoring --- endpoints/openrtb2/video_auction.go | 9 ++++++--- endpoints/openrtb2/video_auction_test.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/endpoints/openrtb2/video_auction.go b/endpoints/openrtb2/video_auction.go index d3ac2000472..cda1a6c411b 100644 --- a/endpoints/openrtb2/video_auction.go +++ b/endpoints/openrtb2/video_auction.go @@ -350,7 +350,7 @@ func (deps *endpointDeps) createImpressions(videoReq *openrtb_ext.BidRequestVide impsArray := make([]openrtb.Imp, numImps) for impInd := range impsArray { - newImp := createImpressionTemplate(storedImp, *videoData) + newImp := createImpressionTemplate(storedImp, videoData) impsArray[impInd] = newImp if reqExactDur { //floor := int(math.Floor(ind/impDivNumber)) @@ -380,8 +380,11 @@ func max(a, b int) int { return b } -func createImpressionTemplate(imp openrtb.Imp, video openrtb.Video) openrtb.Imp { - imp.Video = &video +func createImpressionTemplate(imp openrtb.Imp, video *openrtb.Video) openrtb.Imp { + //for every new impression we need to have it's own copy of video object, because we customize it in further processing + newVideo := &openrtb.Video{} + *newVideo = *video + imp.Video = newVideo return imp } diff --git a/endpoints/openrtb2/video_auction_test.go b/endpoints/openrtb2/video_auction_test.go index 562cf27d215..7b014eb5321 100644 --- a/endpoints/openrtb2/video_auction_test.go +++ b/endpoints/openrtb2/video_auction_test.go @@ -1022,7 +1022,7 @@ func TestCreateImpressionTemplate(t *testing.T) { video.W = 0 video.PlaybackMethod = []openrtb.PlaybackMethod{7, 8} - res := createImpressionTemplate(imp, video) + res := createImpressionTemplate(imp, &video) assert.Equal(t, res.Video.Protocols, []openrtb.Protocol{3, 4}, "") assert.Equal(t, res.Video.MIMEs, []string{"video/flv"}, "") assert.Equal(t, int(res.Video.H), 300, "") From 9e59ee90fc27f2938b3e62790e1d8b9fcd397ef9 Mon Sep 17 00:00:00 2001 From: Veronika Solovei Date: Tue, 12 May 2020 15:50:41 -0700 Subject: [PATCH 3/3] Minor refactoring --- endpoints/openrtb2/video_auction.go | 5 ++--- endpoints/openrtb2/video_auction_test.go | 10 +++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/endpoints/openrtb2/video_auction.go b/endpoints/openrtb2/video_auction.go index cda1a6c411b..cf764bc9d2d 100644 --- a/endpoints/openrtb2/video_auction.go +++ b/endpoints/openrtb2/video_auction.go @@ -382,9 +382,8 @@ func max(a, b int) int { func createImpressionTemplate(imp openrtb.Imp, video *openrtb.Video) openrtb.Imp { //for every new impression we need to have it's own copy of video object, because we customize it in further processing - newVideo := &openrtb.Video{} - *newVideo = *video - imp.Video = newVideo + newVideo := *video + imp.Video = &newVideo return imp } diff --git a/endpoints/openrtb2/video_auction_test.go b/endpoints/openrtb2/video_auction_test.go index 7b014eb5321..38c9dc3f685 100644 --- a/endpoints/openrtb2/video_auction_test.go +++ b/endpoints/openrtb2/video_auction_test.go @@ -1023,11 +1023,11 @@ func TestCreateImpressionTemplate(t *testing.T) { video.PlaybackMethod = []openrtb.PlaybackMethod{7, 8} res := createImpressionTemplate(imp, &video) - assert.Equal(t, res.Video.Protocols, []openrtb.Protocol{3, 4}, "") - assert.Equal(t, res.Video.MIMEs, []string{"video/flv"}, "") - assert.Equal(t, int(res.Video.H), 300, "") - assert.Equal(t, int(res.Video.W), 0, "") - assert.Equal(t, res.Video.PlaybackMethod, []openrtb.PlaybackMethod{7, 8}, "") + assert.Equal(t, res.Video.Protocols, []openrtb.Protocol{3, 4}, "Incorrect video protocols") + assert.Equal(t, res.Video.MIMEs, []string{"video/flv"}, "Incorrect video MIMEs") + assert.Equal(t, int(res.Video.H), 300, "Incorrect video height") + assert.Equal(t, int(res.Video.W), 0, "Incorrect video width") + assert.Equal(t, res.Video.PlaybackMethod, []openrtb.PlaybackMethod{7, 8}, "Incorrect video playback method") } func mockDepsWithMetrics(t *testing.T, ex *mockExchangeVideo) (*endpointDeps, *pbsmetrics.Metrics, *mockAnalyticsModule) {