Skip to content

refactor(leak): replace init() guard with lazy sync.Once check#82

Merged
fredbi merged 3 commits intomasterfrom
copilot/compare-guard-implementation-options
Mar 19, 2026
Merged

refactor(leak): replace init() guard with lazy sync.Once check#82
fredbi merged 3 commits intomasterfrom
copilot/compare-guard-implementation-options

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 19, 2026

  • Replace init() with ensureCompatible() guarded by sync.Once, called at the top of Leaked()
  • Same detection logic, same panic on incompatible format — just lazy
  • Eliminates the gochecknoinits lint suppression
  • Fix gochecknoglobals lint: add //nolint annotation with justification on compatOnce
  • Fix modernize lint: use wg.Go() instead of wg.Add(1); go func()...

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

The compatibility guard for pprof goroutine profile label format
now runs lazily via sync.Once on the first call to Leaked(), instead
of eagerly in init(). This avoids overhead and potential panics for
programs that import the assertions package but never use
NoGoRoutineLeak.

Signed-off-by: GitHub Copilot <[email protected]>

Co-authored-by: fredbi <[email protected]>
Copilot AI changed the title [WIP] Analyze guard implementation options for undocumented Go API refactor(leak): replace init() guard with lazy sync.Once check Mar 19, 2026
Copilot AI requested a review from fredbi March 19, 2026 18:09
@fredbi fredbi marked this pull request as ready for review March 19, 2026 18:11
Copy link
Copy Markdown
Member

@fredbi fredbi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix linting issues

Error: /home/runner/work/testify/testify/internal/leak/leak.go:28:5: compatOnce is a global variable (gochecknoglobals)
var compatOnce sync.Once
^
Error: /home/runner/work/testify/testify/internal/leak/leak.go:47:4: waitgroup: Goroutine creation can be simplified using WaitGroup.Go (modernize)
go func() {
^
2 issues:

  • gochecknoglobals: 1
  • modernize: 1

- Add //nolint:gochecknoglobals annotation with justification on compatOnce
- Replace wg.Add(1)/go func()/defer wg.Done() with wg.Go() (Go 1.25)

Signed-off-by: GitHub Copilot <[email protected]>

Co-authored-by: fredbi <[email protected]>
Copy link
Copy Markdown
Author

Copilot AI commented Mar 19, 2026

Please fix linting issues

Error: /home/runner/work/testify/testify/internal/leak/leak.go:28:5: compatOnce is a global variable (gochecknoglobals)...

Fixed in f0a5970: added //nolint:gochecknoglobals with justification on compatOnce, and replaced wg.Add(1)/go func()/defer wg.Done() with wg.Go() (Go 1.25 modernize).

Copilot AI requested a review from fredbi March 19, 2026 18:37
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 59.25926% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.24%. Comparing base (5700b9e) to head (f0a5970).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
internal/leak/leak.go 59.25% 9 Missing and 2 partials ⚠️

❌ Your patch status has failed because the patch coverage (59.25%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #82      +/-   ##
==========================================
+ Coverage   91.18%   91.24%   +0.05%     
==========================================
  Files          91       91              
  Lines       11929    11929              
==========================================
+ Hits        10878    10885       +7     
+ Misses        835      830       -5     
+ Partials      216      214       -2     

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

@fredbi fredbi merged commit bdd7923 into master Mar 19, 2026
20 of 21 checks passed
@fredbi fredbi deleted the copilot/compare-guard-implementation-options branch March 19, 2026 19:22
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.

2 participants