From 7831f346066c0785e66d0df222a15ab98d569e4d Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Wed, 15 Jan 2014 11:14:28 -1000 Subject: [PATCH] CheckServiceNodes will return node checks that are not service associated --- consul/state_store.go | 6 +++++- consul/state_store_test.go | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/consul/state_store.go b/consul/state_store.go index 7d1ebb6010..84ba662674 100644 --- a/consul/state_store.go +++ b/consul/state_store.go @@ -526,9 +526,13 @@ func (s *StateStore) parseCheckServiceNodes(tx *MDBTxn, res []interface{}, err e panic(fmt.Errorf("Failed to join node: %v", err)) } - // Get any associated checks + // Get any associated checks of the service checks := parseHealthChecks(s.checkTable.GetTxn(tx, "node", srv.Node, srv.ServiceID)) + // Get any checks of the node, not assciated with any service + nodeChecks := parseHealthChecks(s.checkTable.GetTxn(tx, "node", srv.Node, "")) + checks = append(checks, nodeChecks...) + // Setup the node nodes[i].Node = *nodeRes[0].(*structs.Node) nodes[i].Service = structs.NodeService{ diff --git a/consul/state_store_test.go b/consul/state_store_test.go index 773c95821d..5c9dc4973a 100644 --- a/consul/state_store_test.go +++ b/consul/state_store_test.go @@ -716,6 +716,15 @@ func TestCheckServiceNodes(t *testing.T) { if err := store.EnsureCheck(check); err != nil { t.Fatalf("err: %v") } + check = &structs.HealthCheck{ + Node: "foo", + CheckID: serfCheckID, + Name: serfCheckName, + Status: structs.HealthPassing, + } + if err := store.EnsureCheck(check); err != nil { + t.Fatalf("err: %v") + } nodes := store.CheckServiceNodes("db") if len(nodes) != 1 { @@ -728,10 +737,13 @@ func TestCheckServiceNodes(t *testing.T) { if nodes[0].Service.ID != "db1" { t.Fatalf("Bad: %v", nodes[0]) } - if len(nodes[0].Checks) != 1 { + if len(nodes[0].Checks) != 2 { t.Fatalf("Bad: %v", nodes[0]) } - if nodes[0].Checks[0].Status != structs.HealthPassing { + if nodes[0].Checks[0].CheckID != "db" { + t.Fatalf("Bad: %v", nodes[0]) + } + if nodes[0].Checks[1].CheckID != serfCheckID { t.Fatalf("Bad: %v", nodes[0]) } @@ -746,10 +758,13 @@ func TestCheckServiceNodes(t *testing.T) { if nodes[0].Service.ID != "db1" { t.Fatalf("Bad: %v", nodes[0]) } - if len(nodes[0].Checks) != 1 { + if len(nodes[0].Checks) != 2 { t.Fatalf("Bad: %v", nodes[0]) } - if nodes[0].Checks[0].Status != structs.HealthPassing { + if nodes[0].Checks[0].CheckID != "db" { + t.Fatalf("Bad: %v", nodes[0]) + } + if nodes[0].Checks[1].CheckID != serfCheckID { t.Fatalf("Bad: %v", nodes[0]) } }