Skip to content

tests: Fix race condition in one of the Scan Sbom tests#931

Open
matejnesuta wants to merge 3 commits intoguacsec:mainfrom
matejnesuta:ui-test-fix
Open

tests: Fix race condition in one of the Scan Sbom tests#931
matejnesuta wants to merge 3 commits intoguacsec:mainfrom
matejnesuta:ui-test-fix

Conversation

@matejnesuta
Copy link
Contributor

@matejnesuta matejnesuta commented Feb 24, 2026

This PR fixes Scan SBOM test, which tests cancelling of the SBOM analysis.

Even though this test passes on the Github CI, it was occasionally failing on my local setup. There is slight chance that the Scan Sbom result page loads faster than Playwright is able to query the locators for aborting the analysis, which causes the test to flake. Given that Trustify on OCP/RHEL should be faster than in the Github CI, I think it is reasonable to expect this flake on downstream builds as well.

This fix merges 2 Gherkin steps together and adds a page.route() mechanism, which delays any network request on the loading page by 10 seconds, allowing Playwright to properly query the Cancel Report button.

Summary by Sourcery

Tests:

  • Update the SBOM scan cancellation scenario to use a single Gherkin step that both verifies the processing spinner and triggers cancellation, reducing timing-related flakiness.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 24, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors the SBOM scan cancellation E2E test to merge spinner verification and cancel action into a single step, and introduces Playwright request routing to delay API calls so the cancel button can be reliably located and clicked, eliminating a race condition-induced flake.

File-Level Changes

Change Details Files
Merge spinner verification and cancel action into a single Playwright step that also manages network routing to keep the page in a processing state.
  • Replace the previous Then step that only asserted the spinner with a When step that both verifies the processing spinner and clicks the cancel control.
  • Instantiate the SbomScanPage once in the combined step and reuse it for both expectations and the cancel action.
  • Update Gherkin step text and parameter ordering to reflect that the user cancels the report generation by clicking the cancel label while a specific header message is shown.
e2e/tests/ui/features/@sbom-scan/scan-sbom.step.ts
e2e/tests/ui/features/@sbom-scan/scan-sbom.feature
Introduce Playwright routing in the test step to delay API responses and avoid race conditions when locating the cancel button.
  • Add page.route for the '/api/' pattern that delays all matching network requests by 10 seconds before continuing, ensuring the page remains in a processing state long enough to interact with the cancel UI.
  • Call scanPage.expectProcessingSpinner while the API requests are blocked to assert the header and cancel label in the spinner UI.
  • Invoke scanPage.clickCancelProcessing to abort the operation while routes are still active, matching the intended behavior being tested.
  • Clean up network interception after cancellation via page.unroute('/api/') to avoid side effects on subsequent steps or scenarios.
e2e/tests/ui/features/@sbom-scan/scan-sbom.step.ts
Remove the now-redundant Gherkin step and implementation that separately clicked the cancel link.
  • Delete the standalone 'User Clicks on "{string}" link' step definition that called clickCancelProcessing.
  • Simplify the feature scenario by replacing the two-step spinner-then-cancel sequence with the new single cancellation step.
  • Ensure the scenario flow still navigates back to the Generate Vulnerability Report screen after cancellation using the existing Then step.
e2e/tests/ui/features/@sbom-scan/scan-sbom.step.ts
e2e/tests/ui/features/@sbom-scan/scan-sbom.feature

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider wrapping the page.route/page.unroute calls in a try/finally block so the route is always removed even if expectProcessingSpinner or clickCancelProcessing throws, preventing the handler from leaking into later steps.
  • Routing **/api/** with a hard-coded 10s delay is quite broad and slow; you might want to narrow the URL pattern to only the specific SBOM-related request(s) and/or reduce the delay to the minimum needed to reliably click cancel.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider wrapping the `page.route`/`page.unroute` calls in a `try/finally` block so the route is always removed even if `expectProcessingSpinner` or `clickCancelProcessing` throws, preventing the handler from leaking into later steps.
- Routing `**/api/**` with a hard-coded 10s delay is quite broad and slow; you might want to narrow the URL pattern to only the specific SBOM-related request(s) and/or reduce the delay to the minimum needed to reliably click cancel.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.01%. Comparing base (2aed836) to head (f642d57).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #931      +/-   ##
==========================================
+ Coverage   64.47%   65.01%   +0.53%     
==========================================
  Files         195      195              
  Lines        3341     3341              
  Branches      753      753              
==========================================
+ Hits         2154     2172      +18     
+ Misses        890      872      -18     
  Partials      297      297              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant