Skip to content

fix: replace TCP readiness check with signal file to fix flaky Linux test#59

Merged
tablackburn merged 3 commits into
mainfrom
fix/flaky-filedownload-integration-test
May 25, 2026
Merged

fix: replace TCP readiness check with signal file to fix flaky Linux test#59
tablackburn merged 3 commits into
mainfrom
fix/flaky-filedownload-integration-test

Conversation

@tablackburn
Copy link
Copy Markdown
Owner

@tablackburn tablackburn commented May 22, 2026

Reviving forgotten work

This restores a fix you authored on 2026-02-24 (85de79c) that was committed onto the pre-commit-ci-update-config bot branch and never merged — it's not in main. Cherry-picked cleanly onto current main (the integration-test file hasn't diverged since).

What it does

Replaces a TCP readiness check with a signal-file approach in Private/FileDownload.Integration.tests.ps1 (+24/−21) to fix a flaky Linux integration test.

Why now

We hit a flaky download test on Plex #55 (Failed to download file… connection forcibly closed) while reviewing the test-scaffolding PR — this forgotten fix targets that same FileDownload test flakiness, so it's worth landing.

Note

Original work is 3 months old; worth a fresh look to confirm it's still the right approach against current main before merging. CI (incl. integration, if it runs here) will exercise it.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Improved internal test infrastructure and reliability mechanisms for integration testing.

Note: This release contains no user-facing changes.

Review Change Stack

…test

Wait-ServerReady used a TCP socket connect check that succeeded as soon
as HttpListener.Start() opened the port. On Linux, the background job
had not yet called GetContextAsync(), so the test HTTP request arrived
before the listener was ready, causing intermittent failures.

Replace with a signal file approach: the background job writes a temp
file after entering GetContextAsync(), and the parent polls for that
file. This is deterministic and eliminates the race condition.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
(cherry picked from commit 85de79c)
Copilot AI review requested due to automatic review settings May 22, 2026 23:18
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Warning

Review limit reached

@tablackburn, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 48 minutes and 43 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 66f546f2-1ece-4a63-912a-9d06344351db

📥 Commits

Reviewing files that changed from the base of the PR and between 86cbc4e and 52dd7bb.

📒 Files selected for processing (1)
  • tests/Integration/Private/FileDownload.Integration.tests.ps1
📝 Walkthrough

Walkthrough

FileDownload.Integration.tests.ps1 replaces TCP port polling with filesystem signal file polling for HTTP server readiness detection. The Wait-ServerReady helper now waits for a signal file, Start-TestHttpServerJob generates and passes a unique signal file path to the background job, the job writes the file after starting the listener, and the caller waits for the file and removes it.

Changes

HTTP Server Readiness Signaling

Layer / File(s) Summary
Readiness signal helper
tests/Integration/Private/FileDownload.Integration.tests.ps1
Wait-ServerReady now takes a SignalFile path and polls for file existence until timeout instead of checking TCP port connectivity.
Server job setup and caller wait
tests/Integration/Private/FileDownload.Integration.tests.ps1
Start-TestHttpServerJob generates a unique signal file path per invocation, passes it into the background job, waits for the file to appear, and cleans up the file afterward; replaces prior port-based polling and warning logic.
Background job readiness signal
tests/Integration/Private/FileDownload.Integration.tests.ps1
The background job starts HttpListener.GetContextAsync() and then writes the signal file to indicate readiness to accept requests.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A signal file awaits, no sockets to poll,
The server hops ready, the test script in control.
File-based timing beats TCP's old game—
Simpler, cleaner, more reliable fame! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the main change: replacing a TCP readiness check with a signal file to fix a flaky Linux test, which matches the core objective of the PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/flaky-filedownload-integration-test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the integration-test HTTP server “readiness” mechanism to eliminate a race condition on Linux by switching from a TCP connect probe to a signal-file handshake, improving determinism for Invoke-PatFileDownload integration tests.

Changes:

  • Replace TCP-port polling readiness check with polling for a temp “ready” signal file.
  • Signal readiness from the server job only after entering GetContextAsync() to prevent request/accept races.
  • Fail fast if readiness isn’t reached within timeout (instead of warning).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/Integration/Private/FileDownload.Integration.tests.ps1
Comment thread tests/Integration/Private/FileDownload.Integration.tests.ps1
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/Integration/Private/FileDownload.Integration.tests.ps1`:
- Around line 135-144: Wrap the readiness check and throw in a try/finally so
the signal file is always removed: call Wait-ServerReady (using the existing
$readySignalFile and $Port) inside a try block, throw if $ready is $false, and
perform the Test-Path / Remove-Item cleanup in the finally block to guarantee
removal even on timeout or exceptions; reference the existing symbols
Wait-ServerReady, $readySignalFile, Remove-Item and the throw that currently
short-circuits cleanup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6ed63a06-6627-4eb2-a184-8ec6b2a00775

📥 Commits

Reviewing files that changed from the base of the PR and between a083b14 and 86cbc4e.

📒 Files selected for processing (1)
  • tests/Integration/Private/FileDownload.Integration.tests.ps1

Comment thread tests/Integration/Private/FileDownload.Integration.tests.ps1 Outdated
Wrap the readiness wait in Start-TestHttpServerJob with try/catch/finally so a
startup that times out no longer leaks resources:

- The catch stops and removes the background job, releasing the HttpListener and
  its 30-second GetContextAsync wait instead of orphaning the job.
- The finally always removes the readiness signal file, even when the wait times
  out and throws.
- Add ValidateNotNullOrEmpty to the Wait-ServerReady SignalFile parameter.

Addresses review feedback on the integration test scaffolding.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@tablackburn tablackburn merged commit 09b763f into main May 25, 2026
15 checks passed
@tablackburn tablackburn deleted the fix/flaky-filedownload-integration-test branch May 25, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants