summaryrefslogtreecommitdiff
path: root/tests/benchmarks/test_blobs_sqlite_backend.py
diff options
context:
space:
mode:
authordrebs <drebs@riseup.net>2017-10-09 08:37:01 -0300
committerdrebs <drebs@riseup.net>2017-10-09 09:40:23 -0300
commitdabc885eb488e64614633273e8d402346a7a83f8 (patch)
treeb27481a935afe2f888bc73cc0d3f607b0ed5d78a /tests/benchmarks/test_blobs_sqlite_backend.py
parent9b29bc6d6589bea9bb10d8518f8de9383cbe8824 (diff)
[test] rename blobs sqlite benchmarks file
Diffstat (limited to 'tests/benchmarks/test_blobs_sqlite_backend.py')
-rw-r--r--tests/benchmarks/test_blobs_sqlite_backend.py88
1 files changed, 88 insertions, 0 deletions
diff --git a/tests/benchmarks/test_blobs_sqlite_backend.py b/tests/benchmarks/test_blobs_sqlite_backend.py
new file mode 100644
index 00000000..8c6caa66
--- /dev/null
+++ b/tests/benchmarks/test_blobs_sqlite_backend.py
@@ -0,0 +1,88 @@
+import pytest
+import os
+
+from uuid import uuid4
+from io import BytesIO
+
+from twisted.internet.defer import gatherResults
+from twisted.internet.defer import DeferredSemaphore
+
+from leap.soledad.client._db.blobs import SQLiteBlobBackend
+
+
+semaphore = DeferredSemaphore(2)
+
+
+#
+# put
+#
+
+def put(backend, amount, data):
+ deferreds = []
+ for _ in xrange(amount):
+ blob_id = uuid4().hex
+ fd = BytesIO(data)
+ size = len(data)
+ d = semaphore.run(backend.put, blob_id, fd, size)
+ deferreds.append(d)
+ return gatherResults(deferreds)
+
+
+def create_put_test(amount, size):
+
+ @pytest.inlineCallbacks
+ @pytest.mark.sqlite_blobs_backend_put
+ def test(txbenchmark, payload, tmpdir):
+ """
+ Insert a certain amount of data in the sqlite blobs backend.
+ """
+ dbpath = os.path.join(tmpdir.strpath, 'blobs.db')
+ backend = SQLiteBlobBackend(dbpath, key='123')
+ data = payload(size)
+ yield txbenchmark(put, backend, amount, data)
+
+ return test
+
+
+test_sqlite_blobs_backend_put_1_10000k = create_put_test(1, 10000 * 1000)
+test_sqlite_blobs_backend_put_10_1000k = create_put_test(10, 1000 * 1000)
+test_sqlite_blobs_backend_put_100_100k = create_put_test(100, 100 * 1000)
+test_sqlite_blobs_backend_put_1000_10k = create_put_test(1000, 10 * 1000)
+
+
+#
+# put
+#
+
+@pytest.inlineCallbacks
+def get(backend):
+ local = yield backend.list()
+ deferreds = []
+ for blob_id in local:
+ d = backend.get(blob_id)
+ deferreds.append(d)
+ yield gatherResults(deferreds)
+
+
+def create_get_test(amount, size):
+
+ @pytest.inlineCallbacks
+ @pytest.mark.sqlite_blobs_backend_get
+ def test(txbenchmark, payload, tmpdir):
+ """
+ Retrieve a certain amount of data from the sqlite blobs backend.
+ """
+ dbpath = os.path.join(tmpdir.strpath, 'blobs.db')
+ backend = SQLiteBlobBackend(dbpath, key='123')
+ data = payload(size)
+
+ yield put(backend, amount, data)
+ yield txbenchmark(get, backend)
+
+ return test
+
+
+test_sqlite_blobs_backend_get_1_10000k = create_get_test(1, 10000 * 1000)
+test_sqlite_blobs_backend_get_10_1000k = create_get_test(10, 1000 * 1000)
+test_sqlite_blobs_backend_get_100_100k = create_get_test(100, 100 * 1000)
+test_sqlite_blobs_backend_get_1000_10k = create_get_test(1000, 10 * 1000)