-
Notifications
You must be signed in to change notification settings - Fork 224
Test: Vtrack account ttl #4241
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
Merged
Merged
Test: Vtrack account ttl #4241
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9f0bb65
Add test for video cache TTL enforcement for /vtrack endpoint
marki1an 9ed2955
Update after review, and add a tests case for vtrack
marki1an 127abac
Merge branch 'vtrack-account-ttl' into test/vtrack-account-ttl
marki1an 8caf9df
Update after review, and add a tests case for vtrack
marki1an 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 hidden or 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
9 changes: 9 additions & 0 deletions
9
src/test/groovy/org/prebid/server/functional/model/config/AccountVtrackConfig.groovy
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package org.prebid.server.functional.model.config | ||
|
|
||
| import groovy.transform.ToString | ||
|
|
||
| @ToString(includeNames = true, ignoreNulls = true) | ||
| class AccountVtrackConfig { | ||
|
|
||
| Integer ttl | ||
| } |
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import org.prebid.server.functional.model.config.AccountAuctionConfig | |
| import org.prebid.server.functional.model.config.AccountCacheConfig | ||
| import org.prebid.server.functional.model.config.AccountConfig | ||
| import org.prebid.server.functional.model.config.AccountEventsConfig | ||
| import org.prebid.server.functional.model.config.AccountVtrackConfig | ||
| import org.prebid.server.functional.model.db.Account | ||
| import org.prebid.server.functional.model.request.auction.Asset | ||
| import org.prebid.server.functional.model.request.auction.BidRequest | ||
|
|
@@ -13,8 +14,10 @@ import org.prebid.server.functional.model.request.vtrack.VtrackRequest | |
| import org.prebid.server.functional.model.request.vtrack.xml.Vast | ||
| import org.prebid.server.functional.model.response.auction.Adm | ||
| import org.prebid.server.functional.model.response.auction.BidResponse | ||
| import org.prebid.server.functional.service.PrebidServerException | ||
| import org.prebid.server.functional.util.PBSUtils | ||
|
|
||
| import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST | ||
| import static org.prebid.server.functional.model.response.auction.ErrorType.CACHE | ||
| import static org.prebid.server.functional.model.AccountStatus.ACTIVE | ||
| import static org.prebid.server.functional.model.bidder.BidderName.GENERIC | ||
|
|
@@ -607,7 +610,7 @@ class CacheSpec extends BaseSpec { | |
| assert prebidCache.getRequestCount(bidRequest.imp[0].id) == 1 | ||
|
|
||
| and: "Bid response targeting should contain value" | ||
| verifyAll (bidResponse?.seatbid[0]?.bid[0]?.ext?.prebid?.targeting as Map) { | ||
| verifyAll(bidResponse?.seatbid[0]?.bid[0]?.ext?.prebid?.targeting as Map) { | ||
| it.get("hb_cache_id") | ||
| it.get("hb_cache_id_generic") | ||
| it.get("hb_cache_path") == CACHE_PATH | ||
|
|
@@ -643,7 +646,7 @@ class CacheSpec extends BaseSpec { | |
| assert prebidCache.getRequestCount(bidRequest.imp[0].id) == 1 | ||
|
|
||
| and: "Bid response targeting should contain value" | ||
| verifyAll (bidResponse.seatbid[0].bid[0].ext.prebid.targeting) { | ||
| verifyAll(bidResponse.seatbid[0].bid[0].ext.prebid.targeting) { | ||
| it.get("hb_cache_id") | ||
| it.get("hb_cache_id_generic") | ||
| it.get("hb_cache_path") == INTERNAL_CACHE_PATH | ||
|
|
@@ -785,4 +788,120 @@ class CacheSpec extends BaseSpec { | |
| where: | ||
| enabledCacheConcfig << [null, false, true] | ||
| } | ||
|
|
||
| def "PBS should failed VTrack request when sending request without account"() { | ||
| given: "Default VtrackRequest" | ||
| def creative = encodeXml(Vast.getDefaultVastModel(PBSUtils.randomString)) | ||
| def request = VtrackRequest.getDefaultVtrackRequest(creative) | ||
|
|
||
| and: "Flush metrics" | ||
| flushMetrics(defaultPbsService) | ||
|
|
||
| when: "PBS processes vtrack request" | ||
| defaultPbsService.sendVtrackRequest(request, null) | ||
|
|
||
| then: "Request should fail with an error" | ||
| def exception = thrown(PrebidServerException) | ||
| assert exception.statusCode == BAD_REQUEST.code() | ||
| assert exception.responseBody == "Account 'a' is required query parameter and can't be empty" | ||
| } | ||
|
|
||
| def "PBS shouldn't negative value in tllSecond when account vtrack ttl is #accountTtl and request ttl second is #requestedTtl"() { | ||
| given: "Default VtrackRequest" | ||
| def creative = encodeXml(Vast.getDefaultVastModel(PBSUtils.randomString)) | ||
| def request = VtrackRequest.getDefaultVtrackRequest(creative).tap { | ||
| puts[0].ttlseconds = requestedTtl | ||
| } | ||
|
|
||
| and: "Create and save vtrack in account" | ||
| def accountId = PBSUtils.randomNumber.toString() | ||
| def account = new Account().tap { | ||
| it.uuid = accountId | ||
| it.config = new AccountConfig().tap { | ||
| it.vtrack = new AccountVtrackConfig(ttl: accountTtl) | ||
| } | ||
| } | ||
| accountDao.save(account) | ||
|
|
||
| and: "Flush metrics" | ||
| flushMetrics(defaultPbsService) | ||
|
|
||
| when: "PBS processes vtrack request" | ||
| defaultPbsService.sendVtrackRequest(request, accountId) | ||
|
|
||
| then: "Pbs should emit creative_ttl.xml with lowest value" | ||
| def metrics = defaultPbsService.sendCollectedMetricsRequest() | ||
| assert metrics[XML_CREATIVE_TTL_ACCOUNT_METRIC.formatted(accountId)] | ||
| == [requestedTtl, accountTtl].findAll({ it -> it > 0 }).min() | ||
|
||
|
|
||
| where: | ||
| requestedTtl | accountTtl | ||
| PBSUtils.getRandomNumber(300, 1500) as Integer | PBSUtils.getRandomNegativeNumber(-1500, 300) as Integer | ||
| PBSUtils.getRandomNegativeNumber(-1500, 300) as Integer | PBSUtils.getRandomNumber(300, 1500) as Integer | ||
| PBSUtils.getRandomNegativeNumber(-1500, 300) as Integer | PBSUtils.getRandomNegativeNumber(-1500, 300) as Integer | ||
| } | ||
|
|
||
| def "PBS should use lowest tllSecond when account vtrack ttl is #accountTtl and request ttl second is #requestedTtl"() { | ||
| given: "Default VtrackRequest" | ||
| def creative = encodeXml(Vast.getDefaultVastModel(PBSUtils.randomString)) | ||
| def request = VtrackRequest.getDefaultVtrackRequest(creative).tap { | ||
| puts[0].ttlseconds = requestedTtl | ||
| } | ||
|
|
||
| and: "Create and save vtrack in account" | ||
| def accountId = PBSUtils.randomNumber.toString() | ||
| def account = new Account().tap { | ||
| it.uuid = accountId | ||
| it.config = new AccountConfig().tap { | ||
| it.vtrack = new AccountVtrackConfig(ttl: accountTtl) | ||
| } | ||
| } | ||
| accountDao.save(account) | ||
|
|
||
| and: "Flush metrics" | ||
| flushMetrics(defaultPbsService) | ||
|
|
||
| when: "PBS processes vtrack request" | ||
| defaultPbsService.sendVtrackRequest(request, accountId) | ||
|
|
||
| then: "Pbs should emit creative_ttl.xml with lowest value" | ||
| def metrics = defaultPbsService.sendCollectedMetricsRequest() | ||
| assert metrics[XML_CREATIVE_TTL_ACCOUNT_METRIC.formatted(accountId)] | ||
| == [requestedTtl, accountTtl].findAll().min() | ||
|
||
|
|
||
| where: | ||
| requestedTtl | accountTtl | ||
| null | null | ||
| null | PBSUtils.getRandomNumber(300, 1500) as Integer | ||
| PBSUtils.getRandomNumber(300, 1500) as Integer | null | ||
| PBSUtils.getRandomNumber(300, 1500) as Integer | PBSUtils.getRandomNumber(300, 1500) as Integer | ||
| } | ||
|
|
||
| def "PBS should proceed request when account ttl and request ttl second are empty"() { | ||
| given: "Default VtrackRequest" | ||
| def creative = encodeXml(Vast.getDefaultVastModel(PBSUtils.randomString)) | ||
| def request = VtrackRequest.getDefaultVtrackRequest(creative).tap { | ||
| puts[0].ttlseconds = null | ||
| } | ||
|
|
||
| and: "Create and save vtrack in account" | ||
| def accountId = PBSUtils.randomNumber.toString() | ||
| def account = new Account().tap { | ||
| it.uuid = accountId | ||
| it.config = new AccountConfig().tap { | ||
| it.vtrack = new AccountVtrackConfig(ttl: null) | ||
| } | ||
| } | ||
| accountDao.save(account) | ||
|
|
||
| and: "Flush metrics" | ||
| flushMetrics(defaultPbsService) | ||
|
|
||
| when: "PBS processes vtrack request" | ||
| defaultPbsService.sendVtrackRequest(request, accountId) | ||
|
|
||
| then: "Pbs shouldn't emit creative_ttl.xml" | ||
| def metrics = defaultPbsService.sendCollectedMetricsRequest() | ||
| assert !metrics[XML_CREATIVE_TTL_ACCOUNT_METRIC.formatted(accountId)] | ||
| } | ||
| } | ||
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.
PBS shouldn't use negative value