mirror of https://github.com/hashicorp/consul
Adds a little wait after we get the event we were seeking.
parent
3967cfe833
commit
dcff5137f9
|
@ -336,7 +336,6 @@ func (s *TestServer) waitForLeader() {
|
||||||
if _, ok := taggedAddresses["lan"]; !ok {
|
if _, ok := taggedAddresses["lan"]; !ok {
|
||||||
return false, fmt.Errorf("No lan tagged addresses")
|
return false, fmt.Errorf("No lan tagged addresses")
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}, func(err error) {
|
}, func(err error) {
|
||||||
defer s.Stop()
|
defer s.Stop()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package testutil
|
package testutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ func WaitForResult(try testFn, fail errorFn) {
|
||||||
var success bool
|
var success bool
|
||||||
success, err = try()
|
success, err = try()
|
||||||
if success {
|
if success {
|
||||||
|
time.Sleep(25 * time.Millisecond)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,11 +41,20 @@ type rpcFn func(string, interface{}, interface{}) error
|
||||||
func WaitForLeader(t *testing.T, rpc rpcFn, dc string) structs.IndexedNodes {
|
func WaitForLeader(t *testing.T, rpc rpcFn, dc string) structs.IndexedNodes {
|
||||||
var out structs.IndexedNodes
|
var out structs.IndexedNodes
|
||||||
WaitForResult(func() (bool, error) {
|
WaitForResult(func() (bool, error) {
|
||||||
|
// Ensure we have a leader and a node registration.
|
||||||
args := &structs.DCSpecificRequest{
|
args := &structs.DCSpecificRequest{
|
||||||
Datacenter: dc,
|
Datacenter: dc,
|
||||||
}
|
}
|
||||||
err := rpc("Catalog.ListNodes", args, &out)
|
if err := rpc("Catalog.ListNodes", args, &out); err != nil {
|
||||||
return out.QueryMeta.KnownLeader && out.Index > 0, err
|
return false, fmt.Errorf("Catalog.ListNodes failed: %v", err)
|
||||||
|
}
|
||||||
|
if !out.QueryMeta.KnownLeader {
|
||||||
|
return false, fmt.Errorf("No leader")
|
||||||
|
}
|
||||||
|
if out.Index == 0 {
|
||||||
|
return false, fmt.Errorf("Consul index is 0")
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
}, func(err error) {
|
}, func(err error) {
|
||||||
t.Fatalf("failed to find leader: %v", err)
|
t.Fatalf("failed to find leader: %v", err)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue