Skip to content

Add unit tests and context-based watcher cancellation for loopcheck removal#34

Merged
powerkimhub merged 5 commits into
masterfrom
copilot/fix-issue-1-analysis-and-code
Mar 20, 2026
Merged

Add unit tests and context-based watcher cancellation for loopcheck removal#34
powerkimhub merged 5 commits into
masterfrom
copilot/fix-issue-1-analysis-and-code

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

No *_test.go files existed to validate the removal of loopcheck and the switch to an always-on fsnotify watcher.

Tests added (cblogger_test.go)

  • TestNewCBLOGCONFIG_Defaults — confirms LOOPCHECK field is absent from the struct (would be a compile error if reintroduced)
  • TestGetConfigInfos_WithoutLoopcheck — config YAML without loopcheck key parses correctly
  • TestGetConfigInfos_OldConfigWithLoopcheck — old YAML with loopcheck: true loads without error; unknown field is silently ignored by yaml.v3
  • TestDynamicLevelChange — end-to-end: writes a config file, starts the logger, overwrites loglevel, and asserts the watcher picks up the change within 3 s

Production fixes (surfaced during testing)

Goroutine leak / nil-pointer paniclevelSetupWatcher ran forever with no shutdown path; resetting globals in tests caused a panic when the dangling goroutine called SetLevel on a nil logger.

  • setup() now creates a context.WithCancel and stores watcherCancel
  • levelSetupWatcher accepts ctx context.Context and exits on ctx.Done()
  • reloadConfig() helper extracted to remove the duplicated GetConfigInfos + SetLevel pair across Rename/Remove and Write/Create branches
// before
go levelSetupWatcher(loggerName, configFilePath)

// after
ctx, cancel := context.WithCancel(context.Background())
watcherCancel = cancel
go levelSetupWatcher(ctx, loggerName, configFilePath)

Test run results

=== RUN   TestNewCBLOGCONFIG_Defaults       --- PASS (0.00s)
=== RUN   TestGetConfigInfos_WithoutLoopcheck --- PASS (0.00s)
=== RUN   TestGetConfigInfos_OldConfigWithLoopcheck --- PASS (0.00s)
=== RUN   TestDynamicLevelChange             --- PASS (0.30s)
ok  github.com/cloud-barista/cb-log  0.306s

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

Copilot AI changed the title [WIP] Fix issue #1 by analyzing, planning, and implementing code changes Replace busy-wait config polling with fsnotify event-driven watcher Mar 20, 2026
Copilot AI requested a review from powerkimhub March 20, 2026 01:54
Copilot AI changed the title Replace busy-wait config polling with fsnotify event-driven watcher Remove loopcheck config option — file watcher always active Mar 20, 2026
Copilot AI changed the title Remove loopcheck config option — file watcher always active Remove loopcheck config option; watcher is always-on Mar 20, 2026
Copilot AI changed the title Remove loopcheck config option; watcher is always-on Add unit tests and context-based watcher cancellation for loopcheck removal Mar 20, 2026
@powerkimhub powerkimhub marked this pull request as ready for review March 20, 2026 02:21
@powerkimhub powerkimhub merged commit b5fc3bf into master Mar 20, 2026
1 check passed
Copilot stopped work on behalf of powerkimhub due to an error March 20, 2026 02:28
Copilot stopped work on behalf of powerkimhub due to an error March 20, 2026 02:30
powerkimhub added a commit that referenced this pull request Mar 20, 2026
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