Skip to content

[Backport release-1.19] test: stop fake servers leaking fixed ports and hanging the Windows unit tests - #1291

Merged
dapr-bot merged 4 commits into
release-1.19from
backport-1242-to-release-1.19
Oct 16, 2026
Merged

dapr-bot merged 4 commits into
release-1.19from
backport-1242-to-release-1.19

Conversation

@dapr-bot

Copy link
Copy Markdown
Collaborator

Backport 5a556c2 from #1242.

…nit tests (#1242)

* test: bind fake Dapr servers to free ports and release them on failure

The client and actor unit tests started their fake sidecars on fixed ports
(3500, 4443, 3510, 50001, 50010, 50011). FakeDaprSidecar opened its HTTP
socket in __init__ and then bound gRPC in start(). When the gRPC port was
taken (50001 sits in Windows' dynamic port range) start() raised, unittest
skipped tearDownClass, and the HTTP socket stayed listening, unserved, for
the rest of the session. HTTPServer sets SO_REUSEADDR, so on Windows the
next test could bind the same port next to it, connect to the dead socket,
and block forever in the health check.

- FakeHttpServer binds 127.0.0.1 on port 0 by default, turns off address
  reuse, runs as a daemon thread, and its shutdown works (and does not hang)
  when the thread never started. It always closes the socket.
- FakeDaprSidecar defaults both ports to 0, reads the real ports back from
  grpc and the socket, creates the HTTP server only after gRPC is up, and
  releases everything (sockets, grpc server, generated certs) if any step of
  start()/start_secure() fails. stop()/stop_secure() are idempotent.
- Every test class using the fakes registers addClassCleanup right after
  creating the server, reads the bound ports back, and points
  DAPR_HTTP_PORT/DAPR_HTTP_ENDPOINT at them, restoring the previous values
  when the class finishes.
- The three secure test modules reach their parent class through its module,
  so pytest no longer collects and runs the insecure parent a second time in
  each of them (213 duplicate runs).
- Add tests for the fakes: a failed start releases every port and returns
  from stop() promptly.

Signed-off-by: Casper Nielsen <casper@diagrid.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: assert fake server cleanup runs once and mark the reuse test as Windows-only

Signed-off-by: Casper Nielsen <casper@diagrid.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: cover cancelled subscription streams directly

The CANCELLED branch in Subscription.next_message and the matching break in
subscribe_with_handler were only covered by chance, when a test's fake
sidecar shut down under a live stream. With the fake servers now stopped
cleanly, those lines went uncovered. Test both paths against a fake call
instead of relying on teardown timing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Casper Nielsen <casper@diagrid.io>

* test: capture the streaming thread without patching threading.Thread globally

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Casper Nielsen <casper@diagrid.io>

* test: cover secure HTTP start failing after certificates are created

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Casper Nielsen <casper@diagrid.io>

---------

Signed-off-by: Casper Nielsen <casper@diagrid.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 5a556c2)
Signed-off-by: dapr-bot <dapr-bot@users.noreply.github.com>
@dapr-bot
dapr-bot requested review from a team as code owners October 15, 2026 15:43
@CasperGN CasperGN self-assigned this Oct 15, 2026
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release-1.19@f6c110f). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff               @@
##             release-1.19    #1291   +/-   ##
===============================================
  Coverage                ?   86.70%           
===============================================
  Files                   ?      163           
  Lines                   ?    12931           
  Branches                ?        0           
===============================================
  Hits                    ?    11212           
  Misses                  ?     1719           
  Partials                ?        0           

☔ View full report in Codecov by Harness.
📢 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.

@sicoyle sicoyle added automerge allows dapr bot to merge a PR after tests pass autoupdate labels Oct 16, 2026
@dapr-bot
dapr-bot enabled auto-merge (squash) October 16, 2026 13:37
@dapr-bot
dapr-bot merged commit 8de4dd3 into release-1.19 Oct 16, 2026
22 checks passed
@dapr-bot
dapr-bot deleted the backport-1242-to-release-1.19 branch October 16, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge allows dapr bot to merge a PR after tests pass autoupdate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants