Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

best practice of mocking openrtb2/auction #1409

Closed
StarWindMoonCloud opened this issue Jul 19, 2020 · 5 comments
Closed

best practice of mocking openrtb2/auction #1409

StarWindMoonCloud opened this issue Jul 19, 2020 · 5 comments
Assignees

Comments

@StarWindMoonCloud
Copy link

Reasons

  1. test may not meet the requirement since the behavior of real bid can be different, example The HTML doesn't contain a size object prebid-mobile-android#205
  2. bid rate is usually much smaller than 1, make it time-consuming to reproduce

seems mock is not straightforward to achieve, please help suggest

@bretg
Copy link
Contributor

bretg commented Jul 20, 2020

If you're running your own PBS-Java, you can make use of the StoredResponse feature. It's cool. #861 - I just recently confirmed that you can refer to a stored response ID inside of a stored request. Even more cool for mobile scenarios. Will get that documented at some point.

If running your own PBS-Go, you'll have to change the bidders endpoint to a stub of some sort -- a simple local sever or a stupid script like this one I've used for performance testing, with your desired response of course:

// mock_rubicon.go
package main

import (
	"flag"
	"fmt"
	"math/rand"
	"net/http"
	"time"
)

// mock ad engine that sleeps for a random amount of time, then
// responds with the JSON string.

var Port = flag.Int("listen-port", 8000, "Web server port")

var payload = []byte(`{"id":"ddf4459c-6794-43e7-8ebb-6d0b7fcc63b4", "bidid":"6e1ea14c-b7bf-4a10-a02d-4c3d57bb4171", "seatbid":[{"bid":[{"id":"0", "impid":"gdm-ad-300x250-A", "price":1.000000, "adm":"    <script type=\"text/javascript\">n      rubicon_cb = Math.random(); rubicon_rurl = document.referrer; if(top.location==document.location){rubicon_rurl = document.location;} rubicon_rurl = escape(rubicon_rurl);\n      window.rubicon_ad = \"4052144\" + \".\" + \"js\";\n      window.rubicon_creative = \"4425920\" + \".\" + \"js\";\n    </script>\n<div style=\"width: 0; height: 0; overflow: hidden;\"><img border=\"0\" width=\"1\" height=\"1\" src=\"https://beacon-us-iad2.rubiconproject.com/beacon/d/6e1ea14c-b7bf-4a10-a02d-4c3d57bb4171?accountId=13140&siteId=108650&zoneId=511134&e=6A1E40E384DA563B5FF18EBBB94086D83AB681FB81EB8228D0DF9DC45DC20868E85BFD3F4C38C95AEFAA7EE2800BA937C01CF708F38D62A34CEF457B1D5E1B08140455211413C4A5E8B7B866D5D2EF35048FDCA4C7453D08A4C5C8DAD5FE4F41FAB3135B8AA9C2E341133516DD756267D9B3D14FDEBC207A8855AB92CA40AE1E11D296B45B7F031CFDC7548137E43A7467B075A8B3FAC811\" alt=\"\" /></div>\n\n\n<SCRIPT SRC=\"http://select.brealtime.com/ttj?id=9278396&size=300x250\" TYPE=\"text/javascript\"></SCRIPT><div style=\"height:0px;width:0px;overflow:hidden\"><script>(function(){document.write('<iframe src=\"https://tap2-cdn.rubiconproject.com/partner/scripts/rubicon/emily.html?pc=13140/108650&geo=na&co=us\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"NO\" width=\"0\" height=\"0\" style=\"height:0px;width:0px\"></iframe>');})();</script></div>", "crid":"4425920", "w":300, "h":250, "ext":{"rp":{"mime":"text/html","size_id":15, "targeting":[{"key":"rpfl_1001","values":["15_tier0100"]}]}}}]}], "statuscode":0}`)

// sleep interval is approximately normally distributed:
// 40ms - 200ms
// == 160ms

// mean is 120 (ms)
// P(120-3*s <= x <= 120+3*s) == 0.9973
// 120-3*s == 40, 120+3*s == 200
// 3*s = 120-40 = 80, s = 26.666
func handler(w http.ResponseWriter, r *http.Request) {
	t := time.Duration(1000*(rand.NormFloat64()*26.6666+120.0)) * time.Microsecond
	time.Sleep(t)
	w.Header().Set("Content-Type", "application/javascript")
	w.Write(payload)
}

func main() {
	flag.Parse()

	http.HandleFunc("/", handler)
	listen_addr := fmt.Sprintf(":%d", *Port)
	http.ListenAndServe(listen_addr, nil)
}

@bretg bretg added the question label Jul 20, 2020
@bretg bretg self-assigned this Jul 20, 2020
@StarWindMoonCloud
Copy link
Author

Thank you @bretg , this is of course doable for now, looking forward to the StoredResponse feature, makes life eaiser

@StarWindMoonCloud
Copy link
Author

One bad thing about mock this way is that account id and config id are not handled which will result in PREBID_SERVER_ERROR

@bretg
Copy link
Contributor

bretg commented Aug 3, 2020

account id and config id are not handled

If your mock script was slightly smarter, it could handle whatever you needed

e.g. the mock script could parse the incoming request, grab the account ID, and echo it in the response.

The config ID (assuming you mean stored request ID here) should be supported within PBS before calling the mocked endpoint. If there are params in the request that are dynamic (like account ID), the mock can look for them and respond appropriately.

@stale
Copy link

stale bot commented Sep 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants