mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 06:16:08 +00:00
test: Fix badly formatted retry.Run tests
This commit is contained in:
parent
c3d6814149
commit
2794db5aac
@ -318,31 +318,27 @@ func TestEventList_EventBufOrder(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retry.
|
// Test that the event order is preserved when name
|
||||||
|
// filtering on a list of > 1 matching event.
|
||||||
// Test that the event order is preserved when name
|
retry.Run(t, func(r *retry.R) {
|
||||||
// filtering on a list of > 1 matching event.
|
url := "/v1/event/list?name=foo"
|
||||||
Run(t, func(r *retry.R) {
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
url := "/v1/event/list?name=foo"
|
r.Fatal(err)
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
}
|
||||||
if err != nil {
|
resp := httptest.NewRecorder()
|
||||||
r.Fatal(err)
|
obj, err := srv.EventList(resp, req)
|
||||||
}
|
if err != nil {
|
||||||
resp := httptest.NewRecorder()
|
r.Fatal(err)
|
||||||
obj, err := srv.EventList(resp, req)
|
}
|
||||||
if err != nil {
|
list, ok := obj.([]*UserEvent)
|
||||||
r.Fatal(err)
|
if !ok {
|
||||||
}
|
r.Fatalf("bad: %#v", obj)
|
||||||
list, ok := obj.([]*UserEvent)
|
}
|
||||||
if !ok {
|
if len(list) != 3 || list[2].ID != expected.ID {
|
||||||
r.Fatalf("bad: %#v", obj)
|
r.Fatalf("bad: %#v", list)
|
||||||
}
|
}
|
||||||
if len(list) != 3 || list[2].ID != expected.ID {
|
})
|
||||||
r.Fatalf("bad: %#v", list)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,29 +167,25 @@ func TestHealthChecksInState_DistanceSort(t *testing.T) {
|
|||||||
if err := srv.agent.RPC("Coordinate.Update", &arg, &out); err != nil {
|
if err := srv.agent.RPC("Coordinate.Update", &arg, &out); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
retry.
|
// Retry until foo moves to the front of the line.
|
||||||
|
retry.Run(t, func(r *retry.R) {
|
||||||
// Retry until foo moves to the front of the line.
|
resp = httptest.NewRecorder()
|
||||||
Run(t, func(r *retry.R) {
|
obj, err = srv.HealthChecksInState(resp, req)
|
||||||
|
if err != nil {
|
||||||
resp = httptest.NewRecorder()
|
r.Fatalf("err: %v", err)
|
||||||
obj, err = srv.HealthChecksInState(resp, req)
|
}
|
||||||
if err != nil {
|
assertIndex(t, resp)
|
||||||
r.Fatalf("err: %v", err)
|
nodes = obj.(structs.HealthChecks)
|
||||||
}
|
if len(nodes) != 2 {
|
||||||
assertIndex(t, resp)
|
r.Fatalf("bad: %v", nodes)
|
||||||
nodes = obj.(structs.HealthChecks)
|
}
|
||||||
if len(nodes) != 2 {
|
if nodes[0].Node != "foo" {
|
||||||
r.Fatalf("bad: %v", nodes)
|
r.Fatalf("bad: %v", nodes)
|
||||||
}
|
}
|
||||||
if nodes[0].Node != "foo" {
|
if nodes[1].Node != "bar" {
|
||||||
r.Fatalf("bad: %v", nodes)
|
r.Fatalf("bad: %v", nodes)
|
||||||
}
|
}
|
||||||
if nodes[1].Node != "bar" {
|
})
|
||||||
r.Fatalf("bad: %v", nodes)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHealthNodeChecks(t *testing.T) {
|
func TestHealthNodeChecks(t *testing.T) {
|
||||||
@ -428,29 +424,25 @@ func TestHealthServiceChecks_DistanceSort(t *testing.T) {
|
|||||||
if err := srv.agent.RPC("Coordinate.Update", &arg, &out); err != nil {
|
if err := srv.agent.RPC("Coordinate.Update", &arg, &out); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
retry.
|
// Retry until foo has moved to the front of the line.
|
||||||
|
retry.Run(t, func(r *retry.R) {
|
||||||
// Retry until foo has moved to the front of the line.
|
resp = httptest.NewRecorder()
|
||||||
Run(t, func(r *retry.R) {
|
obj, err = srv.HealthServiceChecks(resp, req)
|
||||||
|
if err != nil {
|
||||||
resp = httptest.NewRecorder()
|
r.Fatalf("err: %v", err)
|
||||||
obj, err = srv.HealthServiceChecks(resp, req)
|
}
|
||||||
if err != nil {
|
assertIndex(t, resp)
|
||||||
r.Fatalf("err: %v", err)
|
nodes = obj.(structs.HealthChecks)
|
||||||
}
|
if len(nodes) != 2 {
|
||||||
assertIndex(t, resp)
|
r.Fatalf("bad: %v", obj)
|
||||||
nodes = obj.(structs.HealthChecks)
|
}
|
||||||
if len(nodes) != 2 {
|
if nodes[0].Node != "foo" {
|
||||||
r.Fatalf("bad: %v", obj)
|
r.Fatalf("bad: %v", nodes)
|
||||||
}
|
}
|
||||||
if nodes[0].Node != "foo" {
|
if nodes[1].Node != "bar" {
|
||||||
r.Fatalf("bad: %v", nodes)
|
r.Fatalf("bad: %v", nodes)
|
||||||
}
|
}
|
||||||
if nodes[1].Node != "bar" {
|
})
|
||||||
r.Fatalf("bad: %v", nodes)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHealthServiceNodes(t *testing.T) {
|
func TestHealthServiceNodes(t *testing.T) {
|
||||||
@ -662,29 +654,25 @@ func TestHealthServiceNodes_DistanceSort(t *testing.T) {
|
|||||||
if err := srv.agent.RPC("Coordinate.Update", &arg, &out); err != nil {
|
if err := srv.agent.RPC("Coordinate.Update", &arg, &out); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
retry.
|
// Retry until foo has moved to the front of the line.
|
||||||
|
retry.Run(t, func(r *retry.R) {
|
||||||
// Retry until foo has moved to the front of the line.
|
resp = httptest.NewRecorder()
|
||||||
Run(t, func(r *retry.R) {
|
obj, err = srv.HealthServiceNodes(resp, req)
|
||||||
|
if err != nil {
|
||||||
resp = httptest.NewRecorder()
|
r.Fatalf("err: %v", err)
|
||||||
obj, err = srv.HealthServiceNodes(resp, req)
|
}
|
||||||
if err != nil {
|
assertIndex(t, resp)
|
||||||
r.Fatalf("err: %v", err)
|
nodes = obj.(structs.CheckServiceNodes)
|
||||||
}
|
if len(nodes) != 2 {
|
||||||
assertIndex(t, resp)
|
r.Fatalf("bad: %v", obj)
|
||||||
nodes = obj.(structs.CheckServiceNodes)
|
}
|
||||||
if len(nodes) != 2 {
|
if nodes[0].Node.Node != "foo" {
|
||||||
r.Fatalf("bad: %v", obj)
|
r.Fatalf("bad: %v", nodes)
|
||||||
}
|
}
|
||||||
if nodes[0].Node.Node != "foo" {
|
if nodes[1].Node.Node != "bar" {
|
||||||
r.Fatalf("bad: %v", nodes)
|
r.Fatalf("bad: %v", nodes)
|
||||||
}
|
}
|
||||||
if nodes[1].Node.Node != "bar" {
|
})
|
||||||
r.Fatalf("bad: %v", nodes)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHealthServiceNodes_PassingFilter(t *testing.T) {
|
func TestHealthServiceNodes_PassingFilter(t *testing.T) {
|
||||||
|
@ -1289,26 +1289,23 @@ func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
|
|||||||
Node: agent.config.NodeName,
|
Node: agent.config.NodeName,
|
||||||
}
|
}
|
||||||
var services structs.IndexedNodeServices
|
var services structs.IndexedNodeServices
|
||||||
retry.
|
// Wait for the sync
|
||||||
|
retry.Run(t, func(r *retry.R) {
|
||||||
|
if err := agent.RPC("Catalog.NodeServices", &req, &services); err != nil {
|
||||||
|
r.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for the sync
|
// Make sure we synced our node info - this should have ridden on the
|
||||||
Run(t, func(r *retry.R) {
|
// "consul" service sync
|
||||||
|
id := services.NodeServices.Node.ID
|
||||||
if err := agent.RPC("Catalog.NodeServices", &req, &services); err != nil {
|
addrs := services.NodeServices.Node.TaggedAddresses
|
||||||
r.Fatalf("err: %v", err)
|
meta := services.NodeServices.Node.Meta
|
||||||
}
|
if id != conf.NodeID ||
|
||||||
|
!reflect.DeepEqual(addrs, conf.TaggedAddresses) ||
|
||||||
// Make sure we synced our node info - this should have ridden on the
|
!reflect.DeepEqual(meta, conf.Meta) {
|
||||||
// "consul" service sync
|
r.Fatalf("bad: %v", services.NodeServices.Node)
|
||||||
id := services.NodeServices.Node.ID
|
}
|
||||||
addrs := services.NodeServices.Node.TaggedAddresses
|
})
|
||||||
meta := services.NodeServices.Node.Meta
|
|
||||||
if id != conf.NodeID ||
|
|
||||||
!reflect.DeepEqual(addrs, conf.TaggedAddresses) ||
|
|
||||||
!reflect.DeepEqual(meta, conf.Meta) {
|
|
||||||
r.Fatalf("bad: %v", services.NodeServices.Node)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Blow away the catalog version of the node info
|
// Blow away the catalog version of the node info
|
||||||
if err := agent.RPC("Catalog.Register", args, &out); err != nil {
|
if err := agent.RPC("Catalog.Register", args, &out); err != nil {
|
||||||
@ -1317,26 +1314,21 @@ func TestAgentAntiEntropy_NodeInfo(t *testing.T) {
|
|||||||
|
|
||||||
// Trigger anti-entropy run and wait
|
// Trigger anti-entropy run and wait
|
||||||
agent.StartSync()
|
agent.StartSync()
|
||||||
retry.
|
// Wait for the sync - this should have been a sync of just the node info
|
||||||
|
retry.Run(t, func(r *retry.R) {
|
||||||
// Wait for the sync - this should have been a sync of just the
|
if err := agent.RPC("Catalog.NodeServices", &req, &services); err != nil {
|
||||||
// node info
|
r.Fatalf("err: %v", err)
|
||||||
Run(t, func(r *retry.R) {
|
}
|
||||||
|
|
||||||
if err := agent.RPC("Catalog.NodeServices", &req, &services); err != nil {
|
|
||||||
r.Fatalf("err: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
id := services.NodeServices.Node.ID
|
|
||||||
addrs := services.NodeServices.Node.TaggedAddresses
|
|
||||||
meta := services.NodeServices.Node.Meta
|
|
||||||
if id != conf.NodeID ||
|
|
||||||
!reflect.DeepEqual(addrs, conf.TaggedAddresses) ||
|
|
||||||
!reflect.DeepEqual(meta, conf.Meta) {
|
|
||||||
r.Fatalf("bad: %v", services.NodeServices.Node)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
id := services.NodeServices.Node.ID
|
||||||
|
addrs := services.NodeServices.Node.TaggedAddresses
|
||||||
|
meta := services.NodeServices.Node.Meta
|
||||||
|
if id != conf.NodeID ||
|
||||||
|
!reflect.DeepEqual(addrs, conf.TaggedAddresses) ||
|
||||||
|
!reflect.DeepEqual(meta, conf.Meta) {
|
||||||
|
r.Fatalf("bad: %v", services.NodeServices.Node)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAgentAntiEntropy_deleteService_fails(t *testing.T) {
|
func TestAgentAntiEntropy_deleteService_fails(t *testing.T) {
|
||||||
|
@ -239,37 +239,34 @@ func TestAutopilot_PromoteNonVoter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testrpc.WaitForLeader(t, s1.RPC, "dc1")
|
testrpc.WaitForLeader(t, s1.RPC, "dc1")
|
||||||
retry.
|
// Wait for the new server to be added as a non-voter, but make sure
|
||||||
|
// it doesn't get promoted to a voter even after ServerStabilizationTime,
|
||||||
|
// because that would result in an even-numbered quorum count.
|
||||||
|
retry.Run(t, func(r *retry.R) {
|
||||||
|
future := s1.raft.GetConfiguration()
|
||||||
|
if err := future.Error(); err != nil {
|
||||||
|
r.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for the new server to be added as a non-voter, but make sure
|
servers := future.Configuration().Servers
|
||||||
// it doesn't get promoted to a voter even after ServerStabilizationTime,
|
|
||||||
// because that would result in an even-numbered quorum count.
|
|
||||||
Run(t, func(r *retry.R) {
|
|
||||||
|
|
||||||
future := s1.raft.GetConfiguration()
|
if len(servers) != 2 {
|
||||||
if err := future.Error(); err != nil {
|
r.Fatalf("bad: %v", servers)
|
||||||
r.Fatal(err)
|
}
|
||||||
}
|
if servers[1].Suffrage != raft.Nonvoter {
|
||||||
|
r.Fatalf("bad: %v", servers)
|
||||||
servers := future.Configuration().Servers
|
}
|
||||||
|
health := s1.getServerHealth(string(servers[1].ID))
|
||||||
if len(servers) != 2 {
|
if health == nil {
|
||||||
r.Fatalf("bad: %v", servers)
|
r.Fatal("nil health")
|
||||||
}
|
}
|
||||||
if servers[1].Suffrage != raft.Nonvoter {
|
if !health.Healthy {
|
||||||
r.Fatalf("bad: %v", servers)
|
r.Fatalf("bad: %v", health)
|
||||||
}
|
}
|
||||||
health := s1.getServerHealth(string(servers[1].ID))
|
if time.Now().Sub(health.StableSince) < s1.config.AutopilotConfig.ServerStabilizationTime {
|
||||||
if health == nil {
|
r.Fatal("stable period not elapsed")
|
||||||
r.Fatal("nil health")
|
}
|
||||||
}
|
})
|
||||||
if !health.Healthy {
|
|
||||||
r.Fatalf("bad: %v", health)
|
|
||||||
}
|
|
||||||
if time.Now().Sub(health.StableSince) < s1.config.AutopilotConfig.ServerStabilizationTime {
|
|
||||||
r.Fatal("stable period not elapsed")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Now add another server and make sure they both get promoted to voters after stabilization
|
// Now add another server and make sure they both get promoted to voters after stabilization
|
||||||
dir3, s3 := testServerWithConfig(t, func(c *Config) {
|
dir3, s3 := testServerWithConfig(t, func(c *Config) {
|
||||||
|
@ -676,17 +676,13 @@ func TestCatalog_ListNodes_NodeMetaFilter(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
retry.
|
// Should get an empty list of nodes back
|
||||||
|
retry.Run(t, func(r *retry.R) {
|
||||||
// Should get an empty list of nodes back
|
msgpackrpc.CallWithCodec(codec, "Catalog.ListNodes", &args, &out)
|
||||||
Run(t, func(r *retry.R) {
|
if len(out.Nodes) != 0 {
|
||||||
|
r.Fatal(nil)
|
||||||
msgpackrpc.CallWithCodec(codec, "Catalog.ListNodes", &args, &out)
|
}
|
||||||
if len(out.Nodes) != 0 {
|
})
|
||||||
r.Fatal(nil)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCatalog_ListNodes_StaleRaad(t *testing.T) {
|
func TestCatalog_ListNodes_StaleRaad(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user