test(metrics): initialize dirtyPods in TestModule_Reconcile modules - #2667
Closed
Quang Nguyen (nddq) wants to merge 1 commit into
Closed
test(metrics): initialize dirtyPods in TestModule_Reconcile modules#2667Quang Nguyen (nddq) wants to merge 1 commit into
Quang Nguyen (nddq) wants to merge 1 commit into
Conversation
Four TestModule_Reconcile cases call Reconcile on Module literals that leave dirtyPods nil; only InitModule sets it. Reconcile starts run, whose ticker calls applyDirtyPods every second on a context that no test cancels. The first tick dereferences the nil DirtyCache and the SIGSEGV kills the whole test binary. The crash depends on timing: the binary must stay alive one second past a Reconcile call. On a machine where the package takes over two seconds, go test -tags=unit ./pkg/module/metrics/ fails every run. Initialize dirtyPods in the four literals, matching TestPodCallBack and TestModule_NamespaceAndPodUpdates. Ticks on an empty cache are no-ops, so the leaked goroutines stay harmless. Signed-off-by: Quang Nguyen <28567936+nddq@users.noreply.github.com>
Quang Nguyen (nddq)
requested review from
Amilcar Aponte (apontejaj) and
Mereta (mereta)
August 18, 2026 17:02
Retina Code Coverage ReportTotal coverage no change |
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.
Description
TestModule_Reconcilebuilds fourModuleliterals withoutdirtyPods— onlyInitModuleinitializes that field — and callsReconcileon them.Reconcilecallsrun, which starts a ticker on the package constantinterval(1 second,metrics_module.go:38) with a context that no test cancels. Each tick callsapplyDirtyPods, and the first tick dereferences the nil*DirtyCache:The SIGSEGV kills the whole test binary. Whether it fires is a race between the first tick and process exit: on a machine where the package takes longer than ~2 seconds,
go test -tags=unit ./pkg/module/metrics/fails every run.This PR sets
dirtyPods: common.NewDirtyCache()in the four literals, matching the neighboringTestPodCallBackandTestModule_NamespaceAndPodUpdates. Ticks on an empty cache are no-ops (no filtermanager calls), so the leakedrungoroutines stay harmless for the remainder of the process.Related Issue
N/A — found while validating #2628 locally.
Checklist
git commit -S -s ...). See this documentation on signing commits.Screenshots (if applicable) or Testing Completed
At
origin/main(792c9324) the panic reproduces on every run of the package on a VM where the suite takes ~2.5 seconds. With this fix,go test -tags=unit -count=10 ./pkg/module/metrics/passes cleanly.Additional Notes
go test -raceon this package still fails for an unrelated pre-existing reason:TestBaseMetricObject's expire callback writes a test-local variable (basemetricsobject_test.go:54) that the test reads without synchronization (:77). It reproduces atorigin/mainwith-run TestBaseMetricObjectalone. CI does not run unit tests with-race, and that fix belongs in its own PR.