mirror of https://github.com/status-im/consul.git
Add retries to all `obj`
This commit is contained in:
parent
b96d9b01bd
commit
73d73e0e20
|
@ -10,6 +10,7 @@ import (
|
|||
|
||||
"github.com/hashicorp/consul/acl"
|
||||
"github.com/hashicorp/consul/agent/structs"
|
||||
"github.com/hashicorp/consul/sdk/testutil/retry"
|
||||
"github.com/hashicorp/consul/testrpc"
|
||||
"github.com/hashicorp/serf/coordinate"
|
||||
)
|
||||
|
@ -80,6 +81,7 @@ func TestCoordinate_Nodes(t *testing.T) {
|
|||
// Make sure an empty list is non-nil.
|
||||
req, _ := http.NewRequest("GET", "/v1/coordinate/nodes?dc=dc1", nil)
|
||||
resp := httptest.NewRecorder()
|
||||
retry.Run(t, func(r *retry.R) {
|
||||
obj, err := a.srv.CoordinateNodes(resp, req)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
@ -94,6 +96,7 @@ func TestCoordinate_Nodes(t *testing.T) {
|
|||
if len(coordinates) != 0 {
|
||||
t.Fatalf("coordinates should be empty, received: %v", coordinates)
|
||||
}
|
||||
})
|
||||
|
||||
// Register the nodes.
|
||||
nodes := []string{"foo", "bar"}
|
||||
|
@ -135,56 +138,73 @@ func TestCoordinate_Nodes(t *testing.T) {
|
|||
// Query back and check the nodes are present and sorted correctly.
|
||||
req, _ = http.NewRequest("GET", "/v1/coordinate/nodes?dc=dc1", nil)
|
||||
resp = httptest.NewRecorder()
|
||||
obj, err = a.srv.CoordinateNodes(resp, req)
|
||||
retry.Run(t, func(r *retry.R) {
|
||||
obj, err := a.srv.CoordinateNodes(resp, req)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
coordinates = obj.(structs.Coordinates)
|
||||
coordinates, ok := obj.(structs.Coordinates)
|
||||
if !ok {
|
||||
t.Fatalf("expected: structs.Coordinates, received: %v", coordinates)
|
||||
}
|
||||
if len(coordinates) != 2 ||
|
||||
coordinates[0].Node != "bar" ||
|
||||
coordinates[1].Node != "foo" {
|
||||
t.Fatalf("bad: %v", coordinates)
|
||||
t.Fatalf("expected: bar, foo recieved: %v", coordinates)
|
||||
}
|
||||
|
||||
})
|
||||
// Filter on a nonexistent node segment
|
||||
req, _ = http.NewRequest("GET", "/v1/coordinate/nodes?segment=nope", nil)
|
||||
resp = httptest.NewRecorder()
|
||||
obj, err = a.srv.CoordinateNodes(resp, req)
|
||||
retry.Run(t, func(r *retry.R) {
|
||||
obj, err := a.srv.CoordinateNodes(resp, req)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
coordinates = obj.(structs.Coordinates)
|
||||
if len(coordinates) != 0 {
|
||||
t.Fatalf("bad: %v", coordinates)
|
||||
coordinates, ok := obj.(structs.Coordinates)
|
||||
if !ok {
|
||||
t.Fatalf("expected: structs.Coordinates, received: %v", coordinates)
|
||||
}
|
||||
|
||||
if len(coordinates) != 0 {
|
||||
t.Fatalf("coordinates should be empty, received: %v", coordinates)
|
||||
}
|
||||
})
|
||||
// Filter on a real node segment
|
||||
req, _ = http.NewRequest("GET", "/v1/coordinate/nodes?segment=alpha", nil)
|
||||
resp = httptest.NewRecorder()
|
||||
obj, err = a.srv.CoordinateNodes(resp, req)
|
||||
retry.Run(t, func(r *retry.R) {
|
||||
obj, err := a.srv.CoordinateNodes(resp, req)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
coordinates = obj.(structs.Coordinates)
|
||||
if len(coordinates) != 1 || coordinates[0].Node != "foo" {
|
||||
t.Fatalf("bad: %v", coordinates)
|
||||
coordinates, ok := obj.(structs.Coordinates)
|
||||
if !ok {
|
||||
t.Fatalf("expected: structs.Coordinates, received: %v", coordinates)
|
||||
}
|
||||
|
||||
if len(coordinates) != 1 || coordinates[0].Node != "foo" {
|
||||
t.Fatalf("expected: foo received: %v", coordinates)
|
||||
}
|
||||
})
|
||||
// Make sure the empty filter works
|
||||
req, _ = http.NewRequest("GET", "/v1/coordinate/nodes?segment=", nil)
|
||||
resp = httptest.NewRecorder()
|
||||
obj, err = a.srv.CoordinateNodes(resp, req)
|
||||
retry.Run(t, func(r *retry.R) {
|
||||
obj, err := a.srv.CoordinateNodes(resp, req)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
coordinates = obj.(structs.Coordinates)
|
||||
if len(coordinates) != 1 || coordinates[0].Node != "bar" {
|
||||
t.Fatalf("bad: %v", coordinates)
|
||||
coordinates, ok := obj.(structs.Coordinates)
|
||||
if !ok {
|
||||
t.Fatalf("expected: structs.Coordinates, received: %v", coordinates)
|
||||
}
|
||||
if len(coordinates) != 1 || coordinates[0].Node != "bar" {
|
||||
t.Fatalf("expected: bar received: %v", coordinates)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCoordinate_Node(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue