fix(xmtp_mls): stabilize flaky test_hmac_and_consent_preference_sync#3834
Draft
insipx wants to merge 1 commit into
Draft
fix(xmtp_mls): stabilize flaky test_hmac_and_consent_preference_sync#3834insipx wants to merge 1 commit into
insipx wants to merge 1 commit into
Conversation
The second consent phase of this test did not wait for alix1 to publish the consent update (SyncMetric::ConsentSent) before alix2 performed its one-shot `sync_all_welcomes_and_groups`. Because `register_interest(ConsentReceived).wait()` only waits passively on the receiver metric and never drives a re-sync, that single sync was alix2's only chance to pull the second consent. When it ran before alix1's consent message landed on the server, `sync_all_welcomes_and_groups` filtered the device-sync group out as "no new activity", so ConsentReceived never reached 2 and the test timed out with Err(Expired). Add the same ConsentSent barrier (clear -> update -> wait) the first consent phase already uses, so the receiver sync is guaranteed to observe the message. Test-only change; verified 20/20 stress runs pass. Resolves xmtp#3749 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Resolves #3749
Problem
worker::device_sync::tests::test_hmac_and_consent_preference_syncintermittently timed out waiting for theConsentReceivedmetric to reach2, panicking withErr(Expired)(previously reported as FLAKY 2/4).Root cause (test-only race)
The second consent phase did:
update_consent_stateonly queues work for alix1's device-sync worker, which publishes the consent update to the sync group asynchronously (incrementingConsentSent).register_interest(...).wait()waits passively on the receiver metric — it does not itself drive any re-sync — so alix2's singlesync_all_welcomes_and_groupscall is the only opportunity to pull the second consent. That call filters out groups with no new server activity (filter_groups_needing_sync); if alix2 syncs before alix1's consent message lands on the server, the device-sync group is filtered out, alix2 never pulls the update, andConsentReceivedstays at1until the 10s timeout.The first consent phase in the same test already guards against this by waiting for
ConsentSentbefore the receiver syncs — the second phase simply omitted the same barrier.Fix
Add the same barrier (clear → update → wait for
ConsentSent) before alix2's sync, mirroring the first-consent phase.clear_metricruns beforeupdate_consent_stateso the wait targets the Allowed publish specifically. Production code is untouched.Verification
just test v3 test_hmac_and_consent_preference_sync→ 20/20 stress runs pass.just lint-rust(clippy-Dwarnings, fmt, hakari) passes clean.🤖 Generated with Claude Code
Note
Stabilize flaky
test_hmac_and_consent_preference_syncby awaiting consent propagationThe test had a race condition where alix2's sync could run before the consent update was visible on the server, causing the
ConsentReceivedwait to fail intermittently. Fixes this by clearing theConsentSentmetric, updating consent state, then awaiting oneConsentSentevent before triggering alix2's sync in tests.rs.Macroscope summarized 856aad1.