Skip to content

Commit 82b799b

Browse files
committed
tests: make a standalone 'create_test_data' script that can be called in dev
1 parent b46e0c7 commit 82b799b

File tree

2 files changed

+95
-90
lines changed

2 files changed

+95
-90
lines changed

src/tests/conftest.py

Lines changed: 3 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
"""Test helpers for working with cassandra."""
88

9-
import locale
109
import shutil
1110
import tempfile
12-
from datetime import datetime, timedelta
11+
from datetime import datetime
1312
from pathlib import Path
1413
from unittest.mock import patch
1514

@@ -18,6 +17,7 @@
1817

1918
import retracer as et_retracer
2019
from errortracker import cassandra
20+
from tests.create_test_data import create_test_data
2121

2222

2323
@pytest.fixture(scope="class")
@@ -56,92 +56,5 @@ def datetime_now():
5656

5757
@pytest.fixture(scope="class")
5858
def cassandra_data(datetime_now, temporary_db):
59-
import logging
60-
61-
import bson
62-
63-
from daisy.submit import submit
64-
65-
# disable daisy logger temporarily
66-
daisy_logger = logging.getLogger("daisy")
67-
daisy_logger_level = daisy_logger.level
68-
daisy_logger.setLevel(51) # CRITICAL is 50, so let's go higher
69-
70-
# Make sure the datetime will get formatted "correctly" in that cursed time format: Mon May 5 14:46:10 2025
71-
locale.setlocale(locale.LC_ALL, "C.UTF-8")
72-
73-
def count():
74-
counter = 0
75-
while True:
76-
yield str(counter)
77-
counter += 1
78-
79-
def new_oops(days_ago, data, systemid="imatestsystem"):
80-
crash_date = datetime_now - timedelta(days=days_ago)
81-
oops_date = crash_date.strftime("%c")
82-
data.update({"Date": oops_date})
83-
bson_data = bson.encode(data)
84-
request = type(
85-
"Request",
86-
(object,),
87-
dict(data=bson_data, headers={"X-Whoopsie-Version": "0.2.81ubuntu~fakefortesting"}),
88-
)
89-
submit(request, systemid)
90-
91-
# Get a wide screen, because here we'll want to have compact data, meaning long lines 🙃
92-
# fmt: off
93-
94-
# increase-rate package version 1
95-
for i in [30, 20, 10, 5, 2]:
96-
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "increase-rate 1", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/increase-rate", "StacktraceAddressSignature": "/usr/bin/increase-rate:42:/usr/bin/increase-rate+28"})
97-
98-
# increase-rate package version 2
99-
for i in [2, 2, 1, 1, 1, 0, 0, 0, 0]:
100-
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "increase-rate 2", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/increase-rate", "StacktraceAddressSignature": "/usr/bin/increase-rate:42:/usr/bin/increase-rate+fa0"})
101-
102-
# increase-rate package version 2 in proposed, even more crashes!
103-
for i in [1, 0]:
104-
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "increase-rate 2", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/increase-rate", "StacktraceAddressSignature": "/usr/bin/increase-rate:42:/usr/bin/increase-rate+fa0", "Tags": "package-from-proposed"})
105-
106-
# no-crashes-today package version 1 (old version with crashes)
107-
for i in [30, 20, 10, 5, 2]:
108-
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"})
109-
110-
# no-crashes-today package version 2 (no crashes today - last crash was yesterday)
111-
for i in [5, 3, 1]:
112-
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"})
113-
114-
# few-crashes package version 1 (old version with crashes)
115-
for i in [30, 20, 10, 5, 2]:
116-
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"})
117-
118-
# few-crashes package version 2 (only 2 crashes today - less than threshold of 3)
119-
for i in [0, 0]:
120-
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"})
121-
122-
# new-package (no old version - should always be increase=True)
123-
for i in [0, 0, 0, 0, 0]:
124-
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "new-package 1", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/new-package", "StacktraceAddressSignature": "/usr/bin/new-package:1:/usr/bin/new-package+10"})
125-
126-
# low-difference package version 1 (old version with consistent crashes)
127-
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]:
128-
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"})
129-
130-
# low-difference package version 2 (similar crash rate to version 1, so difference should be low)
131-
# Only 1 crash today which is less than the expected average
132-
for i in [0]:
133-
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "low-difference 2", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/low-difference", "StacktraceAddressSignature": "/usr/bin/low-difference:2:/usr/bin/low-difference+20"})
134-
135-
# all-proposed package version 1
136-
for i in [30, 20, 10]:
137-
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"})
138-
139-
# all-proposed package version 2 (all crashes today are from proposed)
140-
for i in [0, 0, 0, 0]:
141-
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"})
142-
# fmt: on
143-
144-
# re-enable daisy logger
145-
daisy_logger.setLevel(daisy_logger_level)
146-
59+
create_test_data(datetime_now)
14760
yield

src/tests/create_test_data.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import locale
2+
import logging
3+
from datetime import datetime, timedelta
4+
5+
import bson
6+
7+
from daisy.submit import submit
8+
9+
10+
def create_test_data(datetime_now=datetime.now()):
11+
# disable daisy logger temporarily
12+
daisy_logger = logging.getLogger("daisy")
13+
daisy_logger_level = daisy_logger.level
14+
daisy_logger.setLevel(51) # CRITICAL is 50, so let's go higher
15+
16+
# Make sure the datetime will get formatted "correctly" in that cursed time format: Mon May 5 14:46:10 2025
17+
locale.setlocale(locale.LC_ALL, "C.UTF-8")
18+
19+
def new_oops(days_ago, data, systemid="imatestsystem"):
20+
crash_date = datetime_now - timedelta(days=days_ago)
21+
oops_date = crash_date.strftime("%c")
22+
data.update({"Date": oops_date})
23+
bson_data = bson.encode(data)
24+
request = type(
25+
"Request",
26+
(object,),
27+
dict(data=bson_data, headers={"X-Whoopsie-Version": "0.2.81ubuntu~fakefortesting"}),
28+
)
29+
submit(request, systemid)
30+
31+
# Get a wide screen, because here we'll want to have compact data, meaning long lines 🙃
32+
# fmt: off
33+
34+
# increase-rate package version 1
35+
for i in [30, 20, 10, 5, 2]:
36+
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "increase-rate 1", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/increase-rate", "StacktraceAddressSignature": "/usr/bin/increase-rate:42:/usr/bin/increase-rate+28"})
37+
38+
# increase-rate package version 2
39+
for i in [2, 2, 1, 1, 1, 0, 0, 0, 0]:
40+
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "increase-rate 2", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/increase-rate", "StacktraceAddressSignature": "/usr/bin/increase-rate:42:/usr/bin/increase-rate+fa0"})
41+
42+
# increase-rate package version 2 in proposed, even more crashes!
43+
for i in [1, 0]:
44+
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "increase-rate 2", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/increase-rate", "StacktraceAddressSignature": "/usr/bin/increase-rate:42:/usr/bin/increase-rate+fa0", "Tags": "package-from-proposed"})
45+
46+
# no-crashes-today package version 1 (old version with crashes)
47+
for i in [30, 20, 10, 5, 2]:
48+
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"})
49+
50+
# no-crashes-today package version 2 (no crashes today - last crash was yesterday)
51+
for i in [5, 3, 1]:
52+
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"})
53+
54+
# few-crashes package version 1 (old version with crashes)
55+
for i in [30, 20, 10, 5, 2]:
56+
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"})
57+
58+
# few-crashes package version 2 (only 2 crashes today - less than threshold of 3)
59+
for i in [0, 0]:
60+
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"})
61+
62+
# new-package (no old version - should always be increase=True)
63+
for i in [0, 0, 0, 0, 0]:
64+
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "new-package 1", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/new-package", "StacktraceAddressSignature": "/usr/bin/new-package:1:/usr/bin/new-package+10"})
65+
66+
# low-difference package version 1 (old version with consistent crashes)
67+
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]:
68+
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"})
69+
70+
# low-difference package version 2 (similar crash rate to version 1, so difference should be low)
71+
# Only 1 crash today which is less than the expected average
72+
for i in [0]:
73+
new_oops(i, {"DistroRelease": "Ubuntu 24.04", "Package": "low-difference 2", "ProblemType": "Crash", "Architecture": "amd64", "ExecutablePath": "/usr/bin/low-difference", "StacktraceAddressSignature": "/usr/bin/low-difference:2:/usr/bin/low-difference+20"})
74+
75+
# all-proposed package version 1
76+
for i in [30, 20, 10]:
77+
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"})
78+
79+
# all-proposed package version 2 (all crashes today are from proposed)
80+
for i in [0, 0, 0, 0]:
81+
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"})
82+
# fmt: on
83+
84+
# re-enable daisy logger
85+
daisy_logger.setLevel(daisy_logger_level)
86+
87+
88+
if __name__ == "__main__":
89+
from errortracker import cassandra
90+
91+
cassandra.setup_cassandra()
92+
create_test_data()

0 commit comments

Comments
 (0)