summaryrefslogtreecommitdiff
path: root/testing/tests/perf/test_sync.py
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2016-08-09 21:08:13 -0300
committerVictor Shyba <victor.shyba@gmail.com>2016-08-22 12:36:16 -0300
commitf0f3e0358a01708eb048d8eaf463361e682be466 (patch)
treea42831d9f905c0770ee78cca1be2c5bf3af10e51 /testing/tests/perf/test_sync.py
parente8747096045933754d3f8ac2608cce844f6b0fee (diff)
[test] Adds pytest-benchmark adapted to Twisted
Adapted pytest-benchmark to Twisted as it's synchronous and added fixtures for benchmarking.
Diffstat (limited to 'testing/tests/perf/test_sync.py')
-rw-r--r--testing/tests/perf/test_sync.py121
1 files changed, 87 insertions, 34 deletions
diff --git a/testing/tests/perf/test_sync.py b/testing/tests/perf/test_sync.py
index 45af9a91..ea109d05 100644
--- a/testing/tests/perf/test_sync.py
+++ b/testing/tests/perf/test_sync.py
@@ -2,47 +2,100 @@ import pytest
from twisted.internet.defer import gatherResults
-from leap.soledad.common.couch import CouchDatabase
-from leap.soledad.common.document import ServerDocument
+
+def load_up(client, amount, size):
+ content = 'x'*size
+ deferreds = []
+ # create a bunch of local documents
+ for i in xrange(amount):
+ d = client.create_doc({'content': content})
+ deferreds.append(d)
+ d = gatherResults(deferreds)
+ d.addCallback(lambda _: None)
+ return d
-content = ' ' * 10000
+@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 setup():
+ return load_up(client, uploads, size)
+
+ yield txbenchmark_with_setup(setup, client.sync)
@pytest.inlineCallbacks
-def test_upload(soledad_client, request):
- # create a bunch of local documents
- uploads = request.config.option.num_docs
- deferreds = []
- for i in xrange(uploads):
- d = soledad_client.create_doc({'upload': True, 'content': content})
- deferreds.append(d)
- yield gatherResults(deferreds)
+@pytest.mark.benchmark(group="test_upload")
+def test_upload_100_100k(soledad_client, txbenchmark_with_setup):
+ uploads, size, client = 100, 100*1000, soledad_client()
+
+ def setup():
+ return load_up(client, uploads, size)
+
+ yield txbenchmark_with_setup(setup, client.sync)
+
+
+@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()
- # synchronize
- yield soledad_client.sync()
+ def setup():
+ return load_up(client, uploads, size)
- # check that documents reached the remote database
- url = request.config.getoption('--couch-url')
- remote = CouchDatabase(url, 'user-0')
- remote_count, _ = remote.get_all_docs()
- assert remote_count == uploads
+ yield txbenchmark_with_setup(setup, client.sync)
@pytest.inlineCallbacks
-def test_download(soledad_client, request):
- # create a bunch of remote documents
- downloads = request.config.option.num_docs
- url = request.config.getoption('--couch-url')
- remote = CouchDatabase(url, 'user-0')
- for i in xrange(downloads):
- doc = ServerDocument('doc-%d' % i, 'replica:1')
- doc.content = {'download': True, 'content': content}
- remote.save_document(None, doc, i)
-
- # synchronize
- yield soledad_client.sync()
-
- # check that documents reached the local database
- local_count, docs = yield soledad_client.get_all_docs()
- assert local_count == downloads
+@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)