Skip to content

Commit

Permalink
Test: Bidder specific tmax (#3651)
Browse files Browse the repository at this point in the history
* Increase tests coverage for bidder-specific tmax
  • Loading branch information
marki1an authored Jan 7, 2025
1 parent 716a139 commit 08187ba
Showing 1 changed file with 99 additions and 12 deletions.
111 changes: 99 additions & 12 deletions src/test/groovy/org/prebid/server/functional/tests/TimeoutSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class TimeoutSpec extends BaseSpec {

private static final int DEFAULT_TIMEOUT = getRandomTimeout()
private static final int MIN_TIMEOUT = PBSUtils.getRandomNumber(50, 150)
private static final Map PBS_CONFIG = ["auction.biddertmax.max" : MAX_TIMEOUT as String,
"auction.biddertmax.min" : MIN_TIMEOUT as String]
private static final Long MAX_AUCTION_BIDDER_TIMEOUT = 3000
private static final Long MIN_AUCTION_BIDDER_TIMEOUT = 1000
private static final Map PBS_CONFIG = ["auction.biddertmax.max": MAX_AUCTION_BIDDER_TIMEOUT as String,
"auction.biddertmax.min": MIN_AUCTION_BIDDER_TIMEOUT as String]

@Shared
PrebidServerService prebidServerService = pbsServiceFactory.getService(PBS_CONFIG)
Expand Down Expand Up @@ -136,9 +138,10 @@ class TimeoutSpec extends BaseSpec {

and: "Pbs config with default request"
def pbsContainer = new PrebidServerContainer(
["default-request.file.path" : APP_WORKDIR + defaultRequest.fileName,
"auction.biddertmax.max" : MAX_TIMEOUT as String]).tap {
withCopyFileToContainer(MountableFile.forHostPath(defaultRequest), APP_WORKDIR) }
["default-request.file.path": APP_WORKDIR + defaultRequest.fileName,
"auction.biddertmax.max" : MAX_TIMEOUT as String]).tap {
withCopyFileToContainer(MountableFile.forHostPath(defaultRequest), APP_WORKDIR)
}
pbsContainer.start()
def pbsService = new PrebidServerService(pbsContainer)

Expand Down Expand Up @@ -284,8 +287,9 @@ class TimeoutSpec extends BaseSpec {
def "PBS should choose min timeout form config for bidder request when in request value lowest that in auction.biddertmax.min"() {
given: "PBS config with percent"
def minBidderTmax = PBSUtils.getRandomNumber(MIN_TIMEOUT, MAX_TIMEOUT)
def prebidServerService = pbsServiceFactory.getService(["auction.biddertmax.min" : minBidderTmax as String,
"auction.biddertmax.max" : MAX_TIMEOUT as String])
def prebidServerService = pbsServiceFactory.getService(
["auction.biddertmax.min": minBidderTmax as String,
"auction.biddertmax.max": MAX_TIMEOUT as String])

and: "Default basic BidRequest"
def timeout = PBSUtils.getRandomNumber(0, minBidderTmax)
Expand All @@ -307,11 +311,14 @@ class TimeoutSpec extends BaseSpec {
def "PBS should change timeout for bidder due to percent in auction.biddertmax.percent"() {
given: "PBS config with percent"
def percent = PBSUtils.getRandomNumber(2, 98)
def prebidServerService = pbsServiceFactory.getService(["auction.biddertmax.percent": percent as String]
+ PBS_CONFIG)
def pbsConfig = ["auction.biddertmax.percent": percent as String,
"auction.biddertmax.max" : MAX_TIMEOUT as String,
"auction.biddertmax.min" : MIN_TIMEOUT as String]
def prebidServerService = pbsServiceFactory.getService(
pbsConfig)

and: "Default basic BidRequest with generic bidder"
def timeout = getRandomTimeout()
def timeout = randomTimeout
def bidRequest = BidRequest.defaultBidRequest.tap {
tmax = timeout
}
Expand All @@ -321,17 +328,97 @@ class TimeoutSpec extends BaseSpec {

then: "Bidder request should contain percent of request value"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert isInternalProcessingTime(bidderRequest.tmax, getPercentOfValue(percent,timeout))
assert isInternalProcessingTime(bidderRequest.tmax, getPercentOfValue(percent, timeout))

and: "PBS response should contain tmax from request"
assert bidResponse?.ext?.tmaxrequest == timeout as Long

cleanup: "Stop and remove pbs container"
pbsServiceFactory.removeContainer(pbsConfig)
}

def "PBS should apply auction.biddertmax.max timeout when adapters.generic.tmax-deduction-ms exceeds valid top range"() {
given: "PBS config with adapters.generic.tmax-deduction-ms"
def pbsConfig = PBS_CONFIG + ["adapters.generic.tmax-deduction-ms": PBSUtils.getRandomNumber(MAX_AUCTION_BIDDER_TIMEOUT as int) as String]
def prebidServerService = pbsServiceFactory.getService(pbsConfig)

and: "Default basic BidRequest with generic bidder"
def bidRequest = BidRequest.defaultBidRequest.tap {
tmax = randomTimeout
}

when: "PBS processes auction request"
def bidResponse = prebidServerService.sendAuctionRequest(bidRequest)

then: "Bidder request should contain min"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert bidderRequest.tmax == MIN_AUCTION_BIDDER_TIMEOUT

and: "PBS response should contain tmax"
assert bidResponse?.ext?.tmaxrequest == MAX_AUCTION_BIDDER_TIMEOUT

cleanup: "Stop and remove pbs container"
pbsServiceFactory.removeContainer(pbsConfig)
}

def "PBS should resolve timeout as usual when adapters.generic.tmax-deduction-ms specifies zero"() {
given: "PBS config with adapters.generic.tmax-deduction-ms"
def pbsConfig = ["adapters.generic.tmax-deduction-ms": "0"] + PBS_CONFIG
def prebidServerService = pbsServiceFactory.getService(pbsConfig)

and: "Default basic BidRequest with generic bidder"
def timeout = PBSUtils.getRandomNumber(
MIN_AUCTION_BIDDER_TIMEOUT as int,
MAX_AUCTION_BIDDER_TIMEOUT as int)
def bidRequest = BidRequest.defaultBidRequest.tap {
tmax = timeout
}

when: "PBS processes auction request"
def bidResponse = prebidServerService.sendAuctionRequest(bidRequest)

then: "Bidder request should contain right value in tmax"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert isInternalProcessingTime(bidderRequest.tmax, timeout)

and: "PBS response should contain tmax"
assert bidResponse?.ext?.tmaxrequest == timeout as Long

cleanup: "Stop and remove pbs container"
pbsServiceFactory.removeContainer(pbsConfig)
}

def "PBS should properly resolve tmax deduction ms when adapters.generic.tmax-deduction-ms specified"() {
given: "PBS config with adapters.generic.tmax-deduction-ms"
def genericDeductionMs = PBSUtils.getRandomNumber(100, 300)
def randomTimeout = PBSUtils.getRandomNumber(MIN_AUCTION_BIDDER_TIMEOUT + genericDeductionMs as int, MAX_AUCTION_BIDDER_TIMEOUT as int)
def pbsConfig = PBS_CONFIG + ["adapters.generic.tmax-deduction-ms": genericDeductionMs as String]
def prebidServerService = pbsServiceFactory.getService(pbsConfig)

and: "Default basic BidRequest with generic bidder"
def bidRequest = BidRequest.defaultBidRequest.tap {
tmax = randomTimeout
}

when: "PBS processes auction request"
def bidResponse = prebidServerService.sendAuctionRequest(bidRequest)

then: "Bidder request should contain right value in tmax"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert isInternalProcessingTime(bidderRequest.tmax, randomTimeout)

and: "PBS response should contain tmax"
assert bidResponse?.ext?.tmaxrequest == randomTimeout as Long

cleanup: "Stop and remove pbs container"
pbsServiceFactory.removeContainer(pbsConfig)
}

private static long getPercentOfValue(int percent, int value) {
(percent * value) / 100.0 as Long
}

private static boolean isInternalProcessingTime(long bidderRequestTimeout, long requestTimeout){
private static boolean isInternalProcessingTime(long bidderRequestTimeout, long requestTimeout) {
0 < requestTimeout - bidderRequestTimeout
}
}

0 comments on commit 08187ba

Please sign in to comment.