Skip to content

Commit 08187ba

Browse files
authored
Test: Bidder specific tmax (#3651)
* Increase tests coverage for bidder-specific tmax
1 parent 716a139 commit 08187ba

File tree

1 file changed

+99
-12
lines changed

1 file changed

+99
-12
lines changed

src/test/groovy/org/prebid/server/functional/tests/TimeoutSpec.groovy

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ class TimeoutSpec extends BaseSpec {
1616

1717
private static final int DEFAULT_TIMEOUT = getRandomTimeout()
1818
private static final int MIN_TIMEOUT = PBSUtils.getRandomNumber(50, 150)
19-
private static final Map PBS_CONFIG = ["auction.biddertmax.max" : MAX_TIMEOUT as String,
20-
"auction.biddertmax.min" : MIN_TIMEOUT as String]
19+
private static final Long MAX_AUCTION_BIDDER_TIMEOUT = 3000
20+
private static final Long MIN_AUCTION_BIDDER_TIMEOUT = 1000
21+
private static final Map PBS_CONFIG = ["auction.biddertmax.max": MAX_AUCTION_BIDDER_TIMEOUT as String,
22+
"auction.biddertmax.min": MIN_AUCTION_BIDDER_TIMEOUT as String]
2123

2224
@Shared
2325
PrebidServerService prebidServerService = pbsServiceFactory.getService(PBS_CONFIG)
@@ -136,9 +138,10 @@ class TimeoutSpec extends BaseSpec {
136138

137139
and: "Pbs config with default request"
138140
def pbsContainer = new PrebidServerContainer(
139-
["default-request.file.path" : APP_WORKDIR + defaultRequest.fileName,
140-
"auction.biddertmax.max" : MAX_TIMEOUT as String]).tap {
141-
withCopyFileToContainer(MountableFile.forHostPath(defaultRequest), APP_WORKDIR) }
141+
["default-request.file.path": APP_WORKDIR + defaultRequest.fileName,
142+
"auction.biddertmax.max" : MAX_TIMEOUT as String]).tap {
143+
withCopyFileToContainer(MountableFile.forHostPath(defaultRequest), APP_WORKDIR)
144+
}
142145
pbsContainer.start()
143146
def pbsService = new PrebidServerService(pbsContainer)
144147

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

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

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

322329
then: "Bidder request should contain percent of request value"
323330
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
324-
assert isInternalProcessingTime(bidderRequest.tmax, getPercentOfValue(percent,timeout))
331+
assert isInternalProcessingTime(bidderRequest.tmax, getPercentOfValue(percent, timeout))
325332

326333
and: "PBS response should contain tmax from request"
327334
assert bidResponse?.ext?.tmaxrequest == timeout as Long
335+
336+
cleanup: "Stop and remove pbs container"
337+
pbsServiceFactory.removeContainer(pbsConfig)
338+
}
339+
340+
def "PBS should apply auction.biddertmax.max timeout when adapters.generic.tmax-deduction-ms exceeds valid top range"() {
341+
given: "PBS config with adapters.generic.tmax-deduction-ms"
342+
def pbsConfig = PBS_CONFIG + ["adapters.generic.tmax-deduction-ms": PBSUtils.getRandomNumber(MAX_AUCTION_BIDDER_TIMEOUT as int) as String]
343+
def prebidServerService = pbsServiceFactory.getService(pbsConfig)
344+
345+
and: "Default basic BidRequest with generic bidder"
346+
def bidRequest = BidRequest.defaultBidRequest.tap {
347+
tmax = randomTimeout
348+
}
349+
350+
when: "PBS processes auction request"
351+
def bidResponse = prebidServerService.sendAuctionRequest(bidRequest)
352+
353+
then: "Bidder request should contain min"
354+
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
355+
assert bidderRequest.tmax == MIN_AUCTION_BIDDER_TIMEOUT
356+
357+
and: "PBS response should contain tmax"
358+
assert bidResponse?.ext?.tmaxrequest == MAX_AUCTION_BIDDER_TIMEOUT
359+
360+
cleanup: "Stop and remove pbs container"
361+
pbsServiceFactory.removeContainer(pbsConfig)
362+
}
363+
364+
def "PBS should resolve timeout as usual when adapters.generic.tmax-deduction-ms specifies zero"() {
365+
given: "PBS config with adapters.generic.tmax-deduction-ms"
366+
def pbsConfig = ["adapters.generic.tmax-deduction-ms": "0"] + PBS_CONFIG
367+
def prebidServerService = pbsServiceFactory.getService(pbsConfig)
368+
369+
and: "Default basic BidRequest with generic bidder"
370+
def timeout = PBSUtils.getRandomNumber(
371+
MIN_AUCTION_BIDDER_TIMEOUT as int,
372+
MAX_AUCTION_BIDDER_TIMEOUT as int)
373+
def bidRequest = BidRequest.defaultBidRequest.tap {
374+
tmax = timeout
375+
}
376+
377+
when: "PBS processes auction request"
378+
def bidResponse = prebidServerService.sendAuctionRequest(bidRequest)
379+
380+
then: "Bidder request should contain right value in tmax"
381+
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
382+
assert isInternalProcessingTime(bidderRequest.tmax, timeout)
383+
384+
and: "PBS response should contain tmax"
385+
assert bidResponse?.ext?.tmaxrequest == timeout as Long
386+
387+
cleanup: "Stop and remove pbs container"
388+
pbsServiceFactory.removeContainer(pbsConfig)
389+
}
390+
391+
def "PBS should properly resolve tmax deduction ms when adapters.generic.tmax-deduction-ms specified"() {
392+
given: "PBS config with adapters.generic.tmax-deduction-ms"
393+
def genericDeductionMs = PBSUtils.getRandomNumber(100, 300)
394+
def randomTimeout = PBSUtils.getRandomNumber(MIN_AUCTION_BIDDER_TIMEOUT + genericDeductionMs as int, MAX_AUCTION_BIDDER_TIMEOUT as int)
395+
def pbsConfig = PBS_CONFIG + ["adapters.generic.tmax-deduction-ms": genericDeductionMs as String]
396+
def prebidServerService = pbsServiceFactory.getService(pbsConfig)
397+
398+
and: "Default basic BidRequest with generic bidder"
399+
def bidRequest = BidRequest.defaultBidRequest.tap {
400+
tmax = randomTimeout
401+
}
402+
403+
when: "PBS processes auction request"
404+
def bidResponse = prebidServerService.sendAuctionRequest(bidRequest)
405+
406+
then: "Bidder request should contain right value in tmax"
407+
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
408+
assert isInternalProcessingTime(bidderRequest.tmax, randomTimeout)
409+
410+
and: "PBS response should contain tmax"
411+
assert bidResponse?.ext?.tmaxrequest == randomTimeout as Long
412+
413+
cleanup: "Stop and remove pbs container"
414+
pbsServiceFactory.removeContainer(pbsConfig)
328415
}
329416

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

334-
private static boolean isInternalProcessingTime(long bidderRequestTimeout, long requestTimeout){
421+
private static boolean isInternalProcessingTime(long bidderRequestTimeout, long requestTimeout) {
335422
0 < requestTimeout - bidderRequestTimeout
336423
}
337424
}

0 commit comments

Comments
 (0)