Fix flaky jobs_spec download artifacts example

What does this MR do and why?

Fixes the top pipeline-blocking flaky signature for spec/features/projects/jobs_spec.rb (undefined method `response_headers' for nil, 76% of failures), reported in gitlab-org/quality/test-failure-issues#43198+s.

Root cause

The example "downloads the zip file when user clicks the download button" (jobs_spec.rb:303) does:

requests = inspect_requests do
  click_link 'Download'
end
artifact_request = requests.find { |req| req.url.include?('artifacts/download') }
expect(artifact_request.response_headers[...]) # raises on nil

click_link 'Download' triggers a browser-initiated download and returns immediately without waiting for it. inspect_requests then calls wait_for_all_requests, which can observe zero active rack requests because the download has not started yet, and returns before the request is logged. requests.find then returns nil and the assertion raises on nil.response_headers.

The other inspect_requests blocks in this file use a synchronous visit, so they do not race this way.

Fix

Wait inside the inspect_requests block until the artifacts download request has actually been logged before reading it, following the act → wait on a deterministic post-completion signal → assert shape:

click_link 'Download'

wait_for('artifact download request') do
  Gitlab::Testing::RequestInspectorMiddleware.requests.any? do |req|
    req.url.include?('artifacts/download')
  end
end

Verification

  • The example passed 6/6 consecutive isolated runs.
  • The whole Download artifacts context (2 examples) passed.
  • RuboCop and commit-message lint pass.

Related to gitlab-org/quality/test-failure-issues#43198+s

🤖 Generated with Claude Code

Edited by Rémy Coutable

Merge request reports

Loading