summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2017-12-27 14:47:27 -0200
committerdrebs <drebs@leap.se>2017-12-27 14:50:24 -0200
commit5edf23deefca71b632b2cdf2b686c478bc7dcce2 (patch)
tree9c5cd7f601a63b8d86f104bdaf02333167f18269 /tests
parent0f2bd936335ee64e052aba584ecff851af1418a1 (diff)
[test] fix blobs fs backend benchmarks to account for multiple rounds
Diffstat (limited to 'tests')
-rw-r--r--tests/benchmarks/test_blobs_fs_backend.py49
1 files changed, 35 insertions, 14 deletions
diff --git a/tests/benchmarks/test_blobs_fs_backend.py b/tests/benchmarks/test_blobs_fs_backend.py
index 9f1ebf94..2b11c867 100644
--- a/tests/benchmarks/test_blobs_fs_backend.py
+++ b/tests/benchmarks/test_blobs_fs_backend.py
@@ -4,25 +4,42 @@ from leap.soledad.server._blobs import FilesystemBlobsBackend
from twisted.internet import defer
from twisted.web.client import FileBodyProducer
from twisted.internet._producer_helpers import _PullToPush
+from uuid import uuid4
def create_write_test(amount, size):
@pytest.inlineCallbacks
@pytest.mark.benchmark(group='test_blobs_fs_backend_write')
- def test(txbenchmark, payload, tmpdir):
+ def test(txbenchmark_with_setup, payload, tmpdir):
"""
Write many blobs of the same size to the filesystem backend.
"""
backend = FilesystemBlobsBackend(blobs_path=tmpdir.strpath)
data = payload(size)
- semaphore = defer.DeferredSemaphore(100)
- deferreds = []
- for i in xrange(amount):
- producer = FileBodyProducer(BytesIO(data))
- d = semaphore.run(backend.write_blob, 'user', str(i), producer)
- deferreds.append(d)
- yield txbenchmark(defer.gatherResults, deferreds)
+
+ @pytest.inlineCallbacks
+ def setup():
+ blobs = yield backend.list_blobs('user')
+ deferreds = []
+ for blob_id in blobs:
+ d = backend.delete_blob('user', blob_id)
+ deferreds.append(d)
+ yield defer.gatherResults(deferreds)
+
+ @pytest.inlineCallbacks
+ def write():
+ semaphore = defer.DeferredSemaphore(100)
+ deferreds = []
+ for i in xrange(amount):
+ producer = FileBodyProducer(BytesIO(data))
+ blob_id = uuid4().hex
+ d = semaphore.run(
+ backend.write_blob, 'user', blob_id, producer)
+ deferreds.append(d)
+ yield defer.gatherResults(deferreds)
+
+ yield txbenchmark_with_setup(setup, write)
return test
@@ -70,12 +87,16 @@ def create_read_test(amount, size):
yield defer.gatherResults(deferreds)
# ... then measure the read operation
- deferreds = []
- for i in xrange(amount):
- consumer = DevNull()
- d = semaphore.run(backend.read_blob, 'user', str(i), consumer)
- deferreds.append(d)
- yield txbenchmark(defer.gatherResults, deferreds)
+ @pytest.inlineCallbacks
+ def read():
+ deferreds = []
+ for i in xrange(amount):
+ consumer = DevNull()
+ d = semaphore.run(backend.read_blob, 'user', str(i), consumer)
+ deferreds.append(d)
+ yield defer.gatherResults(deferreds)
+
+ yield txbenchmark(read)
return test