Skip to content

Instantly share code, notes, and snippets.

@hungry
Last active August 31, 2017 15:25
Show Gist options
  • Select an option

  • Save hungry/98e69ffcd5911ef84413ed9211c6440f to your computer and use it in GitHub Desktop.

Select an option

Save hungry/98e69ffcd5911ef84413ed9211c6440f to your computer and use it in GitHub Desktop.
import logging
import requests
from simplejson import dumps
from hashlib import sha512
log = logging.getLogger(__name__)
class LoadTest(object):
def __init__(self, gun):
self.gun = gun
self.base_address = gun.get_option("base_address")
def shoot(self, marker, missile):
log.debug("Missile: %s\n%s", marker, missile)
secret_key = '...'
json = dumps({"key": "value"})
m = sha512()
m.update(json + secret_key)
headers = {
"Authorization": m.hexdigest()
}
log.debug("Request headers: %s", headers)
log.debug("Request body: %s", json)
with self.gun.measure(marker + "_init") as di:
try:
r = requests.post(self.base_address, data=json, headers=headers)
di["proto_code"] = r.status_code
except requests.ConnectionError:
log.debug("Connection error", exc_info=True)
di["net_code"] = 1
di["proto_code"] = 500
def case1(self, missile):
self.shoot("case1", missile)
def setup(self, param):
log.info("Setting up LoadTest")
def teardown(self):
log.info("Tearing down LoadTest")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment