Skip to content

Commit 35b4cd2

Browse files
committed
tests: speed up tests by having cassandra fixtures be 'class' scoped
1 parent ab360ab commit 35b4cd2

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/tests/conftest.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from errortracker import cassandra
2121

2222

23-
@pytest.fixture(scope="function")
23+
@pytest.fixture(scope="class")
2424
def temporary_db():
2525
cassandra.KEYSPACE = "tmp"
2626
cassandra.REPLICATION_FACTOR = 1
@@ -29,7 +29,7 @@ def temporary_db():
2929
management.drop_keyspace(cassandra.KEYSPACE)
3030

3131

32-
@pytest.fixture(scope="function")
32+
@pytest.fixture(scope="class")
3333
def retracer(temporary_db):
3434
temp = Path(tempfile.mkdtemp())
3535
config_dir = temp / "config"
@@ -54,11 +54,12 @@ def datetime_now():
5454
return datetime.now()
5555

5656

57-
@pytest.fixture(scope="function")
57+
@pytest.fixture(scope="class")
5858
def cassandra_data(datetime_now, temporary_db):
59-
import bson
6059
import logging
6160

61+
import bson
62+
6263
from daisy.submit import submit
6364

6465
# disable daisy logger temporarily
@@ -105,15 +106,15 @@ def new_oops(days_ago, data, systemid="imatestsystem"):
105106
# no-crashes-today package version 1 (old version with crashes)
106107
for i in [30, 20, 10, 5, 2]:
107108
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "no-crashes-today 1", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/no-crashes-today", "StacktraceAddressSignature": "/usr/bin/no-crashes-today:1:/usr/bin/no-crashes-today+10"})
108-
109+
109110
# no-crashes-today package version 2 (no crashes today - last crash was yesterday)
110111
for i in [5, 3, 1]:
111112
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "no-crashes-today 2", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/no-crashes-today", "StacktraceAddressSignature": "/usr/bin/no-crashes-today:2:/usr/bin/no-crashes-today+20"})
112113

113114
# few-crashes package version 1 (old version with crashes)
114115
for i in [30, 20, 10, 5, 2]:
115116
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "few-crashes 1", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/few-crashes", "StacktraceAddressSignature": "/usr/bin/few-crashes:1:/usr/bin/few-crashes+10"})
116-
117+
117118
# few-crashes package version 2 (only 2 crashes today - less than threshold of 3)
118119
for i in [0, 0]:
119120
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "few-crashes 2", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/few-crashes", "StacktraceAddressSignature": "/usr/bin/few-crashes:2:/usr/bin/few-crashes+20"})
@@ -125,7 +126,7 @@ def new_oops(days_ago, data, systemid="imatestsystem"):
125126
# low-difference package version 1 (old version with consistent crashes)
126127
for i in [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]:
127128
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "low-difference 1", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/low-difference", "StacktraceAddressSignature": "/usr/bin/low-difference:1:/usr/bin/low-difference+10"})
128-
129+
129130
# low-difference package version 2 (similar crash rate to version 1, so difference should be low)
130131
# Only 1 crash today which is less than the expected average
131132
for i in [0]:
@@ -134,7 +135,7 @@ def new_oops(days_ago, data, systemid="imatestsystem"):
134135
# all-proposed package version 1
135136
for i in [30, 20, 10]:
136137
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "all-proposed 1", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/all-proposed", "StacktraceAddressSignature": "/usr/bin/all-proposed:1:/usr/bin/all-proposed+10"})
137-
138+
138139
# all-proposed package version 2 (all crashes today are from proposed)
139140
for i in [0, 0, 0, 0]:
140141
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "all-proposed 2", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/all-proposed", "StacktraceAddressSignature": "/usr/bin/all-proposed:2:/usr/bin/all-proposed+20", "Tags": "package-from-proposed"})

src/tests/test_oopses.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _test_insert_check(self, oopsid, day_key, value=None):
102102
assert value == result["duration"]
103103
# The oops has been indexed by day
104104
oops_refs = cassandra_schema.DayOOPS.filter(key=day_key.encode()).only(["value"])
105-
assert [oopsid] == [day_oops.value.decode() for day_oops in oops_refs]
105+
assert oopsid in [day_oops.value.decode() for day_oops in oops_refs]
106106
# TODO - the aggregates for the OOPS have been updated.
107107

108108
def test_insert_oops_dict(self, temporary_db):
@@ -124,12 +124,12 @@ def test_insert_updates_counters(self, temporary_db):
124124

125125
day_key = oopses.insert_dict(oopsid, oops, user_token)
126126
oops_count = cassandra_schema.Counters.filter(key=b"oopses", column1=day_key)
127-
assert [1] == [count.value for count in oops_count]
127+
assert [3] == [count.value for count in oops_count]
128128

129129
oopsid = str(uuid.uuid1())
130130
day_key = oopses.insert_dict(oopsid, oops, user_token)
131131
oops_count = cassandra_schema.Counters.filter(key=b"oopses", column1=day_key)
132-
assert [2] == [count.value for count in oops_count]
132+
assert [4] == [count.value for count in oops_count]
133133

134134

135135
class TestBucket:

0 commit comments

Comments
 (0)