mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 14:24:39 +00:00
Merge pull request #2684 from hashicorp/b-early-acls
Fixes up ACL timing issues with unit tests.
This commit is contained in:
commit
ee0bc8db0b
@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -610,7 +611,9 @@ func TestAgent_Leave(t *testing.T) {
|
|||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c2.Agent().Leave(); err != nil {
|
// We sometimes see an EOF response to this one, depending on timing.
|
||||||
|
err := c2.Agent().Leave()
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user