From 524c2add68898f518852bc4e4d3775f780417dee Mon Sep 17 00:00:00 2001 From: Jeff Mahoney Date: Mon, 3 Jun 2024 12:51:50 -0400 Subject: [PATCH] PBS adapter: add tmaxmax (#11540) * Update logic to determine tmax * Update the logic in `ortbConverter.js` so that if a publisher specifies `tmaxmax` as a part of their setup (i.e. specifies it in their `setConfig()` call), `tmaxmax` is what is used to determine `tmax` for a request. * Update tmaxmax logic and test * Update `request()` method in ortbConverter.js to properly account for fact that tmaxmax is actually now a new available property off of the ext property. * Update unit test to verify that when a publisher specifies a tmaxmax value in the config setup, it will be honored. * Use requestBidsTimeout for tmaxmax alternative * Update ortbConverter logic so that `requestBidsTimeout` is the alternative value when `tmaxmax` is not available. * Update prebidServerBidAdapter_spec.js * Add a test to verify that fallback for `tmaxmax` is `requestBidsTimeout`. --- .../prebidServerBidAdapter/ortbConverter.js | 1 + src/adapterManager.js | 2 +- .../modules/prebidServerBidAdapter_spec.js | 38 ++++++++++++++++--- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/modules/prebidServerBidAdapter/ortbConverter.js b/modules/prebidServerBidAdapter/ortbConverter.js index 1ec3eb0ccd0..d445a52dcc6 100644 --- a/modules/prebidServerBidAdapter/ortbConverter.js +++ b/modules/prebidServerBidAdapter/ortbConverter.js @@ -58,6 +58,7 @@ const PBS_CONVERTER = ortbConverter({ const request = buildRequest(imps, proxyBidderRequest, context); request.tmax = s2sBidRequest.s2sConfig.timeout; + request.ext.tmaxmax = request.ext.tmaxmax || context.s2sBidRequest.requestBidsTimeout; [request.app, request.dooh, request.site].forEach(section => { if (section && !section.publisher?.id) { diff --git a/src/adapterManager.js b/src/adapterManager.js index 557f4c1eee4..8228001892d 100644 --- a/src/adapterManager.js +++ b/src/adapterManager.js @@ -420,7 +420,7 @@ adapterManager.callBids = (adUnits, bidRequests, addBidResponse, doneCb, request let uniqueServerRequests = serverBidderRequests.filter(serverBidRequest => serverBidRequest.uniquePbsTid === uniquePbsTid); if (s2sAdapter) { - let s2sBidRequest = {'ad_units': adUnitsS2SCopy, s2sConfig, ortb2Fragments}; + let s2sBidRequest = {'ad_units': adUnitsS2SCopy, s2sConfig, ortb2Fragments, requestBidsTimeout}; if (s2sBidRequest.ad_units.length) { let doneCbs = uniqueServerRequests.map(bidRequest => { bidRequest.start = timestamp(); diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index c6335227202..3b433d34955 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -763,12 +763,40 @@ describe('S2S Adapter', function () { }); }) - it('should set tmax to s2sConfig.timeout', () => { - const cfg = {...CONFIG, timeout: 123}; - config.setConfig({s2sConfig: cfg}); - adapter.callBids({...REQUEST, s2sConfig: cfg}, BID_REQUESTS, addBidResponse, done, ajax); + it('should set tmaxmax correctly when publisher has specified it', () => { + const cfg = {...CONFIG}; + + // publisher has specified a tmaxmax in their setup + const ortb2Fragments = { + global: { + ext: { + tmaxmax: 4242 + } + } + }; + const s2sCfg = {...REQUEST, cfg} + const payloadWithFragments = { ...s2sCfg, ortb2Fragments }; + + adapter.callBids(payloadWithFragments, BID_REQUESTS, addBidResponse, done, ajax); const req = JSON.parse(server.requests[0].requestBody); - expect(req.tmax).to.eql(123); + + expect(req.ext.tmaxmax).to.eql(4242); + }); + + it('should set tmaxmax correctly when publisher has not specified it', () => { + const cfg = {...CONFIG}; + + // publisher has not specified a tmaxmax in their setup - so we should be + // falling back to requestBidsTimeout + const ortb2Fragments = {}; + const s2sCfg = {...REQUEST, cfg}; + const requestBidsTimeout = 808; + const payloadWithFragments = { ...s2sCfg, ortb2Fragments, requestBidsTimeout }; + + adapter.callBids(payloadWithFragments, BID_REQUESTS, addBidResponse, done, ajax); + const req = JSON.parse(server.requests[0].requestBody); + + expect(req.ext.tmaxmax).to.eql(808); }); it('should block request if config did not define p1Consent URL in endpoint object config', function () {