зеркало из https://github.com/mozilla/sauropod.git
Refactoring the funkload test
This commit is contained in:
Родитель
11cb869819
Коммит
6bfddc7569
|
@ -17,12 +17,12 @@ port 8001 for use by the tests::
|
||||||
Confirm that your setup is working by running a single instance of the test
|
Confirm that your setup is working by running a single instance of the test
|
||||||
suite::
|
suite::
|
||||||
|
|
||||||
fl-run-test test_simple.py
|
fl-run-test test_sauropod.py
|
||||||
|
|
||||||
Then you can run the loadtest by doing::
|
Then you can run the loadtest by doing::
|
||||||
|
|
||||||
fl-run-bench test_simple.py SimpleTest.test_write_and_read_keys
|
fl-run-bench test_sauropod.py SauropodTests.test_write_read_seq
|
||||||
|
|
||||||
And generate some pretty graphs with::
|
And generate some pretty graphs with::
|
||||||
|
|
||||||
fl-build-report --html --output-directory=html simple-bench.xml
|
fl-build-report --html --output-directory=html sauropod-bench.xml
|
||||||
|
|
|
@ -3,24 +3,24 @@
|
||||||
#
|
#
|
||||||
[main]
|
[main]
|
||||||
title=Sauropod Funkload test
|
title=Sauropod Funkload test
|
||||||
description=simple Sauropod API tests
|
description=Simple loadtests for Sauropod HTTP server
|
||||||
|
|
||||||
url=http://localhost:8001
|
url=http://localhost:8001
|
||||||
|
|
||||||
audience = http://sauropod.mozillalabs.com
|
audience = http://sauropod.mozillalabs.com
|
||||||
num_users = 98
|
num_users = 98
|
||||||
num_keys = 20
|
|
||||||
|
|
||||||
[test_write_and_read_keys]
|
[test_write_read_seq]
|
||||||
description=Sequential write of keys, then sequential read
|
description=Sequential write of keys, then sequential read
|
||||||
|
num_keys = 20
|
||||||
|
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
# Generic funkload configurtion
|
# Generic funkload configurtion
|
||||||
#
|
#
|
||||||
[ftest]
|
[ftest]
|
||||||
log_to = console file
|
log_to = console file
|
||||||
log_path = simple-test.log
|
log_path = sauropod-test.log
|
||||||
result_path = simple-test.xml
|
result_path = sauropod-test.xml
|
||||||
sleep_time_min = 0
|
sleep_time_min = 0
|
||||||
sleep_time_max = 0
|
sleep_time_max = 0
|
||||||
|
|
||||||
|
@ -35,6 +35,6 @@ sleep_time = 0.01
|
||||||
cycle_time = 1
|
cycle_time = 1
|
||||||
log_to =
|
log_to =
|
||||||
log_path =
|
log_path =
|
||||||
result_path = simple-bench.xml
|
result_path = sauropod-bench.xml
|
||||||
sleep_time_min = 0
|
sleep_time_min = 0
|
||||||
sleep_time_max = 0.5
|
sleep_time_max = 0.5
|
|
@ -0,0 +1,77 @@
|
||||||
|
import unittest
|
||||||
|
import json
|
||||||
|
import random
|
||||||
|
from urllib import quote as urlquote
|
||||||
|
from urllib import unquote as urlunquote
|
||||||
|
from urlparse import urljoin
|
||||||
|
|
||||||
|
from funkload.FunkLoadTestCase import FunkLoadTestCase
|
||||||
|
from funkload.utils import Data
|
||||||
|
|
||||||
|
|
||||||
|
class SauropodTests(FunkLoadTestCase):
|
||||||
|
"""FunkLoad-based load tests for Sauropod HTTP server."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.root_url = self.conf_get("main", "url")
|
||||||
|
self.audience = self.conf_get("main", "audience")
|
||||||
|
self.num_users = int(self.conf_get("main", "num_users"))
|
||||||
|
self.userid = None
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.userid = None
|
||||||
|
|
||||||
|
def start_session(self, userid=None):
|
||||||
|
if userid is None:
|
||||||
|
userid = "user%d@moz.com" % random.randint(0, self.num_users - 1)
|
||||||
|
params = {"audience": self.audience, "assertion": self.userid}
|
||||||
|
res = self.post(urljoin(self.root_url, "/session/start"),
|
||||||
|
params=params)
|
||||||
|
self.assertEquals(res.code, 200)
|
||||||
|
self.sessionid = res.body
|
||||||
|
self.userid = userid
|
||||||
|
self.setHeader("Signature", self.sessionid)
|
||||||
|
|
||||||
|
def get_keypath(self, key, userid=None, appid=None):
|
||||||
|
if userid is None:
|
||||||
|
userid = self.userid
|
||||||
|
if appid is None:
|
||||||
|
appid = self.audience
|
||||||
|
keypath = urljoin(self.root_url,"/app/%s/users/%s/keys/%s")
|
||||||
|
keypath %= (urlquote(appid, safe=""),
|
||||||
|
urlquote(userid, safe=""),
|
||||||
|
urlquote(key, safe=""))
|
||||||
|
return keypath
|
||||||
|
|
||||||
|
def get_key(self, key, userid=None, appid=None):
|
||||||
|
keypath = self.get_keypath(key, userid, appid)
|
||||||
|
res = self.get(keypath)
|
||||||
|
self.assertEquals(res.code, 200)
|
||||||
|
return json.loads(res.body)["value"]
|
||||||
|
|
||||||
|
def set_key(self, key, value, userid=None, appid=None):
|
||||||
|
keypath = self.get_keypath(key, userid, appid)
|
||||||
|
res = self.put(keypath, params={"value": value})
|
||||||
|
self.assertTrue(200 <= res.code < 300)
|
||||||
|
|
||||||
|
def del_key(self, key, value, userid=None, appid=None):
|
||||||
|
keypath = self.get_keypath(key, userid, appid)
|
||||||
|
params = {"value": "value%d" % (i,)}
|
||||||
|
res = self.delete(keypath)
|
||||||
|
self.assertTrue(200 <= res.code < 300)
|
||||||
|
|
||||||
|
def test_write_read_seq(self):
|
||||||
|
"""Test sequentual writing then reading of keys.
|
||||||
|
|
||||||
|
This test does a simple sequential write of a bunch of keys, then
|
||||||
|
reads them all back in the same order.
|
||||||
|
"""
|
||||||
|
num_keys = int(self.conf_get("test_write_read_seq", "num_keys"))
|
||||||
|
self.start_session()
|
||||||
|
# Write out a bunch of keys.
|
||||||
|
for i in range(num_keys):
|
||||||
|
self.set_key("key%d" % (i,), "value%d" % (i,))
|
||||||
|
# Read all the keys back in.
|
||||||
|
for i in range(num_keys):
|
||||||
|
value = self.get_key("key%d" % (i,))
|
||||||
|
self.assertEquals(value, "value%d" % (i,))
|
|
@ -1,53 +0,0 @@
|
||||||
import unittest
|
|
||||||
import json
|
|
||||||
import random
|
|
||||||
from urllib import quote as urlquote
|
|
||||||
from urllib import unquote as urlunquote
|
|
||||||
from urlparse import urljoin
|
|
||||||
|
|
||||||
from funkload.FunkLoadTestCase import FunkLoadTestCase
|
|
||||||
from funkload.utils import Data
|
|
||||||
|
|
||||||
|
|
||||||
class SimpleTest(FunkLoadTestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.root_url = self.conf_get("main", "url")
|
|
||||||
self.num_users = int(self.conf_get("main", "num_users"))
|
|
||||||
self.num_keys = int(self.conf_get("main", "num_keys"))
|
|
||||||
|
|
||||||
def start_session(self):
|
|
||||||
assertion = "user%d@moz.com" % random.randint(0, self.num_users - 1)
|
|
||||||
audience = self.conf_get("main", "audience")
|
|
||||||
params = {"audience": audience, "assertion": assertion}
|
|
||||||
res = self.post(urljoin(self.root_url, "/session/start"),
|
|
||||||
params=params)
|
|
||||||
self.assertEquals(res.code, 200)
|
|
||||||
sessionid = res.body
|
|
||||||
self.setHeader("Signature", sessionid)
|
|
||||||
bucket_url = urljoin(self.root_url,"/app/%s/users/%s/keys/")
|
|
||||||
bucket_url %= (urlquote(audience, safe=""),
|
|
||||||
urlquote(assertion, safe=""))
|
|
||||||
return sessionid, bucket_url
|
|
||||||
|
|
||||||
def test_write_and_read_keys(self):
|
|
||||||
"""Test sequentual writing then reading of keys.
|
|
||||||
|
|
||||||
This test does a simple sequential write of a bunch of keys, then
|
|
||||||
reads them all back in the same order.
|
|
||||||
"""
|
|
||||||
sessionid, bucket_url = self.start_session()
|
|
||||||
|
|
||||||
# Write out a bunch of keys.
|
|
||||||
for i in range(self.num_keys):
|
|
||||||
key_url = urljoin(bucket_url, "key%d" % (i,))
|
|
||||||
params = {"value": "value%d" % (i,)}
|
|
||||||
res = self.put(key_url, params=params)
|
|
||||||
self.assertEquals(res.code, 200)
|
|
||||||
|
|
||||||
# Read all the keys back in.
|
|
||||||
for i in range(self.num_keys):
|
|
||||||
key_url = urljoin(bucket_url, "key%d" % (i,))
|
|
||||||
res = self.get(key_url)
|
|
||||||
self.assertEquals(res.code, 200)
|
|
||||||
self.assertEquals(json.loads(res.body)["value"], "value%d" % (i,))
|
|
Загрузка…
Ссылка в новой задаче