Skip to content

Commit 10e6371

Browse files
add dummy import to warm up content_type cache
1 parent 3ee8729 commit 10e6371

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

unittests/dojo_test_case.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def system_settings(
9797
enable_jira_web_hook=False,
9898
disable_jira_webhook_secret=False,
9999
jira_webhook_secret=None,
100+
enable_github=False,
100101
enable_product_tag_inehritance=False,
101102
enable_product_grade=True,
102103
enable_webhooks_notifications=True,
@@ -106,6 +107,7 @@ def system_settings(
106107
ss.enable_jira_web_hook = enable_jira_web_hook
107108
ss.disable_jira_webhook_secret = disable_jira_webhook_secret
108109
ss.jira_webhook_secret = jira_webhook_secret
110+
ss.enable_github = enable_github
109111
ss.enable_product_tag_inheritance = enable_product_tag_inehritance
110112
ss.enable_product_grade = enable_product_grade
111113
ss.enable_webhooks_notifications = enable_webhooks_notifications

unittests/test_importers_performance.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
STACK_HAWK_SUBSET_FILENAME = get_unit_tests_scans_path("stackhawk") / "stackhawk_many_vul_without_duplicated_findings_subset.json"
1919
STACK_HAWK_SCAN_TYPE = "StackHawk HawkScan"
2020

21+
NPM_AUDIT_NO_VULN_FILENAME = get_unit_tests_scans_path("npm_audit") / "no_vuln.json"
22+
NPM_AUDIT_SCAN_TYPE = "NPM Audit Scan"
23+
2124

2225
class TestDojoImporterPerformance(DojoTestCase):
2326

2427
def setUp(self):
2528
super().setUp()
2629
self.system_settings(enable_webhooks_notifications=False)
2730
self.system_settings(enable_product_grade=False)
31+
self.system_settings(enable_github=False)
2832

2933
@contextmanager
3034
def assertNumAsyncTask(self, num):
@@ -66,6 +70,30 @@ def import_reimport_performance(self, expected_num_queries1, expected_num_async_
6670
lead, _ = User.objects.get_or_create(username="admin")
6771
environment, _ = Development_Environment.objects.get_or_create(name="Development")
6872

73+
# first we do a bogus import to make sure any caches are loaded.
74+
# without this the number of queries will be higher as the audit log will load content_type ids from the db
75+
76+
engagement_dummy, _created = Engagement.objects.get_or_create(
77+
name="Test Create Dummy Engagement",
78+
product=product,
79+
target_start=timezone.now(),
80+
target_end=timezone.now(),
81+
)
82+
import_options = {
83+
"user": lead,
84+
"lead": lead,
85+
"scan_date": None,
86+
"environment": environment,
87+
"minimum_severity": "Info",
88+
"active": True,
89+
"verified": True,
90+
"sync": True,
91+
"scan_type": NPM_AUDIT_SCAN_TYPE,
92+
"engagement": engagement_dummy,
93+
}
94+
importer = DefaultImporter(**import_options)
95+
test, _, _len_new_findings, _len_closed_findings, _, _, _ = importer.process_scan(NPM_AUDIT_NO_VULN_FILENAME.open(encoding="utf-8"))
96+
6997
# first import the subset which missed one finding and a couple of endpoints on some of the findings
7098
with (
7199
self.subTest("import1"), impersonate(Dojo_User.objects.get(username="admin")),
@@ -132,7 +160,7 @@ def import_reimport_performance(self, expected_num_queries1, expected_num_async_
132160

133161
def test_import_reimport_reimport_performance(self):
134162
self.import_reimport_performance(
135-
expected_num_queries1=603,
163+
expected_num_queries1=605,
136164
expected_num_async_tasks1=15,
137165
expected_num_queries2=489,
138166
expected_num_async_tasks2=23,
@@ -169,7 +197,7 @@ def test_import_reimport_reimport_performance_no_async_with_product_grading(self
169197
"""
170198
self.system_settings(enable_product_grade=True)
171199
self.import_reimport_performance(
172-
expected_num_queries1=673,
200+
expected_num_queries1=675,
173201
expected_num_async_tasks1=25,
174202
expected_num_queries2=544,
175203
expected_num_async_tasks2=30,

0 commit comments

Comments
 (0)