Repository navigation
Retry telemetry receiver test setup when a probed port is taken - #146
Merged
Merged
Conversation
The receiver and packet diagnostics tests probe a free UDP port, close the probe, then start the receiver on that port. A parallel test can bind the port in between, so the start fails with AddressAlreadyInUse even though nothing is wrong with the receiver. Start and restart now pick a fresh port and retry on that error only, matching the existing helpers in the capture and observer tests. The occupied-port cases still bind the port they reserve. The released-port checks accept a refused probe when the port is no longer bound on loopback, since another test can take a released port on the wildcard address.
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.
What changed
TelemetryUdpReceiverTests: every test that started or restarted the receiver on a probed port now goes throughStartOnAvailablePortAsync/RestartOnAvailablePortAsync. They probe a fresh port and retry only onSocketError.AddressAlreadyInUse, up to 8 attempts; the last failure and every other error still fail the test. This is the same patternRunDatagramCaptureTestsandTelemetryValidatedStateObserverTestsalready use.FailedRestartKeepsExistingListenerAndSettingsStateAlivenow creates its occupied-port reservation before starting the receiver, so the reservation's own port-0 bind can no longer land on the receiver's probed port. The restart onto the occupied port is unchanged and must still throwSocketException.TelemetryPacketDiagnosticsTests: the two receiver starts use the same retrying helper.SuccessfulRestartClearsSessionStateAndReleasesOldPortandDisposeReleasesPortAndPreventsRestartare unchanged.TelemetryUdpReceiver.ValidatePortstill rejects port 0, so the receiver cannot pick its own port, and this change does not alter that.Why
These tests bind a UDP socket to port 0, read the assigned port, close the socket and then call
StartAsync(port). Other test classes in the same assembly run in parallel and bind their own loopback sockets (port probes and receivers). One of them can bind the released port before the receiver does. CI run 39523189748, attempt 1 (job "Build and test", step "Check critical behavior and affected tests"), failed this way inPacketSubscriberFailureDoesNotTerminateListener:SocketException: Only one usage of each socket addressfromTelemetryUdpReceiver.CreateBoundSession(line 272), called fromStartAsync. The Telemetry project was the only test project running at that point, and the PR did not touch telemetry.A loopback socket was checked on Windows 11 against the receiver's exclusive loopback bind:
AddressAlreadyInUse.UdpClientsender auto-bound on the wildcard address does not block it.So the competing socket is another loopback probe or listener.
Checked (Windows 11, pinned SDK 8.0.426, Release, head 0629bb5 = e366e1a + main ab8ac13)
dotnet build tests/Wisp.Telemetry.Tests -c Release: 0 warnings, 0 errors.dotnet test tests/Wisp.Telemetry.Tests -c Release: 96 of 96 passed, five runs in a row.dotnet format whitespace --verify-no-changeson both changed files andgit diff --check: clean.Wisp.Telemetry.Testsfailures among them; runs that passed on a rerun are not in that list.Not verified