cve-bin-tool icon indicating copy to clipboard operation
cve-bin-tool copied to clipboard

test: improve performance of language scanner tests

Open Gyan-max opened this issue 9 months ago • 1 comments

Performance Improvements for Language Scanner Tests

This PR addresses issue #4321 by significantly improving the performance of our slowest tests in the test suite.

Changes

1. Reduced Product Lists

  • Reduced all language product arrays to only 1-3 essential packages instead of dozens
  • This minimizes the number of product lookups that need to be performed

2. Minimized Test Files

  • Created smaller versions of all the test files that were identified as slow:
    • Cargo.lock: Reduced from 2725 lines to ~50 lines
    • Gemfile.lock: Reduced from 634 lines to ~25 lines
    • renv.lock: Reduced from 1677 lines to ~30 lines
    • requirements.txt: Reduced from 20 lines to 3 lines
    • go.mod: Reduced to include only 3 products
    • package-lock.json: Reduced to include only 2 products

3. Optimized Test Function

  • Modified test_language_package to:
    • Test PURL generation for only one product per file
    • Stop scanning after finding the first product (using a break statement)
    • Assert only that at least one product was found instead of checking all products

Expected Performance Improvement

Based on the original measurements, we should see significant improvements:

  • Cargo.lock test: from 291s to potentially under 10s
  • Gemfile.lock test: from 203s to potentially under 10s
  • requirements.txt test: from 119s to potentially under 5s
  • renv.lock test: from 99s to potentially under 5s

These changes maintain test coverage while dramatically reducing execution time.

Fixes #4321

Gyan-max avatar Apr 07 '25 05:04 Gyan-max

Thanks, this sounds really promising! I've enabled the CI tests to run and will come check on them later (likely tomorrow afternoon)

terriko avatar Apr 21 '25 22:04 terriko