Skip to content

Commit 1933759

Browse files
fix query counts
1 parent 6580b96 commit 1933759

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

unittests/test_importers_performance.py

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,6 @@ def import_reimport_performance(self, expected_num_queries1, expected_num_async_
172172
reimporter = DefaultReImporter(**reimport_options)
173173
test, _, _len_new_findings, _len_closed_findings, _, _, _ = reimporter.process_scan(scan)
174174

175-
# patch the we_want_async decorator to always return True so we don't depend on block_execution flag shenanigans
176-
# @patch("dojo.decorators.we_want_async", return_value=True)
177-
# def test_import_reimport_reimport_performance_async(self, mock):
178175
@override_settings(ENABLE_AUDITLOG=True, AUDITLOG_TYPE="django-auditlog")
179176
def test_import_reimport_reimport_performance_async(self):
180177
# Ensure django-auditlog is properly configured for this test
@@ -191,38 +188,27 @@ def test_import_reimport_reimport_performance_async(self):
191188
expected_num_async_tasks3=20,
192189
)
193190

194-
# @patch("dojo.decorators.we_want_async", return_value=False)
195-
# def test_import_reimport_reimport_performance_no_async(self, mock):
196-
@override_settings(ENABLE_AUDITLOG=True, AUDITLOG_TYPE="django-auditlog")
197-
def test_import_reimport_reimport_performance_no_async(self):
191+
@override_settings(ENABLE_AUDITLOG=True, AUDITLOG_TYPE="django-pghistory")
192+
def test_import_reimport_reimport_performance_pghistory_async(self):
198193
"""
199-
This test checks the performance of the importers when they are run in sync mode.
200-
The reason for this is that we also want to be aware of when a PR affects the number of queries
201-
or async tasks created by a background task.
202-
The impersonate context manager above does not work as expected for disabling async,
203-
so we patch the we_want_async decorator to always return False.
194+
This test checks the performance of the importers when using django-pghistory with async enabled.
195+
Query counts will need to be determined by running the test initially.
204196
"""
205-
# Ensure django-auditlog is properly configured for this test
206197
from dojo.auditlog import configure_audit_system, configure_pghistory_triggers
207198
configure_audit_system()
208199
configure_pghistory_triggers()
209200

210-
testuser = User.objects.get(username="admin")
211-
testuser.usercontactinfo.block_execution = True
212-
testuser.usercontactinfo.save()
213201
self.import_reimport_performance(
214-
expected_num_queries1=682,
202+
expected_num_queries1=648,
215203
expected_num_async_tasks1=10,
216-
expected_num_queries2=615,
204+
expected_num_queries2=603,
217205
expected_num_async_tasks2=22,
218-
expected_num_queries3=297,
206+
expected_num_queries3=287,
219207
expected_num_async_tasks3=20,
220208
)
221209

222-
# @patch("dojo.decorators.we_want_async", return_value=False)
223-
# def test_import_reimport_reimport_performance_no_async_with_product_grading(self, mock):
224210
@override_settings(ENABLE_AUDITLOG=True, AUDITLOG_TYPE="django-auditlog")
225-
def test_import_reimport_reimport_performance_no_async_with_product_grading(self):
211+
def test_import_reimport_reimport_performance_no_async(self):
226212
"""
227213
This test checks the performance of the importers when they are run in sync mode.
228214
The reason for this is that we also want to be aware of when a PR affects the number of queries
@@ -238,57 +224,63 @@ def test_import_reimport_reimport_performance_no_async_with_product_grading(self
238224
testuser = User.objects.get(username="admin")
239225
testuser.usercontactinfo.block_execution = True
240226
testuser.usercontactinfo.save()
241-
self.system_settings(enable_product_grade=True)
242-
243227
self.import_reimport_performance(
244-
expected_num_queries1=666,
228+
expected_num_queries1=682,
245229
expected_num_async_tasks1=10,
246-
expected_num_queries2=630,
230+
expected_num_queries2=615,
247231
expected_num_async_tasks2=22,
248-
expected_num_queries3=312,
232+
expected_num_queries3=297,
249233
expected_num_async_tasks3=20,
250234
)
251235

252-
# New pghistory performance tests
253236
@override_settings(ENABLE_AUDITLOG=True, AUDITLOG_TYPE="django-pghistory")
254-
def test_import_reimport_reimport_performance_pghistory_async(self):
237+
def test_import_reimport_reimport_performance_pghistory_no_async(self):
255238
"""
256-
This test checks the performance of the importers when using django-pghistory with async enabled.
239+
This test checks the performance of the importers when using django-pghistory with async disabled.
257240
Query counts will need to be determined by running the test initially.
258241
"""
259242
from dojo.auditlog import configure_audit_system, configure_pghistory_triggers
260243
configure_audit_system()
261244
configure_pghistory_triggers()
262245

246+
testuser = User.objects.get(username="admin")
247+
testuser.usercontactinfo.block_execution = True
248+
testuser.usercontactinfo.save()
249+
263250
self.import_reimport_performance(
264251
expected_num_queries1=648,
265252
expected_num_async_tasks1=10,
266-
expected_num_queries2=603,
253+
expected_num_queries2=608,
267254
expected_num_async_tasks2=22,
268-
expected_num_queries3=287,
255+
expected_num_queries3=292,
269256
expected_num_async_tasks3=20,
270257
)
271258

272-
@override_settings(ENABLE_AUDITLOG=True, AUDITLOG_TYPE="django-pghistory")
273-
def test_import_reimport_reimport_performance_pghistory_no_async(self):
259+
@override_settings(ENABLE_AUDITLOG=True, AUDITLOG_TYPE="django-auditlog")
260+
def test_import_reimport_reimport_performance_no_async_with_product_grading(self):
274261
"""
275-
This test checks the performance of the importers when using django-pghistory with async disabled.
276-
Query counts will need to be determined by running the test initially.
262+
This test checks the performance of the importers when they are run in sync mode.
263+
The reason for this is that we also want to be aware of when a PR affects the number of queries
264+
or async tasks created by a background task.
265+
The impersonate context manager above does not work as expected for disabling async,
266+
so we patch the we_want_async decorator to always return False.
277267
"""
268+
# Ensure django-auditlog is properly configured for this test
278269
from dojo.auditlog import configure_audit_system, configure_pghistory_triggers
279270
configure_audit_system()
280271
configure_pghistory_triggers()
281272

282273
testuser = User.objects.get(username="admin")
283274
testuser.usercontactinfo.block_execution = True
284275
testuser.usercontactinfo.save()
276+
self.system_settings(enable_product_grade=True)
285277

286278
self.import_reimport_performance(
287-
expected_num_queries1=648,
279+
expected_num_queries1=666,
288280
expected_num_async_tasks1=10,
289-
expected_num_queries2=608,
281+
expected_num_queries2=630,
290282
expected_num_async_tasks2=22,
291-
expected_num_queries3=292,
283+
expected_num_queries3=312,
292284
expected_num_async_tasks3=20,
293285
)
294286

0 commit comments

Comments
 (0)