test: add additional http status code assertions in coordinate HTTP API tests (#6410)

When this test flakes sometimes this happens:

    --- FAIL: TestCoordinate_Node (1.69s)
    panic: interface conversion: interface {} is nil, not structs.Coordinates [recovered]
    FAIL    github.com/hashicorp/consul/agent       19.999s
    Exit code: 1
    panic: interface conversion: interface {} is nil, not structs.Coordinates [recovered]
            panic: interface conversion: interface {} is nil, not structs.Coordinates

There is definitely a bug lurking, but the code seems to imply this can
only return nil on 404. The tests previously were not checking the
status code.

The underlying cause of the flake is unknown, but this should turn the
failure into a more normal test failure.
This commit is contained in:
R.B. Boyer 2019-08-29 09:55:05 -05:00 committed by GitHub
parent 00aa108490
commit d979d8c239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 0 deletions

View File

@ -63,6 +63,10 @@ func TestCoordinate_Datacenters(t *testing.T) {
t.Fatalf("err: %v", err)
}
if resp.Code != http.StatusOK {
t.Fatalf("bad: %v", resp.Code)
}
maps := obj.([]structs.DatacenterMap)
if len(maps) != 1 ||
maps[0].Datacenter != "dc1" ||
@ -87,6 +91,10 @@ func TestCoordinate_Nodes(t *testing.T) {
r.Fatalf("err: %v", err)
}
if resp.Code != http.StatusOK {
r.Fatalf("bad: %v", resp.Code)
}
// Check that coordinates are empty before registering a node
coordinates, ok := obj.(structs.Coordinates)
if !ok {
@ -144,6 +152,10 @@ func TestCoordinate_Nodes(t *testing.T) {
r.Fatalf("err: %v", err)
}
if resp.Code != http.StatusOK {
r.Fatalf("bad: %v", resp.Code)
}
coordinates, ok := obj.(structs.Coordinates)
if !ok {
r.Fatalf("expected: structs.Coordinates, received: %+v", obj)
@ -163,6 +175,10 @@ func TestCoordinate_Nodes(t *testing.T) {
r.Fatalf("err: %v", err)
}
if resp.Code != http.StatusOK {
r.Fatalf("bad: %v", resp.Code)
}
coordinates, ok := obj.(structs.Coordinates)
if !ok {
r.Fatalf("expected: structs.Coordinates, received: %+v", obj)
@ -180,6 +196,10 @@ func TestCoordinate_Nodes(t *testing.T) {
r.Fatalf("err: %v", err)
}
if resp.Code != http.StatusOK {
r.Fatalf("bad: %v", resp.Code)
}
coordinates, ok := obj.(structs.Coordinates)
if !ok {
r.Fatalf("expected: structs.Coordinates, received: %+v", obj)
@ -220,6 +240,7 @@ func TestCoordinate_Node(t *testing.T) {
if err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != http.StatusNotFound {
t.Fatalf("bad: %v", resp.Code)
}
@ -269,6 +290,10 @@ func TestCoordinate_Node(t *testing.T) {
t.Fatalf("err: %v", err)
}
if resp.Code != http.StatusOK {
t.Fatalf("bad: %v", resp.Code)
}
coordinates := obj.(structs.Coordinates)
if len(coordinates) != 1 ||
coordinates[0].Node != "foo" {
@ -294,6 +319,10 @@ func TestCoordinate_Node(t *testing.T) {
t.Fatalf("err: %v", err)
}
if resp.Code != http.StatusOK {
t.Fatalf("bad: %v", resp.Code)
}
coordinates = obj.(structs.Coordinates)
if len(coordinates) != 1 || coordinates[0].Node != "foo" {
t.Fatalf("bad: %v", coordinates)
@ -342,6 +371,11 @@ func TestCoordinate_Update(t *testing.T) {
if err != nil {
t.Fatalf("err: %v", err)
}
if resp.Code != http.StatusOK {
t.Fatalf("bad: %v", resp.Code)
}
time.Sleep(300 * time.Millisecond)
// Query back and check the coordinates are present.