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")) +}