From 0c89183f548fc55cd7a5ecf8e856973c5f0ffe71 Mon Sep 17 00:00:00 2001 From: Deepesh Pathak Date: Wed, 18 Mar 2026 13:56:38 -0700 Subject: [PATCH] cell: fix incorrect Close of nested health scopes in SimpleHealthCell This commit fixes incorrect `name` tracking for nested scopes in SimpleHealthCell, where the scope is registered without just the name of the scope instead of full scope identifier. This leads to a situation where `Close` doesn't remove the registered nested scopes from internal map of scope tracker. Signed-off-by: Deepesh Pathak --- cell/simple_health.go | 9 +++++++-- cell/simple_health_test.go | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/cell/simple_health.go b/cell/simple_health.go index 60da0ef..904715d 100644 --- a/cell/simple_health.go +++ b/cell/simple_health.go @@ -31,11 +31,16 @@ func (h *SimpleHealth) NewScope(name string) Health { h.Lock() defer h.Unlock() + scope := name + if len(h.Scope) > 0 { + scope = h.Scope + "." + name + } + h2 := &SimpleHealth{ simpleHealthRoot: h.simpleHealthRoot, - Scope: h.Scope + "." + name, + Scope: scope, } - h.all[name] = h2 + h.all[scope] = h2 return h2 } diff --git a/cell/simple_health_test.go b/cell/simple_health_test.go index e761206..4bd5903 100644 --- a/cell/simple_health_test.go +++ b/cell/simple_health_test.go @@ -53,3 +53,24 @@ hive stop expected := `health 'test1.*matched: test1.*health 'test2.*matched: test2` require.Regexp(t, expected, strings.ReplaceAll(stdout.String(), "\n", " ")) } + +func TestSimpleHealthClose(t *testing.T) { + _, h := cell.NewSimpleHealth() + require.NotNil(t, h) + + hTest := h.NewScope("test") + require.NotNil(t, hTest) + + hTestInner := hTest.NewScope("inner") + require.NotNil(t, hTestInner) + + require.NotNil(t, h.GetChild("test")) + require.NotNil(t, h.GetChild("test.inner")) + + hTest.Close() + require.Nil(t, h.GetChild("test")) + require.NotNil(t, h.GetChild("test.inner")) + + hTestInner.Close() + require.Nil(t, h.GetChild("test.inner")) +}