Skip to content

fix(registry): wait for background meta refresh before test reset#894

Merged
liangshuo-1 merged 2 commits into
mainfrom
fix/registry-wait-background-refresh
May 14, 2026
Merged

fix(registry): wait for background meta refresh before test reset#894
liangshuo-1 merged 2 commits into
mainfrom
fix/registry-wait-background-refresh

Conversation

@liangshuo-1
Copy link
Copy Markdown
Collaborator

@liangshuo-1 liangshuo-1 commented May 14, 2026

Summary

Fixes a data race in internal/registry tests that caused go test -race (coverage CI job) to fail intermittently.

Root cause

  • TestComputeMinimumScopeSet calls Init()triggerBackgroundRefresh(), which starts doBackgroundRefresh in a goroutine.
  • The next test, TestComputeMinimumScopeSet_Tenant, calls resetInit() while that goroutine can still be running fetchRemoteMerged / remoteMetaURL and reading package-level globals that resetInit() writes → race under -race.

This is unrelated to doc-only PRs (e.g. #891); it is test-isolation / lifecycle hygiene.

Change

  • Wrap the background refresh goroutine in sync.WaitGroup (bgRefreshInFlight).
  • At the start of test helper resetInit(), call waitBackgroundRefresh() before mutating globals.

Verification

go test -race -count=3 ./internal/registry/... -run 'TestComputeMinimumScopeSet'
go test -race ./internal/registry/...

Review

Per team thread: @codex code owner review; cross-check welcome on test/race narrative.

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes

    • Improved background refresh initialization to reliably track in-flight work and avoid race conditions during reinitialization.
  • Tests

    • Added test synchronization to wait for background refresh completion before resetting state, improving test stability.

Review Change Stack

TestComputeMinimumScopeSet can start doBackgroundRefresh via Init() while
the next test's resetInit() mutates package-level globals the goroutine
still reads (e.g. remoteMetaURL / configuredBrand), causing data races under
-race in the coverage job.

Track the refresh goroutine with a WaitGroup and drain it at the start of
resetInit() in tests.

Change-Id: Ibf9475c87bb655e403fb6ffcc3431ef0f340ceb6
Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c128f3a1-e598-4214-97d1-d1d58400e7d4

📥 Commits

Reviewing files that changed from the base of the PR and between 905d13a and 6c2993c.

📒 Files selected for processing (2)
  • internal/registry/remote.go
  • internal/registry/remote_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/registry/remote_test.go

📝 Walkthrough

Walkthrough

A package-level sync.WaitGroup now tracks the background refresh goroutine started by triggerBackgroundRefresh. Tests add a waitBackgroundRefresh() helper and call it from resetInit() so any in-flight refresh completes before package state is reinitialized.

Changes

Background refresh synchronization

Layer / File(s) Summary
Background refresh goroutine tracking
internal/registry/remote.go
Added bgRefreshInFlight WaitGroup and modified triggerBackgroundRefresh to run doBackgroundRefresh inside a goroutine that calls bgRefreshInFlight.Add(1) before work and Done() via defer on completion.
Test wait helper and teardown ordering
internal/registry/remote_test.go
Added waitBackgroundRefresh() that blocks on bgRefreshInFlight, and updated resetInit() to call it before clearing package-level globals.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • larksuite/cli#280: Both PRs modify the registry test initialization flow in internal/registry/remote_test.go—this PR adds waitBackgroundRefresh() into resetInit() while that PR updates test init/reset behavior.

Suggested labels

size/S

Poem

🐰 A quiet goroutine raced at dawn,
Unseen, it hummed until tests were drawn.
A WaitGroup hops in, counts each flight,
Waiting till all are done before midnight.
Now teardowns sleep sound, no more fright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: waiting for background meta refresh before test reset to fix a data race issue.
Description check ✅ Passed The description covers all required template sections with clear summary, changes, verification steps, and related context; it is thorough and complete.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/registry-wait-background-refresh

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 and usage tips.

@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label May 14, 2026
Move the drain helper next to resetInit in remote_test.go so non-test
builds cannot import a blocking wait API; bgRefreshInFlight stays in
production for triggerBackgroundRefresh accounting.

Addresses review nit: test-only lifecycle hook belongs in _test compilation.

Change-Id: I58b74bcd0fcf5c5e60eb8a3a24be503ea7466c35
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 14, 2026

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@6c2993cc634ee573e741b58c61b981588b645fb1

🧩 Skill update

npx skills add larksuite/cli#fix/registry-wait-background-refresh -y -g

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.90%. Comparing base (52e0129) to head (6c2993c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #894   +/-   ##
=======================================
  Coverage   65.90%   65.90%           
=======================================
  Files         520      520           
  Lines       49274    49277    +3     
=======================================
+ Hits        32474    32477    +3     
  Misses      14026    14026           
  Partials     2774     2774           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@liangshuo-1 liangshuo-1 merged commit f49a2f7 into main May 14, 2026
21 checks passed
@liangshuo-1 liangshuo-1 deleted the fix/registry-wait-background-refresh branch May 14, 2026 14:33
@liangshuo-1 liangshuo-1 mentioned this pull request May 15, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants