# HG changeset patch # User Ludovic Chabant # Date 1413385874 25200 # Node ID 8b45c5ba5d47858053558bd56b263aa4f0db7a3d # Parent 5f809e691124a06c8aa8567cb7ffca205a59e25b Add benchmark tests. diff -r 5f809e691124 -r 8b45c5ba5d47 .hgignore --- a/.hgignore Mon Oct 13 22:41:21 2014 -0700 +++ b/.hgignore Wed Oct 15 08:11:14 2014 -0700 @@ -1,5 +1,4 @@ syntax:glob -benchmarks venv node_modules wikked/static @@ -11,4 +10,8 @@ *.sublime-* MANIFEST Wikked.egg-info +benchmarks/Benchmark.conf +benchmarks/logs +benchmarks/logs-distributed +benchmarks/results diff -r 5f809e691124 -r 8b45c5ba5d47 benchmarks/Benchmark.conf.sample --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/benchmarks/Benchmark.conf.sample Wed Oct 15 08:11:14 2014 -0700 @@ -0,0 +1,52 @@ +# main section for the test case +[main] +title=Wikked Load Tests 1 +description=Test fetching pages randomly +url=http://localhost:5000 + +# a section for each test +[test_benchmark] +description=Access some random URLs +#username=foo +#password=bar +page_names=Main page;Sandbox;Another Sandbox +nb_times=20 + +# a section to configure the test mode +[ftest] +log_to = console file +log_path = logs/test-load1.log +result_path = results/test-load1.xml +sleep_time_min = 0 +sleep_time_max = 0 + +# a section to configure the bench mode +[bench] +cycles = 10:20:40 +duration = 10 +startup_delay = 0.01 +sleep_time = 0.01 +cycle_time = 1 +log_to = +log_path = logs/bench-load1.log +result_path = results/bench-load1.xml +sleep_time_min = 0 +sleep_time_max = 0.5 + +[distribute] +log_path = log-distributed +funkload_location=http://pypi.python.org/packages/source/f/funkload/funkload-1.16.1.tar.gz + +[workers] +hosts = foo1 foo2 + +[foo1] +host=foo's ip +username=foo +ssh_key=foo's key + +[foo2] +host=foo's ip +username=foo +ssh_key=foo's key + diff -r 5f809e691124 -r 8b45c5ba5d47 benchmarks/test_benchmark.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/benchmarks/test_benchmark.py Wed Oct 15 08:11:14 2014 -0700 @@ -0,0 +1,36 @@ +import re +import urllib +import random +import unittest +from funkload.FunkLoadTestCase import FunkLoadTestCase + + +class Benchmark(FunkLoadTestCase): + """This test uses a configuration file Benchmark.conf.""" + def setUp(self): + self.server_url = self.conf_get('main', 'url') + + def test_simple(self): + server_url = self.server_url + if not re.match('https?://', server_url): + raise Exception("The `server_url` setting doesn't have a scheme.") + + username = self.conf_get('test_benchmark', 'username', None) + password = self.conf_get('test_benchmark', 'password', None) + if username and password: + self.post(self.server_url + "/api/user/login", + params=[['username', username], + ['password', password]], + description="Login as %s" % username) + + nb_times = self.conf_getInt('test_benchmark', 'nb_times') + names = self.conf_get('test_benchmark', 'page_names').split(';') + for i in range(nb_times): + r = random.randint(0, len(names) - 1) + url = server_url + '/api/read/' + urllib.quote(names[r]) + self.get(url, description='Getting %s' % names[r]) + + +if __name__ in ('main', '__main__'): + unittest.main() +