fix(tui): isolate i18n locale in tests to eliminate parallel flake#152
Merged
Conversation
The process-global rust_i18n locale caused flaky failures under parallel test execution. Tests such as render_expired_badge_in_list and sync_indicator_ascii_fallbacks held no locale guard, so they could read a locale mutated by a concurrent zh-CN guard holder and assert the wrong localized text. Root cause: LocaleGuard serialized only guard holders via a std::sync::Mutex. Tests that depended on the locale without holding a guard raced against those that did, and the non-reentrant mutex precluded nesting. Changes: - i18n: LOCALE_LOCK is now a parking_lot::ReentrantMutex so a manual LocaleGuard can nest inside a render-helper guard without deadlocking. - list tests: render_snapshot/render_buffer gain _locale variants that hold an internal LocaleGuard (default delegates to "en"). The two zh-CN timestamp tests are migrated to render_buffer_locale(.., "zh-CN"). - Add a deterministic concurrent-isolation test (proves en renders stay correct under concurrent zh-CN guard holders) and a localized-helper contract test (en "Expired" / zh-CN "已过期"). - Add LocaleGuard::en() to 85 locale-dependent tests across 14 files that previously had no guard. Verified: cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test (2595 + all integration/snapshot/e2e) run 3x, cargo build --release --bin ok, cargo audit (0 vulnerabilities). render_expired_badge_in_list and sync_indicator_ascii_fallbacks are now stable across runs.
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.
Problem
The process-global
rust_i18nlocale caused flaky failures under parallel test execution (e.g.render_expired_badge_in_list,sync_indicator_ascii_fallbacks). These tests held no locale guard, so they could read a locale mutated by a concurrent zh-CN guard holder and assert the wrong localized text.Root cause
LocaleGuardserialized only guard holders via astd::sync::Mutex. Tests that depended on the locale without holding a guard raced against those that did — and the non-reentrant mutex made nesting (manual guard + helper guard) deadlock.Fix
i18n:LOCALE_LOCK→parking_lot::ReentrantMutex— guards can nest without deadlock; concurrent locale-sensitive tests still serialize across threads.listtests:render_snapshot/render_buffergain_localevariants that hold an internalLocaleGuard(default delegates to"en"). The two zh-CN timestamp tests migrate torender_buffer_locale(.., "zh-CN").Expired/ zh-CN已过期).LocaleGuard::en().Verification (CI gate, all green)
cargo fmt --check✅cargo clippy --all-targets -- -D warnings✅cargo test(2595 + all integration / snapshot / e2e) — run 3×, stable ✅cargo build --release --bin ok✅cargo audit— 0 vulnerabilities ✅ (1 pre-existing allowedaesyank viakeepass, unrelated)render_expired_badge_in_listandsync_indicator_ascii_fallbacksare now stable across runs.Test-infrastructure only; not user-visible, so no version bump.