mirror of https://github.com/hashicorp/consul
PR to fix TestAgent_IndexChurn and TestPreparedQuery_Wrapper. (#4512)
* Fixes TestAgent_IndexChurn * Fixes TestPreparedQuery_Wrapper * Increased sleep in agent_test for IndexChurn to 500ms * Made the comment about joinWAN operation much less of a cliffhangerpull/4517/head
parent
8a1f42e190
commit
c88900aaa9
|
@ -15,6 +15,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/consul/testrpc"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent/checks"
|
"github.com/hashicorp/consul/agent/checks"
|
||||||
"github.com/hashicorp/consul/agent/config"
|
"github.com/hashicorp/consul/agent/config"
|
||||||
"github.com/hashicorp/consul/agent/connect"
|
"github.com/hashicorp/consul/agent/connect"
|
||||||
|
@ -626,6 +628,9 @@ func verifyIndexChurn(t *testing.T, tags []string) {
|
||||||
a := NewTestAgent(t.Name(), "")
|
a := NewTestAgent(t.Name(), "")
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
|
// Ensure we have a leader before we start adding the services
|
||||||
|
testrpc.WaitForLeader(t, a.RPC, "dc1")
|
||||||
|
|
||||||
svc := &structs.NodeService{
|
svc := &structs.NodeService{
|
||||||
ID: "redis",
|
ID: "redis",
|
||||||
Service: "redis",
|
Service: "redis",
|
||||||
|
@ -670,9 +675,18 @@ func verifyIndexChurn(t *testing.T, tags []string) {
|
||||||
ServiceName: "redis",
|
ServiceName: "redis",
|
||||||
}
|
}
|
||||||
var before structs.IndexedCheckServiceNodes
|
var before structs.IndexedCheckServiceNodes
|
||||||
|
|
||||||
|
// This sleep is so that the serfHealth check is added to the agent
|
||||||
|
// A value of 375ms is sufficient enough time to ensure the serfHealth
|
||||||
|
// check is added to an agent. 500ms so that we don't see flakiness ever.
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
if err := a.RPC("Health.ServiceNodes", args, &before); err != nil {
|
if err := a.RPC("Health.ServiceNodes", args, &before); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
for _, name := range before.Nodes[0].Checks {
|
||||||
|
a.logger.Println("[DEBUG] Checks Registered: ", name.Name)
|
||||||
|
}
|
||||||
if got, want := len(before.Nodes), 1; got != want {
|
if got, want := len(before.Nodes), 1; got != want {
|
||||||
t.Fatalf("got %d want %d", got, want)
|
t.Fatalf("got %d want %d", got, want)
|
||||||
}
|
}
|
||||||
|
@ -681,11 +695,14 @@ func verifyIndexChurn(t *testing.T, tags []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
|
a.logger.Println("[INFO] # ", i+1, "Sync in progress ")
|
||||||
if err := a.sync.State.SyncFull(); err != nil {
|
if err := a.sync.State.SyncFull(); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If this test fails here this means that the Consul-X-Index
|
||||||
|
// has changed for the RPC, which means that idempotent ops
|
||||||
|
// are not working as intended.
|
||||||
var after structs.IndexedCheckServiceNodes
|
var after structs.IndexedCheckServiceNodes
|
||||||
if err := a.RPC("Health.ServiceNodes", args, &after); err != nil {
|
if err := a.RPC("Health.ServiceNodes", args, &after); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
|
|
|
@ -2893,16 +2893,18 @@ func TestPreparedQuery_Wrapper(t *testing.T) {
|
||||||
wrapper.GetLogger().Printf("[DEBUG] Test")
|
wrapper.GetLogger().Printf("[DEBUG] Test")
|
||||||
|
|
||||||
ret, err := wrapper.GetOtherDatacentersByDistance()
|
ret, err := wrapper.GetOtherDatacentersByDistance()
|
||||||
|
wrapper.GetLogger().Println("Returned value: ", ret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if len(ret) != 1 || ret[0] != "dc2" {
|
if len(ret) != 1 || ret[0] != "dc2" {
|
||||||
t.Fatalf("bad: %v", ret)
|
t.Fatalf("bad: %v", ret)
|
||||||
}
|
}
|
||||||
|
// Since we have no idea when the joinWAN operation completes
|
||||||
if err := wrapper.ForwardDC("Status.Ping", "dc2", &struct{}{}, &struct{}{}); err != nil {
|
// we keep on querying until the the join operation completes.
|
||||||
t.Fatalf("err: %v", err)
|
retry.Run(t, func(r *retry.R) {
|
||||||
}
|
r.Check(s1.forwardDC("Status.Ping", "dc2", &struct{}{}, &struct{}{}))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockQueryServer struct {
|
type mockQueryServer struct {
|
||||||
|
|
Loading…
Reference in New Issue