summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2016-08-09 23:54:33 -0300
committerVictor Shyba <victor.shyba@gmail.com>2016-08-22 12:36:16 -0300
commit6639cf0d00fa5bdfc0f43d4dea5c5055776130b8 (patch)
treef8fd08ad84918e96cffdffd814e2a129ef705599 /testing
parentf0f3e0358a01708eb048d8eaf463361e682be466 (diff)
[test] use a nested func to simplify scenarios
If we have many scenarios (like 20/500k, 100/100k, 1000,10k) then making a nested function to generate tests based on scenario parameters simplifies the code a lot.
Diffstat (limited to 'testing')
-rw-r--r--testing/tests/perf/conftest.py6
-rw-r--r--testing/tests/perf/test_sync.py104
2 files changed, 35 insertions, 75 deletions
diff --git a/testing/tests/perf/conftest.py b/testing/tests/perf/conftest.py
index 8a75d0ae..4b2186db 100644
--- a/testing/tests/perf/conftest.py
+++ b/testing/tests/perf/conftest.py
@@ -208,7 +208,7 @@ def txbenchmark_with_setup(benchmark):
#
@pytest.fixture()
-def soledad_client(tmpdir, soledad_server, remote_db, soledad_dbs):
+def soledad_client(tmpdir, soledad_server, remote_db, soledad_dbs, request):
passphrase = DEFAULT_PASSPHRASE
server_url = DEFAULT_URL
token = DEFAULT_TOKEN
@@ -220,7 +220,7 @@ def soledad_client(tmpdir, soledad_server, remote_db, soledad_dbs):
local_db_path = os.path.join(tmpdir.strpath, '%s.db' % uuid4().hex)
remote_db(uuid)
soledad_dbs(uuid)
- return Soledad(
+ soledad_client = Soledad(
uuid,
unicode(passphrase),
secrets_path=secrets_path,
@@ -229,4 +229,6 @@ def soledad_client(tmpdir, soledad_server, remote_db, soledad_dbs):
cert_file=None,
auth_token=token,
defer_encryption=True)
+ request.addfinalizer(soledad_client.close)
+ return soledad_client
return create
diff --git a/testing/tests/perf/test_sync.py b/testing/tests/perf/test_sync.py
index ea109d05..146f1394 100644
--- a/testing/tests/perf/test_sync.py
+++ b/testing/tests/perf/test_sync.py
@@ -15,87 +15,45 @@ def load_up(client, amount, size):
return d
-@pytest.inlineCallbacks
-@pytest.mark.benchmark(group="test_upload")
-def test_upload_20_500k(soledad_client, txbenchmark_with_setup):
- uploads, size, client = 20, 500*1000, soledad_client()
+def create_upload(uploads, size):
+ @pytest.inlineCallbacks
+ @pytest.mark.benchmark(group="test_upload")
+ def test(soledad_client, txbenchmark_with_setup):
+ client = soledad_client()
- def setup():
- return load_up(client, uploads, size)
+ def setup():
+ return load_up(client, uploads, size)
- yield txbenchmark_with_setup(setup, client.sync)
+ yield txbenchmark_with_setup(setup, client.sync)
+ return test
-@pytest.inlineCallbacks
-@pytest.mark.benchmark(group="test_upload")
-def test_upload_100_100k(soledad_client, txbenchmark_with_setup):
- uploads, size, client = 100, 100*1000, soledad_client()
+test_upload_20_500k = create_upload(20, 500*1000)
+test_upload_100_100k = create_upload(100, 100*1000)
+test_upload_1000_10k = create_upload(1000, 10*1000)
- def setup():
- return load_up(client, uploads, size)
- yield txbenchmark_with_setup(setup, client.sync)
+def create_download(downloads, size):
+ @pytest.inlineCallbacks
+ @pytest.mark.benchmark(group="test_download")
+ def test(soledad_client, txbenchmark_with_setup):
+ client = soledad_client()
+ yield load_up(client, downloads, size)
+ yield client.sync()
+ # We could create them directly on couch, but sending them
+ # ensures we are dealing with properly encrypted docs
-@pytest.inlineCallbacks
-@pytest.mark.benchmark(group="test_upload")
-def test_upload_1000_10k(soledad_client, txbenchmark_with_setup):
- uploads, size, client = 1000, 10*1000, soledad_client()
+ def setup():
+ clean_client = soledad_client()
+ return (clean_client,), {}
- def setup():
- return load_up(client, uploads, size)
+ def sync(clean_client):
+ return clean_client.sync()
+ yield txbenchmark_with_setup(setup, sync)
+ return test
- yield txbenchmark_with_setup(setup, client.sync)
-
-@pytest.inlineCallbacks
-@pytest.mark.benchmark(group="test_download")
-def test_download_20_500k(soledad_client, txbenchmark_with_setup):
- downloads, size, client = 20, 500*1000, soledad_client()
-
- yield load_up(client, downloads, size)
- yield client.sync()
-
- def setup():
- clean_client = soledad_client()
- return (clean_client,), {}
-
- def sync(clean_client):
- return clean_client.sync()
- yield txbenchmark_with_setup(setup, sync)
-
-
-@pytest.inlineCallbacks
-@pytest.mark.benchmark(group="test_download")
-def test_download_100_100k(soledad_client, txbenchmark_with_setup):
- downloads, size, client = 100, 100*1000, soledad_client()
-
- yield load_up(client, downloads, size)
- yield client.sync()
- # We could create them directly on remote db, but sending them
- # ensures we are dealing with properly encrypted docs
-
- def setup():
- clean_client = soledad_client()
- return (clean_client,), {}
-
- def sync(clean_client):
- return clean_client.sync()
- yield txbenchmark_with_setup(setup, sync)
-
-
-@pytest.inlineCallbacks
-@pytest.mark.benchmark(group="test_download")
-def test_download_1000_10k(soledad_client, txbenchmark_with_setup):
- downloads, size, client = 1000, 10*1000, soledad_client()
-
- yield load_up(client, downloads, size)
- yield client.sync()
-
- def setup():
- clean_client = soledad_client()
- return (clean_client,), {}
-
- def sync(clean_client):
- return clean_client.sync()
- yield txbenchmark_with_setup(setup, sync)
+test_download_20_500k = create_download(20, 500*1000)
+test_download_100_100k = create_download(100, 100*1000)
+test_download_1000_10k = create_download(1000, 10*1000)