mirror of https://github.com/status-im/consul.git
Fix `TestCatalogListNodes_StaleRaad` with `WaitForLeader`
This commit is contained in:
parent
f1b9dbe5c3
commit
aa00bfff7d
|
@ -2,8 +2,8 @@ package consul
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hashicorp/consul/testutil"
|
|
||||||
"github.com/hashicorp/consul/consul/structs"
|
"github.com/hashicorp/consul/consul/structs"
|
||||||
|
"github.com/hashicorp/consul/testutil"
|
||||||
"net/rpc"
|
"net/rpc"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -254,8 +254,13 @@ func TestCatalogListNodes_StaleRaad(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for a leader
|
args := structs.DCSpecificRequest{
|
||||||
time.Sleep(100 * time.Millisecond)
|
Datacenter: "dc1",
|
||||||
|
QueryOptions: structs.QueryOptions{AllowStale: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
testutil.WaitForLeader(t, client1.Call, args)
|
||||||
|
testutil.WaitForLeader(t, client2.Call, args)
|
||||||
|
|
||||||
// Use the follower as the client
|
// Use the follower as the client
|
||||||
var client *rpc.Client
|
var client *rpc.Client
|
||||||
|
@ -271,10 +276,6 @@ func TestCatalogListNodes_StaleRaad(t *testing.T) {
|
||||||
s2.fsm.State().EnsureNode(1, structs.Node{"foo", "127.0.0.1"})
|
s2.fsm.State().EnsureNode(1, structs.Node{"foo", "127.0.0.1"})
|
||||||
}
|
}
|
||||||
|
|
||||||
args := structs.DCSpecificRequest{
|
|
||||||
Datacenter: "dc1",
|
|
||||||
QueryOptions: structs.QueryOptions{AllowStale: true},
|
|
||||||
}
|
|
||||||
var out structs.IndexedNodes
|
var out structs.IndexedNodes
|
||||||
if err := client.Call("Catalog.ListNodes", &args, &out); err != nil {
|
if err := client.Call("Catalog.ListNodes", &args, &out); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
|
|
|
@ -27,14 +27,15 @@ func WaitForResult(test testFn, error errorFn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type clientRPC func(string, interface {}, interface {}) error
|
type rpcFn func(string, interface {}, interface {}) error
|
||||||
|
|
||||||
func WaitForLeader(t *testing.T, rpc clientRPC, args interface{}) {
|
func WaitForLeader(t *testing.T, rpc rpcFn, args interface{}) structs.IndexedNodes {
|
||||||
|
var out structs.IndexedNodes
|
||||||
WaitForResult(func() (bool, error) {
|
WaitForResult(func() (bool, error) {
|
||||||
var out structs.IndexedNodes
|
|
||||||
err := rpc("Catalog.ListNodes", args, &out)
|
err := rpc("Catalog.ListNodes", args, &out)
|
||||||
return out.QueryMeta.KnownLeader, err
|
return out.QueryMeta.KnownLeader, err
|
||||||
}, func(err error) {
|
}, func(err error) {
|
||||||
t.Fatalf("failed to find leader: %v", err)
|
t.Fatalf("failed to find leader: %v", err)
|
||||||
})
|
})
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue