Skip to content

Commit

Permalink
Add unit test for the timeout on the scan functions #135
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Druez <tdruez@nexb.com>
  • Loading branch information
tdruez committed Apr 8, 2021
1 parent 5a0a722 commit 6fb93f6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Release notes
// -------------

### unreleased

- Implement timeout on the scan functions, default to 120 seconds per resources.
https://github.com/nexB/scancode.io/issues/135

### v21.4.5

- Add support for Docker and VM images using RPMs such as Fedora, CentOS, RHEL,
Expand Down
25 changes: 25 additions & 0 deletions scanpipe/tests/test_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from django.test import TestCase
from django.test import TransactionTestCase

from scancode.interrupt import TimeoutError as InterruptTimeoutError

from scanpipe.models import CodebaseResource
from scanpipe.models import DiscoveredPackage
from scanpipe.models import Project
Expand Down Expand Up @@ -244,6 +246,29 @@ def test_scanpipe_pipes_scancode_scan_file(self):
self.assertEqual(expected, list(scan_results.keys()))
self.assertEqual([], scan_errors)

def test_scanpipe_pipes_scancode_scan_file_timeout(self):
input_location = str(self.data_location / "notice.NOTICE")

with mock.patch("scancode.api.get_copyrights") as get_copyrights:
get_copyrights.side_effect = InterruptTimeoutError
scan_results, scan_errors = scancode.scan_file(input_location)

expected_errors = [
"ERROR: for scanner: copyrights:\n"
"ERROR: Processing interrupted: timeout after 120 seconds."
]
self.assertEqual(expected_errors, scan_errors)

expected = [
"licenses",
"license_expressions",
"spdx_license_expressions",
"percentage_of_license_text",
"emails",
"urls",
]
self.assertEqual(expected, list(scan_results.keys()))

def test_scanpipe_pipes_scancode_scan_file_and_save_results(self):
project1 = Project.objects.create(name="Analysis")
codebase_resource1 = CodebaseResource.objects.create(
Expand Down

0 comments on commit 6fb93f6

Please sign in to comment.