Visitar URL original
fix: let two tests render under t.Parallel without racing by janosmiko · Pull Request #671 · janosmiko/lfk · GitHub
Skip to content

fix: let two tests render under t.Parallel without racing - #671

Merged
janosmiko merged 1 commit into
mainfrom
refactor/per-model-render-globals
Aug 22, 2026
Merged

janosmiko merged 1 commit into
mainfrom
refactor/per-model-render-globals

Conversation

@janosmiko

Copy link
Copy Markdown
Owner

Model.View() sets the package-level ui.Active* and ui.Nyan* variables that the renderers read a moment later. Two renders on different goroutines therefore race them, and worse than racing, one can read another Model's values.

Bubble Tea renders on a single goroutine, so this is latent in production. It shows up in tests: any second test that renders under t.Parallel() trips -race. Two tests in discovery_failure_level_test.go carried a comment saying they could not be parallel because of it.

Why a lock rather than parameters

The original plan was to turn ActiveCollapsedCategories and ActiveCategoryCounts into parameters. The race detector showed the problem is wider than those two: the first report lands on view.go:87, which is ui.NyanMode, and the same block sets the security-badge state right after. RenderColumn already takes nine parameters, and threading a dozen values through it would be a large change to a hot path for a latent bug.

Guarding each variable individually would not fix the real defect either. A frame needs all of them to come from the same Model, so a per-variable lock would still let one render read another Model's values and paint a wrong frame. ui.RenderMu takes the whole pass, which is the unit the assignments and the renderers actually share. An uncontended mutex costs about 20ns against a multi-millisecond render.

Test plan

  • Both TestDiscoveryFailureAt* tests now call t.Parallel() and pass under -race
  • Verified red first: with t.Parallel() added and no lock, all three parallel tests report race detected
  • go test -race ./internal/app/... (3 consecutive runs)
  • golangci-lint run ./internal/... reports 0 issues

TestWatchTickAgeAdvancesOnMemoizedItems already had t.Parallel() and was racing silently until another parallel test joined it.

Model.View() sets the package-level Active* and Nyan* variables that the
renderers read a moment later, so two renders on different goroutines
race them. Bubble Tea renders on one goroutine, so this is latent in
production, but any second test that renders under t.Parallel() trips
-race. Two tests carried a comment saying they could not be parallel
because of it.

Guarding each variable would not fix it: a frame needs all of them to
come from the same Model, so a per-variable lock would still let one
render read another Model's values. ui.RenderMu takes the whole pass
instead, which is what the assignments and the renderers actually share.
An uncontended mutex costs nothing against a multi-millisecond render.
@coderabbitai

coderabbitai Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 86cef9c3-7299-46c6-aff3-a5805f596023

📥 Commits

Reviewing files that changed from the base of the PR and between ca36a79 and f390eb8.

📒 Files selected for processing (3)
  • internal/app/discovery_failure_level_test.go
  • internal/app/view.go
  • internal/ui/render_state.go

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.


Summary by CodeRabbit

  • Bug Fixes

    • Improved rendering reliability by preventing overlapping render operations.
    • Reduced potential inconsistencies when rendering and testing occur concurrently.
  • Tests

    • Discovery failure tests can now run in parallel for faster test execution.

Walkthrough

The change adds ui.RenderMu to serialize complete rendering passes. renderView locks this mutex and defers its release. Both discovery failure tests now call t.Parallel().

Merge Risk: ⚪ Minimal · up to f390e

This change serializes shared render state and enables the affected tests to run in parallel; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: enabling parallel rendering tests without race conditions.
Description check ✅ Passed The description explains the race, locking rationale, affected tests, and verification results, although it omits several template sections.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@janosmiko
janosmiko merged commit 251b36f into main Aug 22, 2026
10 checks passed
@janosmiko
janosmiko deleted the refactor/per-model-render-globals branch August 22, 2026 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant