Repository navigation
[Backport release-1.19] test: stop fake servers leaking fixed ports and hanging the Windows unit tests - #1291
Merged
Merged
Conversation
…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>
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
sicoyle
approved these changes
Oct 16, 2026
dapr-bot
enabled auto-merge (squash)
October 16, 2026 13:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport 5a556c2 from #1242.