pairing: Add retry logic to get_pairing_data to fix flaky test#664
Merged
pairing: Add retry logic to get_pairing_data to fix flaky test#664
Conversation
The test_pairing_session test was flaky due to a race condition in the pairing protocol. The NewDeviceClient generates the device_id locally and sends it via the QR code channel before the PairDevice gRPC request reaches the server. When the AttestationDeviceClient immediately calls GetPairingData with that device_id, the session might not exist yet. This adds retry logic to get_pairing_data that retries for up to 10 seconds with 100ms intervals, handling the inherent race condition in the pairing protocol.
2a35ca6 to
e28f79d
Compare
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.
Summary
The
test_pairing_sessiontest was flaky due to a race condition in the pairing protocol.Problem
The
NewDeviceClientgenerates thedevice_idlocally and sends it via the QR code channel before thePairDevicegRPC request reaches the server. When theAttestationDeviceClientimmediately callsGetPairingDatawith thatdevice_id, the session might not exist on the server yet, causing aKeyError.The race happens because:
device_id) to the channel firstSolution
Add retry logic to
get_pairing_datain theAttestationDeviceClientthat retries for up to 10 seconds with 100ms intervals. This handles the inherent race condition in the pairing protocol where the attestation device may receive the QR code before the new device'sPairDevicerequest has been processed by the server.Testing
Verified with flaky test plugin - passed 10 out of 10 runs: