mirror of https://github.com/hashicorp/consul
Remove all sleeps from `catalog_endpoint_test.go`
parent
f202123fb1
commit
14dec397f8
|
@ -64,8 +64,8 @@ func TestCatalogRegister_ForwardLeader(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Wait for a leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client1.Call, "dc1")
|
||||
testutil.WaitForLeader(t, client2.Call, "dc1")
|
||||
|
||||
// Use the follower as the client
|
||||
var client *rpc.Client
|
||||
|
@ -109,8 +109,7 @@ func TestCatalogRegister_ForwardDC(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Wait for the leaders
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client.Call, "dc2")
|
||||
|
||||
arg := structs.RegisterRequest{
|
||||
Datacenter: "dc2", // SHould forward through s1
|
||||
|
@ -146,8 +145,7 @@ func TestCatalogDeregister(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Wait for leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client.Call, "dc1")
|
||||
|
||||
if err := client.Call("Catalog.Deregister", &arg, &out); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
@ -171,7 +169,8 @@ func TestCatalogListDatacenters(t *testing.T) {
|
|||
if _, err := s2.JoinWAN([]string{addr}); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
testutil.WaitForLeader(t, client.Call, "dc1")
|
||||
|
||||
var out []string
|
||||
if err := client.Call("Catalog.ListDatacenters", struct{}{}, &out); err != nil {
|
||||
|
@ -208,8 +207,7 @@ func TestCatalogListNodes(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Wait for leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client.Call, "dc1")
|
||||
|
||||
// Just add a node
|
||||
s1.fsm.State().EnsureNode(1, structs.Node{"foo", "127.0.0.1"})
|
||||
|
@ -254,8 +252,8 @@ func TestCatalogListNodes_StaleRaad(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
testutil.WaitForLeader(t, client1.Call)
|
||||
testutil.WaitForLeader(t, client2.Call)
|
||||
testutil.WaitForLeader(t, client1.Call, "dc1")
|
||||
testutil.WaitForLeader(t, client2.Call, "dc1")
|
||||
|
||||
// Use the follower as the client
|
||||
var client *rpc.Client
|
||||
|
@ -318,8 +316,8 @@ func TestCatalogListNodes_ConsistentRead_Fail(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Wait for a leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client1.Call, "dc1")
|
||||
testutil.WaitForLeader(t, client2.Call, "dc1")
|
||||
|
||||
// Use the leader as the client, kill the follower
|
||||
var client *rpc.Client
|
||||
|
@ -368,8 +366,8 @@ func TestCatalogListNodes_ConsistentRead(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Wait for a leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client1.Call, "dc1")
|
||||
testutil.WaitForLeader(t, client2.Call, "dc1")
|
||||
|
||||
// Use the leader as the client, kill the follower
|
||||
var client *rpc.Client
|
||||
|
@ -403,9 +401,6 @@ func BenchmarkCatalogListNodes(t *testing.B) {
|
|||
client := rpcClient(nil, s1)
|
||||
defer client.Close()
|
||||
|
||||
// Wait for leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Just add a node
|
||||
s1.fsm.State().EnsureNode(1, structs.Node{"foo", "127.0.0.1"})
|
||||
|
||||
|
@ -436,8 +431,7 @@ func TestCatalogListServices(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Wait for leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client.Call, "dc1")
|
||||
|
||||
// Just add a node
|
||||
s1.fsm.State().EnsureNode(1, structs.Node{"foo", "127.0.0.1"})
|
||||
|
@ -474,8 +468,7 @@ func TestCatalogListServices_Blocking(t *testing.T) {
|
|||
}
|
||||
var out structs.IndexedServices
|
||||
|
||||
// Wait for leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client.Call, "dc1")
|
||||
|
||||
// Run the query
|
||||
if err := client.Call("Catalog.ListServices", &args, &out); err != nil {
|
||||
|
@ -489,7 +482,7 @@ func TestCatalogListServices_Blocking(t *testing.T) {
|
|||
// Async cause a change
|
||||
start := time.Now()
|
||||
go func() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
s1.fsm.State().EnsureNode(1, structs.Node{"foo", "127.0.0.1"})
|
||||
s1.fsm.State().EnsureService(2, "foo", &structs.NodeService{"db", "db", []string{"primary"}, 5000})
|
||||
}()
|
||||
|
@ -501,7 +494,7 @@ func TestCatalogListServices_Blocking(t *testing.T) {
|
|||
}
|
||||
|
||||
// Should block at least 100ms
|
||||
if time.Now().Sub(start) < 100*time.Millisecond {
|
||||
if time.Now().Sub(start) < 50 * time.Millisecond {
|
||||
t.Fatalf("too fast")
|
||||
}
|
||||
|
||||
|
@ -528,8 +521,7 @@ func TestCatalogListServices_Timeout(t *testing.T) {
|
|||
}
|
||||
var out structs.IndexedServices
|
||||
|
||||
// Wait for leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client.Call, "dc1")
|
||||
|
||||
// Run the query
|
||||
if err := client.Call("Catalog.ListServices", &args, &out); err != nil {
|
||||
|
@ -538,7 +530,7 @@ func TestCatalogListServices_Timeout(t *testing.T) {
|
|||
|
||||
// Setup a blocking query
|
||||
args.MinQueryIndex = out.Index
|
||||
args.MaxQueryTime = 100 * time.Millisecond
|
||||
args.MaxQueryTime = 50 * time.Millisecond
|
||||
|
||||
// Re-run the query
|
||||
start := time.Now()
|
||||
|
@ -548,7 +540,7 @@ func TestCatalogListServices_Timeout(t *testing.T) {
|
|||
}
|
||||
|
||||
// Should block at least 100ms
|
||||
if time.Now().Sub(start) < 100*time.Millisecond {
|
||||
if time.Now().Sub(start) < 50 * time.Millisecond {
|
||||
t.Fatalf("too fast")
|
||||
}
|
||||
|
||||
|
@ -610,8 +602,7 @@ func TestCatalogListServiceNodes(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Wait for leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client.Call, "dc1")
|
||||
|
||||
// Just add a node
|
||||
s1.fsm.State().EnsureNode(1, structs.Node{"foo", "127.0.0.1"})
|
||||
|
@ -654,8 +645,7 @@ func TestCatalogNodeServices(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Wait for leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client.Call, "dc1")
|
||||
|
||||
// Just add a node
|
||||
s1.fsm.State().EnsureNode(1, structs.Node{"foo", "127.0.0.1"})
|
||||
|
@ -706,8 +696,7 @@ func TestCatalogRegister_FailedCase1(t *testing.T) {
|
|||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
// Wait for leader
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
testutil.WaitForLeader(t, client.Call, "dc1")
|
||||
|
||||
if err := client.Call("Catalog.Register", &arg, &out); err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
|
Loading…
Reference in New Issue