summaryrefslogtreecommitdiff
path: root/tests/benchmarks/test_resources.py
diff options
context:
space:
mode:
authordrebs <drebs@riseup.net>2017-09-17 12:08:25 -0300
committerdrebs <drebs@riseup.net>2017-09-17 15:50:55 -0300
commitcfff46ff9becdbe5cf48816870e625ed253ecc57 (patch)
tree8d239e4499f559d86ed17ea3632008303b25d485 /tests/benchmarks/test_resources.py
parentf29abe28bd778838626d12fcabe3980a8ce4fa8c (diff)
[refactor] move tests to root of repository
Tests entrypoint was in a testing/ subfolder in the root of the repository. This was made mainly because we had some common files for tests and we didn't want to ship them (files in testing/test_soledad, which is itself a python package. This sometimes causes errors when loading tests (it seems setuptools is confused with having one python package in a subdirectory of another). This commit moves the tests entrypoint to the root of the repository. Closes: #8952
Diffstat (limited to 'tests/benchmarks/test_resources.py')
-rw-r--r--tests/benchmarks/test_resources.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/benchmarks/test_resources.py b/tests/benchmarks/test_resources.py
new file mode 100644
index 00000000..173edbd1
--- /dev/null
+++ b/tests/benchmarks/test_resources.py
@@ -0,0 +1,50 @@
+import pytest
+import random
+import time
+
+from decimal import Decimal
+
+
+def bellardBig(n):
+ # http://en.wikipedia.org/wiki/Bellard%27s_formula
+ pi = Decimal(0)
+ k = 0
+ while k < n:
+ pi += (Decimal(-1) ** k / (1024 ** k)) * (
+ Decimal(256) / (10 * k + 1) +
+ Decimal(1) / (10 * k + 9) -
+ Decimal(64) / (10 * k + 3) -
+ Decimal(32) / (4 * k + 1) -
+ Decimal(4) / (10 * k + 5) -
+ Decimal(4) / (10 * k + 7) -
+ Decimal(1) / (4 * k + 3))
+ k += 1
+ pi = pi * 1 / (2 ** 6)
+ return pi
+
+
+@pytest.mark.skip(reason='not a real use case, used only for instrumentation')
+def test_cpu_intensive(monitored_benchmark):
+
+ def _cpu_intensive():
+ sleep = [random.uniform(0.5, 1.5) for _ in xrange(3)]
+ while sleep:
+ t = sleep.pop()
+ time.sleep(t)
+ bellardBig(int((10 ** 3) * t))
+
+ monitored_benchmark(_cpu_intensive)
+
+
+@pytest.mark.skip(reason='not a real use case, used only for instrumentation')
+def test_memory_intensive(monitored_benchmark):
+
+ def _memory_intensive():
+ sleep = [random.uniform(0.5, 1.5) for _ in xrange(3)]
+ bigdata = ""
+ while sleep:
+ t = sleep.pop()
+ bigdata += "b" * 10 * int(10E6)
+ time.sleep(t)
+
+ monitored_benchmark(_memory_intensive)