Skip to content

Commit

Permalink
Timeout tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtuchkova committed Nov 9, 2021
1 parent 78b12ff commit 5494da3
Show file tree
Hide file tree
Showing 18 changed files with 303 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class AmpSpec extends BaseSpec {
}

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getDbStoredRequest(ampRequest, ampStoredRequest)
def storedRequest = StoredRequest.getAmpDbStoredRequest(ampRequest, ampStoredRequest)
storedRequestDao.save(storedRequest)

when: "PBS processes amp request"
Expand Down
121 changes: 119 additions & 2 deletions src/test/groovy/org/prebid/server/functional/AuctionSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package org.prebid.server.functional

import org.prebid.server.functional.model.db.StoredRequest
import org.prebid.server.functional.model.request.auction.BidRequest
import org.prebid.server.functional.model.request.auction.StoredRequestExt
import org.prebid.server.functional.service.PrebidServerService
import org.prebid.server.functional.util.PBSUtils
import spock.lang.Shared
import spock.lang.Unroll

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 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])

@Unroll
def "PBS should return version in response header for auction request for #description"() {
Expand All @@ -23,4 +31,113 @@ class AuctionSpec extends BaseSpec {
BidRequest.defaultBidRequest || "valid bid request"
new BidRequest() || "invalid bid request"
}

def "PBS should apply timeout from stored request when it's not specified in the auction request"() {
given: "Default basic BidRequest with generic bidder"
def bidRequest = BidRequest.defaultBidRequest.tap {
tmax = null
ext.prebid.storedRequest = new StoredRequestExt(id: PBSUtils.randomNumber.toString())
}

and: "Default stored request with timeout"
def timeout = PBSUtils.getRandomNumber(0, MAX_TIMEOUT)
def storedRequestModel = BidRequest.defaultStoredRequest.tap {
tmax = timeout
}

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getAuctionDbStoredRequest(bidRequest, storedRequestModel)
storedRequestDao.save(storedRequest)

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

then: "Bidder request should contain timeout from the stored request"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert bidderRequest.tmax == timeout as Long
}

@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 bidRequest = BidRequest.defaultBidRequest.tap {
tmax = timeout
ext.prebid.storedRequest = new StoredRequestExt(id: PBSUtils.randomNumber.toString())
}

and: "Default stored request"
def storedRequestModel = BidRequest.defaultStoredRequest.tap {
it.tmax = tmaxStoredRequest
}

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getAuctionDbStoredRequest(bidRequest, storedRequestModel)
storedRequestDao.save(storedRequest)

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

then: "Bidder request should contain timeout from the request"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert bidderRequest.tmax == timeout as Long

where:
tmaxStoredRequest << [null, PBSUtils.getRandomNumber(0, MAX_TIMEOUT)]
}

@Unroll
def "PBS should honor max timeout from the settings for auction request"() {
given: "Default basic BidRequest with generic bidder"
def bidRequest = BidRequest.defaultBidRequest.tap {
tmax = autcionRequestTimeout
ext.prebid.storedRequest = new StoredRequestExt(id: PBSUtils.randomNumber.toString())
}

and: "Default stored request"
def storedRequest = BidRequest.defaultStoredRequest.tap {
it.tmax = storedRequestTimeout
}

and: "Save storedRequest into DB"
def storedRequestModel = StoredRequest.getAuctionDbStoredRequest(bidRequest, storedRequest)
storedRequestDao.save(storedRequestModel)

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

then: "Bidder request timeout should correspond to the maximum from the settings"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert bidderRequest.tmax == MAX_TIMEOUT as Long

where:
autcionRequestTimeout || storedRequestTimeout
MAX_TIMEOUT + 1 || null
null || MAX_TIMEOUT + 1
MAX_TIMEOUT + 1 || MAX_TIMEOUT + 1
}

def "PBS should honor default timeout for auction request"() {
given: "Default basic BidRequest without timeout"
def bidRequest = BidRequest.defaultBidRequest.tap {
tmax = null
ext.prebid.storedRequest = new StoredRequestExt(id: PBSUtils.randomNumber.toString())
}

and: "Default stored request without timeout"
def storedRequest = BidRequest.defaultStoredRequest.tap {
it.tmax = null
}

and: "Save storedRequest into DB"
def storedRequestModel = StoredRequest.getAuctionDbStoredRequest(bidRequest, storedRequest)
storedRequestDao.save(storedRequestModel)

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

then: "Bidder request timeout should correspond to the maximum from the settings"
def bidderRequest = bidder.getBidderRequest(bidRequest.id)
assert bidderRequest.tmax == DEFAULT_TIMEOUT as Long
}
}
34 changes: 34 additions & 0 deletions src/test/groovy/org/prebid/server/functional/CookieSyncSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.prebid.server.functional

import org.prebid.server.functional.model.UidsCookie
import org.prebid.server.functional.model.db.Account
import org.prebid.server.functional.model.request.cookiesync.CookieSyncRequest
import org.prebid.server.functional.service.PrebidServerException
import org.prebid.server.functional.util.PBSUtils
import spock.lang.PendingFeature

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"
def pbsService = pbsServiceFactory.getService(["cookie-sync.default-timeout-ms": "1"])

and: "Default CookieSyncRequest with account"
def cookieSyncRequest = CookieSyncRequest.defaultCookieSyncRequest
cookieSyncRequest.account = PBSUtils.randomNumber.toString()
def uidsCookie = UidsCookie.defaultUidsCookie

and: "Account in the DB"
def account = new Account(uuid: cookieSyncRequest.account, eventsEnabled: true)
accountDao.save(account)

when: "PBS processes cookie sync request"
pbsService.sendCookieSyncRequest(cookieSyncRequest, uidsCookie)

then: "Request should fail with error"
def exception = thrown(PrebidServerException)
assert exception.statusCode == 500
assert exception.responseBody.contains("Timed out while executing SQL query")
}
}
4 changes: 2 additions & 2 deletions src/test/groovy/org/prebid/server/functional/DebugSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class DebugSpec extends BaseSpec {
}

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getDbStoredRequest(ampRequest, ampStoredRequest)
def storedRequest = StoredRequest.getAmpDbStoredRequest(ampRequest, ampStoredRequest)
storedRequestDao.save(storedRequest)

when: "PBS processes amp request"
Expand Down Expand Up @@ -292,7 +292,7 @@ class DebugSpec extends BaseSpec {
}

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getDbStoredRequest(ampRequest, ampStoredRequest)
def storedRequest = StoredRequest.getAmpDbStoredRequest(ampRequest, ampStoredRequest)
storedRequestDao.save(storedRequest)

when: "PBS processes amp request"
Expand Down
28 changes: 28 additions & 0 deletions src/test/groovy/org/prebid/server/functional/EventSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.prebid.server.functional

import org.prebid.server.functional.model.db.Account
import org.prebid.server.functional.model.request.event.EventRequest
import org.prebid.server.functional.service.PrebidServerException

class EventSpec extends BaseSpec {

def "PBS should return an error for event request when the timeout time is exceeded"() {
given: "PBS with timeout configuration"
def pbsService = pbsServiceFactory.getService(["event.default-timeout-ms": "1"])

and: "Default EventRequest"
def eventRequest = EventRequest.defaultEventRequest

and: "Account in the DB"
def account = new Account(uuid: eventRequest.accountId, eventsEnabled: true)
accountDao.save(account)

when: "PBS processes event request"
pbsService.sendEventRequest(eventRequest)

then: "Request should fail with error"
def exception = thrown(PrebidServerException)
assert exception.statusCode == 500
assert exception.responseBody.contains("Timed out while executing SQL query")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.prebid.server.functional.model.request.amp.AmpRequest
import org.prebid.server.functional.model.request.auction.BidRequest
import org.prebid.server.functional.model.request.event.EventRequest
import org.prebid.server.functional.model.request.setuid.SetuidRequest
import org.prebid.server.functional.model.request.setuid.UidsCookie
import org.prebid.server.functional.model.UidsCookie
import org.prebid.server.functional.model.request.vtrack.VtrackRequest
import org.prebid.server.functional.model.request.vtrack.xml.Vast
import org.prebid.server.functional.service.PrebidServerException
Expand Down Expand Up @@ -63,7 +63,7 @@ class HttpSettingsSpec extends BaseSpec {
ampStoredRequest.regs.ext.gdpr = 1

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getDbStoredRequest(ampRequest, ampStoredRequest)
def storedRequest = StoredRequest.getAmpDbStoredRequest(ampRequest, ampStoredRequest)
storedRequestDao.save(storedRequest)

and: "Prepare default account response with gdpr = 0"
Expand Down Expand Up @@ -117,8 +117,10 @@ class HttpSettingsSpec extends BaseSpec {
def response = prebidServerService.sendSetUidRequest(request, uidsCookie)

then: "Response should contain uids cookie"
assert response.uidsCookie
assert !response.responseBody?.isEmpty()
assert response.uidsCookie.bday
assert !response.uidsCookie.tempUIDs
assert !response.uidsCookie.uids
assert response.responseBody == ResourceUtil.readByteArrayFromClassPath("org/prebid/server/functional/tracking-pixel.png")

and: "There should be only one account request"
assert httpSettings.getRequestCount(request.account) == 1
Expand Down
35 changes: 35 additions & 0 deletions src/test/groovy/org/prebid/server/functional/SetuidSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.prebid.server.functional

import org.prebid.server.functional.model.UidsCookie
import org.prebid.server.functional.model.db.Account
import org.prebid.server.functional.model.request.setuid.SetuidRequest
import org.prebid.server.functional.service.PrebidServerException
import org.prebid.server.functional.util.PBSUtils
import spock.lang.PendingFeature

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"
def pbsService = pbsServiceFactory.getService(["setuid.default-timeout-ms": "1"])

and: "Default setuid request with account"
def request = SetuidRequest.defaultSetuidRequest
def uidsCookie = UidsCookie.defaultUidsCookie
request.account = PBSUtils.randomNumber.toString()

and: "Account in the DB"
def account = new Account(uuid: request.account, eventsEnabled: true)
accountDao.save(account)

when: "PBS processes setuid request"
pbsService.sendSetUidRequest(request, uidsCookie)

then: "Request should fail with error"
def exception = thrown(PrebidServerException)
assert exception.statusCode == 500
assert exception.responseBody.contains("Timed out while executing SQL query")

}
}
11 changes: 7 additions & 4 deletions src/test/groovy/org/prebid/server/functional/SmokeSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.prebid.server.functional.model.request.cookiesync.CookieSyncRequest
import org.prebid.server.functional.model.request.event.EventRequest
import org.prebid.server.functional.model.request.logging.httpinteraction.HttpInteractionRequest
import org.prebid.server.functional.model.request.setuid.SetuidRequest
import org.prebid.server.functional.model.request.setuid.UidsCookie
import org.prebid.server.functional.model.UidsCookie
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.cookiesync.CookieSyncResponse
Expand Down Expand Up @@ -52,7 +52,7 @@ class SmokeSpec extends BaseSpec {
ampStoredRequest.site.publisher.id = ampRequest.account

and: "Save storedRequest into DB"
def storedRequest = StoredRequest.getDbStoredRequest(ampRequest, ampStoredRequest)
def storedRequest = StoredRequest.getAmpDbStoredRequest(ampRequest, ampStoredRequest)
storedRequestDao.save(storedRequest)

when: "PBS processes amp request"
Expand Down Expand Up @@ -107,8 +107,11 @@ class SmokeSpec extends BaseSpec {
def response = defaultPbsService.sendSetUidRequest(request, uidsCookie)

then: "Response should contain uids cookie"
assert response.uidsCookie
assert !response.responseBody?.isEmpty()
assert response.uidsCookie.bday
assert !response.uidsCookie.tempUIDs
assert !response.uidsCookie.uids
assert response.responseBody ==
ResourceUtil.readByteArrayFromClassPath("org/prebid/server/functional/tracking-pixel.png")
}

def "PBS should get uids cookie"() {
Expand Down
27 changes: 27 additions & 0 deletions src/test/groovy/org/prebid/server/functional/VtrackSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.prebid.server.functional

import org.prebid.server.functional.model.request.vtrack.VtrackRequest
import org.prebid.server.functional.model.request.vtrack.xml.Vast
import org.prebid.server.functional.service.PrebidServerException
import org.prebid.server.functional.util.PBSUtils

class VtrackSpec extends BaseSpec {

def "PBS should return an error for vtrack request when the timeout time is exceeded"() {
given: "PBS with timeout configuration"
def pbsService = pbsServiceFactory.getService(["vtrack.default-timeout-ms": "1"])

and: "Default VtrackRequest"
def payload = PBSUtils.randomNumber.toString()
def request = VtrackRequest.getDefaultVtrackRequest(mapper.encodeXml(Vast.getDefaultVastModel(payload)))
def accountId = PBSUtils.randomNumber.toString()

when: "PBS processes vtrack request"
pbsService.sendVtrackRequest(request, accountId)

then: "Request should fail with error"
def exception = thrown(PrebidServerException)
assert exception.statusCode == 500
assert exception.responseBody.contains("Timed out while executing SQL query")
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.prebid.server.functional.model.request.setuid
package org.prebid.server.functional.model

import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import groovy.transform.ToString
import org.prebid.server.functional.model.request.setuid.UidWithExpiry
import org.prebid.server.functional.model.response.setuid.ZonedDateTimeDeserializer

import java.time.Clock
import java.time.ZonedDateTime
Expand All @@ -13,6 +16,7 @@ class UidsCookie {
Map<String, UidWithExpiry> tempUIDs
Boolean optout
@JsonFormat(pattern = "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'", timezone = "UTC")
@JsonDeserialize(using = ZonedDateTimeDeserializer)
ZonedDateTime bday

static UidsCookie getDefaultUidsCookie() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ class StoredRequest {
@Convert(converter = StoredRequestConfigTypeConverter)
BidRequest requestData

static StoredRequest getDbStoredRequest(AmpRequest ampRequest, BidRequest bidRequest) {
static StoredRequest getAmpDbStoredRequest(AmpRequest ampRequest, BidRequest bidRequest) {
new StoredRequest(reqid: ampRequest.tagId, accountId: ampRequest.account, requestData: bidRequest)
}

static StoredRequest getAuctionDbStoredRequest(BidRequest bidRequest, BidRequest storedRequest) {
new StoredRequest(reqid: bidRequest.ext.prebid.storedRequest.id, accountId: bidRequest.site.publisher.id,
requestData: storedRequest)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Prebid {
Integer debug
Targeting targeting
PrebidCache cache
StoredRequest storedRequest
StoredRequestExt storedRequest
Amp amp
Channel channel
List<PrebidSchain> schains
Expand Down
Loading

0 comments on commit 5494da3

Please sign in to comment.