-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FossIdTest improvements #5797
FossIdTest improvements #5797
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5797 +/- ##
=========================================
Coverage 57.71% 57.71%
Complexity 2190 2190
=========================================
Files 321 321
Lines 18989 18989
Branches 3730 3730
=========================================
Hits 10960 10960
Misses 6887 6887
Partials 1142 1142
Flags with carried forward coverage won't be shown. Click here to find out more. Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -676,9 +676,10 @@ class FossIdTest : WordSpec({ | |||
|
|||
val fossId = createFossId(config) | |||
|
|||
val scannerRun = fossId.scan(listOf(pkg1, pkg2)) | |||
fossId.scan(listOf(pkg1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this line then need to be kept at all? I currently don't see an assertion that would depend on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How I understand the test the last check coVerify { service.deleteScan(USER, API_KEY, scanCode) }
verifies that the scan of pkg1
gets deleted as well if the scan of pkg2
fails. But to be honest, I had a hard time coming to that conclusion and the whole test class seems a bit too complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sschuberth this is required by scannerRun.results.scanResults.keys shouldHaveSize 1
If one scan fails, other successful scans should be deleted hence there should be no result for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, I think theses changes are wrong @mnonnenmacher : now there a two scanner runs.
The first one is successful. The second one fails. However since these are two separate runs, the first scan is not deleted anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test does not fail which shows the other scan is deleted. The reason is that the same instance of FossId
is used and createdScans
(which is used as input when deleting scans) is a class variable. However, if the scans would be triggered the other way round it would probably not work. It seems an interface change is required, but I'm also a bit surprised that this comes up only now since it's running like this for several months now on our side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
PackageScannerWrapper
interface needs to be adapted to take a list of packages
I was wondering whether that doesn't make sense anyway, as it could allow for some significant scanner-implementation-internal performance improvements. A bit similar to how I changed PackageCurationProvider
to take collection of packages in 0592a68.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nnobelis So I had a look at the current implementation, especially these two places:
ort/scanner/src/main/kotlin/scanners/fossid/FossId.kt
Lines 314 to 318 in 1258f27
val scanCode = if (config.deltaScans) { checkAndCreateDeltaScan(scans, url, revision, projectCode, projectName) } else { checkAndCreateScan(scans, url, revision, projectCode, projectName) } ort/scanner/src/main/kotlin/scanners/fossid/FossId.kt
Lines 351 to 355 in 1258f27
if (!config.keepFailedScans) { createdScans.forEach { code -> logger.warn { "Deleting scan '$code' during exception cleanup." } deleteScan(code) } Both are inside a loop over the packages to scan, so if I read the code correctly the behavior was always like this, that scans started before a failed scan would be deleted, but other scans could still be started after a failed scan. Is this an issue that needs to be fixed or is the current code working correctly?
Yes I think you find a bug. Originally, the logic was to delete the scan in the catch
and let the exception bubble up. Then somebody came with "it should not throw an exception, it should create an ortIssue
instead.
But you are right, if a scan fails all successful scans should be deleted (if the option is set !) and no further scan should be created.
If the option is not set, successful scans should be kept and further scans should be run.
Makes sense ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will propose a fix in a separate PR and update this PR afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nnobelis For now I have only added a commit that changes the test to illustrate the issue which also shows that this refactoring does not change the behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
PackageScannerWrapper
interface needs to be adapted to take a list of packagesI was wondering whether that doesn't make sense anyway, as it could allow for some significant scanner-implementation-internal performance improvements. A bit similar to how I changed
PackageCurationProvider
to take collection of packages in 0592a68.
This might be, but this requires changes in ExperimentalScanner
and because our only PackageScannerWrapper
implementation FossId
does not do any such optimizations I would not want to work on this before we have an actual use case.
23b8644
to
fc1aeec
Compare
@@ -676,9 +676,10 @@ class FossIdTest : WordSpec({ | |||
|
|||
val fossId = createFossId(config) | |||
|
|||
val scannerRun = fossId.scan(listOf(pkg1, pkg2)) | |||
fossId.scan(listOf(pkg1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, I think theses changes are wrong @mnonnenmacher : now there a two scanner runs.
The first one is successful. The second one fails. However since these are two separate runs, the first scan is not deleted anymore.
Please see my comment, I think changing the signature of |
If `keepFailedScans` is set to `false`, all scans should be deleted if a single scan fails. Change `FossIdTest` to show that currently scans started after a failed scan are not deleted. Signed-off-by: Martin Nonnenmacher <[email protected]>
Refactor the test that tests the deletion of a failed scan to call the scan function separately for the two packages. This is a preparation for changing the scan function to take only one package instead of a list. Calling the scan functions for the packages separately works because `FossId` stores the relevant information for deleting scans in class properties. Signed-off-by: Martin Nonnenmacher <[email protected]>
Change the scan function to take a single package instead of a list to prepare an upcoming refactoring where `FossId` will be changed to implement only the `PackageScannerWrapper` interface which scans packages individually. Signed-off-by: Martin Nonnenmacher <[email protected]>
Run the `FossId.scanPackages()` directly instead of through the `Scanner` class. This simplifies the test code and eases the migration of the `FossId` class to support only the experimental scanner. Signed-off-by: Martin Nonnenmacher <[email protected]>
fc1aeec
to
e13b6e6
Compare
@sschuberth @nnobelis Would one of you mind approving this or is there something left to do? |
See the commit messages for details. This is preparation for removing the legacy scanner.