|
6 | 6 |
|
7 | 7 | """Test helpers for working with cassandra.""" |
8 | 8 |
|
9 | | -import locale |
10 | 9 | import shutil |
11 | 10 | import tempfile |
12 | | -from datetime import datetime, timedelta |
| 11 | +from datetime import datetime |
13 | 12 | from pathlib import Path |
14 | 13 | from unittest.mock import patch |
15 | 14 |
|
|
18 | 17 |
|
19 | 18 | import retracer as et_retracer |
20 | 19 | from errortracker import cassandra |
| 20 | +from tests.create_test_data import create_test_data |
21 | 21 |
|
22 | 22 |
|
23 | 23 | @pytest.fixture(scope="class") |
@@ -56,92 +56,5 @@ def datetime_now(): |
56 | 56 |
|
57 | 57 | @pytest.fixture(scope="class") |
58 | 58 | 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) |
147 | 60 | yield |
0 commit comments