Skip to content

Commit e5d56d5

Browse files
warmup cache better
1 parent 2617bfd commit e5d56d5

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

unittests/test_importers_performance.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@
88
from dojo.decorators import dojo_async_task_counter
99
from dojo.importers.default_importer import DefaultImporter
1010
from dojo.importers.default_reimporter import DefaultReImporter
11-
from dojo.models import Development_Environment, Dojo_User, Engagement, Product, Product_Type, User
11+
from dojo.models import (
12+
Development_Environment,
13+
Dojo_User,
14+
Endpoint,
15+
Endpoint_Status,
16+
Engagement,
17+
Finding,
18+
Product,
19+
Product_Type,
20+
User,
21+
)
1222

1323
from .dojo_test_case import DojoTestCase, get_unit_tests_scans_path
1424

@@ -18,7 +28,7 @@
1828
STACK_HAWK_SUBSET_FILENAME = get_unit_tests_scans_path("stackhawk") / "stackhawk_many_vul_without_duplicated_findings_subset.json"
1929
STACK_HAWK_SCAN_TYPE = "StackHawk HawkScan"
2030

21-
NPM_AUDIT_NO_VULN_FILENAME = get_unit_tests_scans_path("npm_audit") / "no_vuln.json"
31+
NPM_AUDIT_NO_VULN_FILENAME = get_unit_tests_scans_path("npm_audit") / "one_vuln.json"
2232
NPM_AUDIT_SCAN_TYPE = "NPM Audit Scan"
2333

2434

@@ -94,6 +104,21 @@ def import_reimport_performance(self, expected_num_queries1, expected_num_async_
94104
importer = DefaultImporter(**import_options)
95105
test, _, _len_new_findings, _len_closed_findings, _, _, _ = importer.process_scan(NPM_AUDIT_NO_VULN_FILENAME.open(encoding="utf-8"))
96106

107+
# if True:
108+
# exit(0) # this is to make sure the importers are not run when running the tests in the IDE, as it will take too long
109+
110+
finding = Finding.objects.filter(test=test).first()
111+
112+
endpoint = Endpoint.objects.create(host="foo.bar", product=product)
113+
Endpoint_Status.objects.create(
114+
finding=finding,
115+
endpoint=endpoint,
116+
)
117+
118+
finding.endpoints.add(endpoint)
119+
finding.title = "Dummy finding to ensure audit log is created"
120+
finding.save()
121+
97122
# first import the subset which missed one finding and a couple of endpoints on some of the findings
98123
with (
99124
self.subTest("import1"), impersonate(Dojo_User.objects.get(username="admin")),
@@ -160,7 +185,7 @@ def import_reimport_performance(self, expected_num_queries1, expected_num_async_
160185

161186
def test_import_reimport_reimport_performance(self):
162187
self.import_reimport_performance(
163-
expected_num_queries1=605,
188+
expected_num_queries1=602,
164189
expected_num_async_tasks1=15,
165190
expected_num_queries2=489,
166191
expected_num_async_tasks2=23,

0 commit comments

Comments
 (0)