Forget a runtime's old instance once it answers under a new one, so a restart is not reported as a missed answer

This commit is contained in:
jochen
2026-10-05 15:38:30 +02:00
parent 379d19d907
commit 52a0cc4fcb
2 changed files with 30 additions and 0 deletions
@@ -198,3 +198,22 @@ func TestARuntimeHeardBeforeAndNotNowIsNamed(t *testing.T) {
t.Errorf("%v", err)
}
}
// A runtime restarted answers under a new instance id; its old instance is gone, not unheard.
func TestARestartedRuntimeIsNotNamedUnheard(t *testing.T) {
heard := func(id string) *index {
return &index{Modules: map[string]*moduleInfo{}, Recorded: map[string][]string{}, Discovery: announce.Discovery{At: time.Now().UTC(),
Heard: []announce.Heard{{Info: micro.Info{ServiceIdentity: micro.ServiceIdentity{Name: "node-tools", ID: id,
Metadata: map[string]string{"node": "laptop"}}}}}}}
}
s := &Surface{}
s.remember(heard("before-restart"))
after := heard("after-restart")
s.remember(after)
if len(after.Unheard) != 0 {
t.Errorf("a restarted runtime was named unheard: %+v", after.Unheard)
}
if len(s.runtimes) != 1 {
t.Errorf("the old instance is still kept: %d runtimes", len(s.runtimes))
}
}