fix: P1-3 address heartbeat timer leak, test drain, and store consistency

- COR-001: drain runHeartbeat goroutine via done channel before test returns,
  eliminating race against concurrent SetHeartbeatInterval tests
- COR-002: replace time.After with time.NewTimer + defer t.Stop() + t.Reset()
  to prevent timer goroutine leaks on context cancellation
- COR-005: guard HeartbeatInterval store write with > 0 check in OnClusterUpdated,
  keeping store consistent with SetHeartbeatInterval's zero-ignore semantics
This commit is contained in:
Rongsong Shen 2026-04-17 14:20:02 +00:00
parent ffc5b20cdb
commit 0a3de8b040
3 changed files with 16 additions and 9 deletions

View file

@ -60,7 +60,9 @@ func (h *DefaultHandler) OnHostConfigUpdated(incoming *models.HostInfo) {
func (h *DefaultHandler) OnClusterUpdated(incoming *models.ClusterInfo) {
existing, _ := store.Clusters.Get(incoming.ClusterName)
existing.ClusterName = incoming.ClusterName
existing.HeartbeatInterval = incoming.HeartbeatInterval
if incoming.HeartbeatInterval > 0 {
existing.HeartbeatInterval = incoming.HeartbeatInterval
}
existing.Vcpus = incoming.Vcpus
existing.InactiveHeartbeatCount = incoming.InactiveHeartbeatCount
store.Clusters.Put(existing.ClusterName, existing)