fd927ea110
- Improve resilience of testrpc.WaitForLeader() - Add additionall retry to CI - Increase "go test" timeout to 8m - Add wait for cluster leader to several tests in the agent package - Add retry to some tests in the api and command packages
28 lines
675 B
Go
28 lines
675 B
Go
package testrpc
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
"github.com/hashicorp/consul/testutil/retry"
|
|
)
|
|
|
|
type rpcFn func(string, interface{}, interface{}) error
|
|
|
|
func WaitForLeader(t *testing.T, rpc rpcFn, dc string) {
|
|
var out structs.IndexedNodes
|
|
retry.Run(t, func(r *retry.R) {
|
|
// Ensure we have a leader and a node registration.
|
|
args := &structs.DCSpecificRequest{Datacenter: dc}
|
|
if err := rpc("Catalog.ListNodes", args, &out); err != nil {
|
|
r.Fatalf("Catalog.ListNodes failed: %v", err)
|
|
}
|
|
if !out.QueryMeta.KnownLeader {
|
|
r.Fatalf("No leader")
|
|
}
|
|
if out.Index < 2 {
|
|
r.Fatalf("Consul index should be at least 2")
|
|
}
|
|
})
|
|
}
|