From 05e35f57feb836d093b5995f84183c24d8a33891 Mon Sep 17 00:00:00 2001 From: mtuchkova Date: Thu, 11 Nov 2021 20:34:32 +0200 Subject: [PATCH] fix after review --- .../groovy/org/prebid/server/functional/AmpSpec.groovy | 5 ----- .../org/prebid/server/functional/AuctionSpec.groovy | 10 +++++----- .../org/prebid/server/functional/BaseSpec.groovy | 5 +++++ .../org/prebid/server/functional/CookieSyncSpec.groovy | 1 + .../org/prebid/server/functional/EventSpec.groovy | 1 + .../org/prebid/server/functional/SetuidSpec.groovy | 1 + .../org/prebid/server/functional/VtrackSpec.groovy | 1 + .../functional/service/PrebidServerService.groovy | 2 +- 8 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/test/groovy/org/prebid/server/functional/AmpSpec.groovy b/src/test/groovy/org/prebid/server/functional/AmpSpec.groovy index e306f0801f0..9cac8224eb1 100644 --- a/src/test/groovy/org/prebid/server/functional/AmpSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/AmpSpec.groovy @@ -4,7 +4,6 @@ import org.prebid.server.functional.model.db.StoredRequest import org.prebid.server.functional.model.request.amp.AmpRequest import org.prebid.server.functional.model.request.auction.BidRequest import org.prebid.server.functional.service.PrebidServerService -import org.prebid.server.functional.util.PBSUtils import spock.lang.Shared import spock.lang.Unroll @@ -145,8 +144,4 @@ class AmpSpec extends BaseSpec { AmpRequest.defaultAmpRequest || "valid AMP request" new AmpRequest() || "invalid AMP request" } - - private static int getRandomTimeout() { - PBSUtils.getRandomNumber(MIN_TIMEOUT, MAX_TIMEOUT) - } } diff --git a/src/test/groovy/org/prebid/server/functional/AuctionSpec.groovy b/src/test/groovy/org/prebid/server/functional/AuctionSpec.groovy index 91e892defbe..6e10a245f74 100644 --- a/src/test/groovy/org/prebid/server/functional/AuctionSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/AuctionSpec.groovy @@ -12,9 +12,9 @@ import static org.prebid.server.functional.util.SystemProperties.PBS_VERSION class AuctionSpec extends BaseSpec { - private static final int MAX_TIMEOUT = 5000 - private static final int DEFAULT_TIMEOUT = PBSUtils.getRandomNumber(1000, MAX_TIMEOUT) + private static final int DEFAULT_TIMEOUT = getRandomTimeout() private static final String PBS_VERSION_HEADER = "pbs-java/$PBS_VERSION" + @Shared PrebidServerService prebidServerService = pbsServiceFactory.getService(["auction.max-timeout-ms" : MAX_TIMEOUT as String, "auction.default-timeout-ms": DEFAULT_TIMEOUT as String]) @@ -42,7 +42,7 @@ class AuctionSpec extends BaseSpec { } and: "Default stored request with timeout" - def timeout = PBSUtils.getRandomNumber(0, MAX_TIMEOUT) + def timeout = getRandomTimeout() def storedRequestModel = BidRequest.defaultStoredRequest.tap { tmax = timeout } @@ -62,7 +62,7 @@ class AuctionSpec extends BaseSpec { @Unroll def "PBS should prefer timeout from the auction request when stored request timeout is #tmax"() { given: "Default basic BidRequest with generic bidder" - def timeout = PBSUtils.getRandomNumber(0, MAX_TIMEOUT) + def timeout = getRandomTimeout() def bidRequest = BidRequest.defaultBidRequest.tap { tmax = timeout ext.prebid.storedRequest = new PrebidStoredRequest(id: PBSUtils.randomNumber.toString()) @@ -85,7 +85,7 @@ class AuctionSpec extends BaseSpec { assert bidderRequest.tmax == timeout as Long where: - tmaxStoredRequest << [null, PBSUtils.getRandomNumber(0, MAX_TIMEOUT)] + tmaxStoredRequest << [null, getRandomTimeout()] } @Unroll diff --git a/src/test/groovy/org/prebid/server/functional/BaseSpec.groovy b/src/test/groovy/org/prebid/server/functional/BaseSpec.groovy index f929121adcb..6007c8e80c9 100644 --- a/src/test/groovy/org/prebid/server/functional/BaseSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/BaseSpec.groovy @@ -12,6 +12,7 @@ import org.prebid.server.functional.testcontainers.PbsServiceFactory import org.prebid.server.functional.testcontainers.scaffolding.Bidder import org.prebid.server.functional.testcontainers.scaffolding.PrebidCache import org.prebid.server.functional.util.ObjectMapperWrapper +import org.prebid.server.functional.util.PBSUtils import spock.lang.Specification import static org.prebid.server.functional.testcontainers.Dependencies.mysqlContainer @@ -48,4 +49,8 @@ abstract class BaseSpec extends Specification { repository.removeAllDatabaseData() pbsServiceFactory.stopContainers() } + + protected static int getRandomTimeout() { + PBSUtils.getRandomNumber(MIN_TIMEOUT, MAX_TIMEOUT) + } } diff --git a/src/test/groovy/org/prebid/server/functional/CookieSyncSpec.groovy b/src/test/groovy/org/prebid/server/functional/CookieSyncSpec.groovy index 8241dd30121..7ea2af2844d 100644 --- a/src/test/groovy/org/prebid/server/functional/CookieSyncSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/CookieSyncSpec.groovy @@ -12,6 +12,7 @@ class CookieSyncSpec extends BaseSpec { @PendingFeature def "PBS should return an error for cookie_sync request when the timeout time is exceeded"() { given: "PBS with timeout configuration" + // Using minimal allowed time for timeout (1ms) to get timeout error. def pbsService = pbsServiceFactory.getService(["cookie-sync.default-timeout-ms": "1"]) and: "Default CookieSyncRequest with account" diff --git a/src/test/groovy/org/prebid/server/functional/EventSpec.groovy b/src/test/groovy/org/prebid/server/functional/EventSpec.groovy index 77fd156b6e1..03865692155 100644 --- a/src/test/groovy/org/prebid/server/functional/EventSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/EventSpec.groovy @@ -8,6 +8,7 @@ class EventSpec extends BaseSpec { def "PBS should return an error for event request when the timeout time is exceeded"() { given: "PBS with timeout configuration" + // Using minimal allowed time for timeout (1ms) to get timeout error. def pbsService = pbsServiceFactory.getService(["event.default-timeout-ms": "1"]) and: "Default EventRequest" diff --git a/src/test/groovy/org/prebid/server/functional/SetuidSpec.groovy b/src/test/groovy/org/prebid/server/functional/SetuidSpec.groovy index 7e8b96f98c1..b5793fc4f9b 100644 --- a/src/test/groovy/org/prebid/server/functional/SetuidSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/SetuidSpec.groovy @@ -12,6 +12,7 @@ class SetuidSpec extends BaseSpec { @PendingFeature def "PBS should return an error for setuid request when the timeout time is exceeded"() { given: "PBS with timeout configuration" + // Using minimal allowed time for timeout (1ms) to get timeout error. def pbsService = pbsServiceFactory.getService(["setuid.default-timeout-ms": "1"]) and: "Default setuid request with account" diff --git a/src/test/groovy/org/prebid/server/functional/VtrackSpec.groovy b/src/test/groovy/org/prebid/server/functional/VtrackSpec.groovy index 3192fcaf638..bfb2200bed0 100644 --- a/src/test/groovy/org/prebid/server/functional/VtrackSpec.groovy +++ b/src/test/groovy/org/prebid/server/functional/VtrackSpec.groovy @@ -9,6 +9,7 @@ class VtrackSpec extends BaseSpec { def "PBS should return an error for vtrack request when the timeout time is exceeded"() { given: "PBS with timeout configuration" + // Using minimal allowed time for timeout (1ms) to get timeout error. def pbsService = pbsServiceFactory.getService(["vtrack.default-timeout-ms": "1"]) and: "Default VtrackRequest" diff --git a/src/test/groovy/org/prebid/server/functional/service/PrebidServerService.groovy b/src/test/groovy/org/prebid/server/functional/service/PrebidServerService.groovy index 3b0c133c17c..80b533a5dc2 100644 --- a/src/test/groovy/org/prebid/server/functional/service/PrebidServerService.groovy +++ b/src/test/groovy/org/prebid/server/functional/service/PrebidServerService.groovy @@ -282,7 +282,7 @@ class PrebidServerService { if (uids) { return mapper.decode(new String(Base64.urlDecoder.decode(uids)), UidsCookie) } else { - throw new IllegalStateException() + throw new IllegalStateException("uids cookie is missing in response") } }