From e02ae7b6b4028e248c36cf0356fd73e1409b321f Mon Sep 17 00:00:00 2001 From: James Phillips Date: Fri, 26 Jun 2015 17:35:35 -0700 Subject: [PATCH] Takes the node name out of the coordinate get call. --- consul/coordinate_endpoint.go | 9 ++------- consul/coordinate_endpoint_test.go | 26 +++++++++++++------------- consul/fsm_test.go | 12 ++++++------ 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/consul/coordinate_endpoint.go b/consul/coordinate_endpoint.go index b97d2442a..b57549b65 100644 --- a/consul/coordinate_endpoint.go +++ b/consul/coordinate_endpoint.go @@ -91,13 +91,8 @@ func (c *Coordinate) Get(args *structs.NodeSpecificRequest, reply *structs.Index &reply.QueryMeta, state.QueryTables("Coordinates"), func() error { - idx, coord, err := state.CoordinateGet(args.Node) - reply.Index = idx - if coord == nil { - reply.Coord = nil - } else { - reply.Coord = coord.Coord - } + var err error + reply.Index, reply.Coord, err = state.CoordinateGet(args.Node) return err }) } diff --git a/consul/coordinate_endpoint_test.go b/consul/coordinate_endpoint_test.go index feee040f0..1205346e0 100644 --- a/consul/coordinate_endpoint_test.go +++ b/consul/coordinate_endpoint_test.go @@ -79,39 +79,39 @@ func TestCoordinate_Update(t *testing.T) { // Make sure the updates did not yet apply because the update period // hasn't expired. state := s1.fsm.State() - _, d, err := state.CoordinateGet("node1") + _, c, err := state.CoordinateGet("node1") if err != nil { t.Fatalf("err: %v", err) } - if d != nil { + if c != nil { t.Fatalf("should be nil because the update should be batched") } - _, d, err = state.CoordinateGet("node2") + _, c, err = state.CoordinateGet("node2") if err != nil { t.Fatalf("err: %v", err) } - if d != nil { + if c != nil { t.Fatalf("should be nil because the update should be batched") } // Wait a while and the updates should get picked up. time.Sleep(2 * s1.config.CoordinateUpdatePeriod) - _, d, err = state.CoordinateGet("node1") + _, c, err = state.CoordinateGet("node1") if err != nil { t.Fatalf("err: %v", err) } - if d == nil { + if c == nil { t.Fatalf("should return a coordinate but it's nil") } - verifyCoordinatesEqual(t, d.Coord, arg1.Coord) - _, d, err = state.CoordinateGet("node2") + verifyCoordinatesEqual(t, c, arg1.Coord) + _, c, err = state.CoordinateGet("node2") if err != nil { t.Fatalf("err: %v", err) } - if d == nil { + if c == nil { t.Fatalf("should return a coordinate but it's nil") } - verifyCoordinatesEqual(t, d.Coord, arg2.Coord) + verifyCoordinatesEqual(t, c, arg2.Coord) // Now try spamming coordinates and make sure it starts dropping when // the pipe is full. @@ -132,14 +132,14 @@ func TestCoordinate_Update(t *testing.T) { // Wait a little while for the batch routine to run, then make sure // all but the last coordinate update made it in. time.Sleep(2 * s1.config.CoordinateUpdatePeriod) - _, d, err = state.CoordinateGet("node1") + _, c, err = state.CoordinateGet("node1") if err != nil { t.Fatalf("err: %v", err) } - if d == nil { + if c == nil { t.Fatalf("should return a coordinate but it's nil") } - verifyCoordinatesEqual(t, d.Coord, arg1.Coord) + verifyCoordinatesEqual(t, c, arg1.Coord) } func TestCoordinate_Get(t *testing.T) { diff --git a/consul/fsm_test.go b/consul/fsm_test.go index 69011ac77..991397594 100644 --- a/consul/fsm_test.go +++ b/consul/fsm_test.go @@ -761,23 +761,23 @@ func TestFSM_CoordinateUpdate(t *testing.T) { } // Read back the two coordinates to make sure they got updated. - _, d, err := fsm.state.CoordinateGet(updates[0].Node) + _, c, err := fsm.state.CoordinateGet(updates[0].Node) if err != nil { t.Fatalf("err: %v", err) } - if d == nil { + if c == nil { t.Fatalf("missing") } - verifyCoordinatesEqual(t, updates[0].Coord, d.Coord) + verifyCoordinatesEqual(t, c, updates[0].Coord) - _, d, err = fsm.state.CoordinateGet(updates[1].Node) + _, c, err = fsm.state.CoordinateGet(updates[1].Node) if err != nil { t.Fatalf("err: %v", err) } - if d == nil { + if c == nil { t.Fatalf("missing") } - verifyCoordinatesEqual(t, updates[1].Coord, d.Coord) + verifyCoordinatesEqual(t, c, updates[1].Coord) } func TestFSM_SessionCreate_Destroy(t *testing.T) {