|
1 | | -import time |
2 | 1 | from datetime import datetime, timedelta |
3 | 2 | from datetime import timezone as dt_timezone |
4 | 3 |
|
|
15 | 14 | ) |
16 | 15 | from sentry.testutils.cases import SnubaTestCase, TestCase |
17 | 16 |
|
| 17 | +PREPROD_PRODUCER_MOCK_PATH = "sentry.preprod.eap.write._eap_producer.produce" |
| 18 | + |
18 | 19 |
|
19 | 20 | class PreprodEAPIntegrationTest(TestCase, SnubaTestCase): |
20 | 21 | def test_write_and_read_size_metric_round_trip(self): |
@@ -58,41 +59,35 @@ def test_write_and_read_size_metric_round_trip(self): |
58 | 59 | analysis_file_id=123, |
59 | 60 | ) |
60 | 61 |
|
61 | | - produce_preprod_size_metric_to_eap( |
| 62 | + self.produce_and_store_eap_items( |
| 63 | + PREPROD_PRODUCER_MOCK_PATH, |
| 64 | + produce_preprod_size_metric_to_eap, |
62 | 65 | size_metric=size_metric, |
63 | 66 | organization=self.organization, |
64 | 67 | organization_id=self.organization.id, |
65 | 68 | project_id=self.project.id, |
66 | 69 | ) |
67 | 70 |
|
68 | | - max_attempts = 20 |
69 | | - found = False |
70 | | - |
71 | | - for attempt in range(max_attempts): |
72 | | - time.sleep(0.5) |
73 | | - |
74 | | - app_filter = TraceItemFilter( |
75 | | - comparison_filter=ComparisonFilter( |
76 | | - key=AttributeKey(name="app_id", type=AttributeKey.Type.TYPE_STRING), |
77 | | - op=ComparisonFilter.OP_EQUALS, |
78 | | - value=AttributeValue(val_str="com.example.integrationtest"), |
79 | | - ) |
80 | | - ) |
81 | | - |
82 | | - response = query_preprod_size_metrics( |
83 | | - organization_id=self.organization.id, |
84 | | - project_ids=[self.project.id], |
85 | | - start=datetime.now(dt_timezone.utc) - timedelta(hours=1), |
86 | | - end=datetime.now(dt_timezone.utc) + timedelta(hours=1), |
87 | | - referrer="test.preprod.integration", |
88 | | - filter=app_filter, |
| 71 | + app_filter = TraceItemFilter( |
| 72 | + comparison_filter=ComparisonFilter( |
| 73 | + key=AttributeKey(name="app_id", type=AttributeKey.Type.TYPE_STRING), |
| 74 | + op=ComparisonFilter.OP_EQUALS, |
| 75 | + value=AttributeValue(val_str="com.example.integrationtest"), |
89 | 76 | ) |
| 77 | + ) |
90 | 78 |
|
91 | | - if response.column_values: |
92 | | - found = True |
93 | | - break |
| 79 | + response = query_preprod_size_metrics( |
| 80 | + organization_id=self.organization.id, |
| 81 | + project_ids=[self.project.id], |
| 82 | + start=datetime.now(dt_timezone.utc) - timedelta(hours=1), |
| 83 | + end=datetime.now(dt_timezone.utc) + timedelta(hours=1), |
| 84 | + referrer="test.preprod.integration", |
| 85 | + filter=app_filter, |
| 86 | + ) |
94 | 87 |
|
95 | | - assert found, f"Data not found in Snuba after {max_attempts} attempts" |
| 88 | + assert response.column_values and response.column_values[0].results, ( |
| 89 | + "Data not found in Snuba" |
| 90 | + ) |
96 | 91 |
|
97 | 92 | columns = {cv.attribute_name: idx for idx, cv in enumerate(response.column_values)} |
98 | 93 |
|
@@ -154,49 +149,44 @@ def test_write_multiple_size_metrics_same_artifact(self): |
154 | 149 | max_install_size=1000, |
155 | 150 | ) |
156 | 151 |
|
157 | | - produce_preprod_size_metric_to_eap( |
| 152 | + self.produce_and_store_eap_items( |
| 153 | + PREPROD_PRODUCER_MOCK_PATH, |
| 154 | + produce_preprod_size_metric_to_eap, |
158 | 155 | size_metric=size_metric_main, |
159 | 156 | organization=self.organization, |
160 | 157 | organization_id=self.organization.id, |
161 | 158 | project_id=self.project.id, |
162 | 159 | ) |
163 | 160 |
|
164 | | - produce_preprod_size_metric_to_eap( |
| 161 | + self.produce_and_store_eap_items( |
| 162 | + PREPROD_PRODUCER_MOCK_PATH, |
| 163 | + produce_preprod_size_metric_to_eap, |
165 | 164 | size_metric=size_metric_watch, |
166 | 165 | organization=self.organization, |
167 | 166 | organization_id=self.organization.id, |
168 | 167 | project_id=self.project.id, |
169 | 168 | ) |
170 | 169 |
|
171 | | - max_attempts = 20 |
172 | | - found_count = 0 |
173 | | - |
174 | | - for attempt in range(max_attempts): |
175 | | - time.sleep(0.5) |
176 | | - |
177 | | - app_filter = TraceItemFilter( |
178 | | - comparison_filter=ComparisonFilter( |
179 | | - key=AttributeKey(name="app_id", type=AttributeKey.Type.TYPE_STRING), |
180 | | - op=ComparisonFilter.OP_EQUALS, |
181 | | - value=AttributeValue(val_str="com.example.multitest"), |
182 | | - ) |
183 | | - ) |
184 | | - |
185 | | - response = query_preprod_size_metrics( |
186 | | - organization_id=self.organization.id, |
187 | | - project_ids=[self.project.id], |
188 | | - start=datetime.now(dt_timezone.utc) - timedelta(hours=1), |
189 | | - end=datetime.now(dt_timezone.utc) + timedelta(hours=1), |
190 | | - referrer="test.preprod.integration", |
191 | | - filter=app_filter, |
| 170 | + app_filter = TraceItemFilter( |
| 171 | + comparison_filter=ComparisonFilter( |
| 172 | + key=AttributeKey(name="app_id", type=AttributeKey.Type.TYPE_STRING), |
| 173 | + op=ComparisonFilter.OP_EQUALS, |
| 174 | + value=AttributeValue(val_str="com.example.multitest"), |
192 | 175 | ) |
| 176 | + ) |
193 | 177 |
|
194 | | - if response.column_values: |
195 | | - found_count = len(response.column_values[0].results) |
196 | | - if found_count >= 2: |
197 | | - break |
| 178 | + response = query_preprod_size_metrics( |
| 179 | + organization_id=self.organization.id, |
| 180 | + project_ids=[self.project.id], |
| 181 | + start=datetime.now(dt_timezone.utc) - timedelta(hours=1), |
| 182 | + end=datetime.now(dt_timezone.utc) + timedelta(hours=1), |
| 183 | + referrer="test.preprod.integration", |
| 184 | + filter=app_filter, |
| 185 | + ) |
198 | 186 |
|
199 | | - assert found_count == 2, f"Expected 2 records, found {found_count}" |
| 187 | + assert response.column_values and len(response.column_values[0].results) == 2, ( |
| 188 | + f"Expected 2 records, found {len(response.column_values[0].results) if response.column_values else 0}" |
| 189 | + ) |
200 | 190 |
|
201 | 191 | columns = {cv.attribute_name: idx for idx, cv in enumerate(response.column_values)} |
202 | 192 | num_rows = len(response.column_values[0].results) |
|
0 commit comments