Add E2E tests for aggregation, fix race condition by DaveTryon · Pull Request #1141 · microsoft/sbom-tool (original) (raw)
The bulk of this change is adding an E2E test to exercise aggregation. It aggregates only 1 source SBOM, with the hope that we can later add a second case with more than 1 source SBOM. While adding this, a race condition was discovered--the call to ISbomConfigProvider.ClearCache was sometimes being called before the Task.Run calls in FileHasher.Run had completed, leading to an Exception being thrown. Shout-out to @sfoslund for providing a fix that was tightly scoped and didn't involve extensive plumbing changes to make FileHasher.Run--and it entire calling stack--fully async.
Some changes were needed to the FileHasher unit tests, since the test now needs to include execution of the code inside the Task.Run block. These changes fell into 2 categories:
- Populate the
filesobject before calling theFileHasher.Run(I put this into a helper method since needed this in multiple places). - Use deconstruction because the analyzer was complaining without it.