mirror of https://github.com/status-im/consul.git
More flaky test fixes (#6151)
* Add retry to TestAPI_ClientTxn * Add retry to TestLeader_RegisterMember * Account for empty watch result in ConnectRootsWatch
This commit is contained in:
parent
95dbb7f2f1
commit
59dbd070d7
|
@ -68,13 +68,15 @@ func TestLeader_RegisterMember(t *testing.T) {
|
|||
}
|
||||
|
||||
// Server should be registered
|
||||
retry.Run(t, func(r *retry.R) {
|
||||
_, node, err := state.GetNode(s1.config.NodeName)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
r.Fatalf("err: %v", err)
|
||||
}
|
||||
if node == nil {
|
||||
t.Fatalf("server not registered")
|
||||
r.Fatalf("server not registered")
|
||||
}
|
||||
})
|
||||
|
||||
// Service should be registered
|
||||
_, services, err := state.NodeServices(nil, s1.config.NodeName)
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/consul/sdk/testutil/retry"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-uuid"
|
||||
|
||||
"github.com/pascaldekloe/goe/verify"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAPI_ClientTxn(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
c, s := makeClient(t)
|
||||
defer s.Stop()
|
||||
|
||||
|
@ -24,7 +23,7 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
|
||||
// Set up a test service and health check.
|
||||
nodeID, err := uuid.GenerateUUID()
|
||||
require.NoError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
catalog := c.Catalog()
|
||||
reg := &CatalogRegistration{
|
||||
|
@ -59,11 +58,11 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
},
|
||||
}
|
||||
_, err = catalog.Register(reg, nil)
|
||||
require.NoError(err)
|
||||
require.NoError(t, err)
|
||||
|
||||
node, _, err := catalog.Node("foo", nil)
|
||||
require.NoError(err)
|
||||
require.Equal(nodeID, node.Node.ID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, nodeID, node.Node.ID)
|
||||
|
||||
// Make a session.
|
||||
id, _, err := session.CreateNoChecks(nil, nil)
|
||||
|
@ -218,8 +217,9 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
verify.Values(t, "", ret.Results, expected)
|
||||
require.Equal(t, ret.Results, expected)
|
||||
|
||||
retry.Run(t, func(r *retry.R) {
|
||||
// Run a read-only transaction.
|
||||
ops = TxnOps{
|
||||
&TxnOp{
|
||||
|
@ -237,9 +237,9 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
}
|
||||
ok, ret, _, err = txn.Txn(ops, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
r.Fatalf("err: %v", err)
|
||||
} else if !ok {
|
||||
t.Fatalf("transaction failure")
|
||||
r.Fatalf("transaction failure")
|
||||
}
|
||||
|
||||
expected = TxnResults{
|
||||
|
@ -269,7 +269,8 @@ func TestAPI_ClientTxn(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
verify.Values(t, "", ret.Results, expected)
|
||||
require.Equal(r, ret.Results, expected)
|
||||
})
|
||||
|
||||
// Sanity check using the regular GET API.
|
||||
kv := c.KV()
|
||||
|
|
|
@ -715,7 +715,7 @@ func TestConnectRootsWatch(t *testing.T) {
|
|||
return // ignore
|
||||
}
|
||||
v, ok := raw.(*api.CARootList)
|
||||
if !ok || v == nil {
|
||||
if !ok || v == nil || len(v.Roots) == 0 {
|
||||
return // ignore
|
||||
}
|
||||
// Only 1 CA is the bootstrapped state (i.e. first response). Ignore this
|
||||
|
|
Loading…
Reference in New Issue