Skip to content

Commit

Permalink
Fixed unstable unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pierresouchay authored and Thibault Gilles committed Nov 9, 2018
1 parent b153f9b commit 3a99d79
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions agent/catalog_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ func TestCatalogServiceNodes_DistanceSort(t *testing.T) {
t.Parallel()
a := NewTestAgent(t.Name(), "")
defer a.Shutdown()
testrpc.WaitForLeader(t, a.RPC, "dc1")

// Register nodes.
args := &structs.RegisterRequest{
Expand Down Expand Up @@ -831,6 +832,7 @@ func TestCatalogServiceNodes_ConnectProxy(t *testing.T) {
assert := assert.New(t)
a := NewTestAgent(t.Name(), "")
defer a.Shutdown()
testrpc.WaitForLeader(t, a.RPC, "dc1")

// Register
args := structs.TestRegisterRequestProxy(t)
Expand Down Expand Up @@ -860,6 +862,7 @@ func TestCatalogConnectServiceNodes_good(t *testing.T) {
assert := assert.New(t)
a := NewTestAgent(t.Name(), "")
defer a.Shutdown()
testrpc.WaitForLeader(t, a.RPC, "dc1")

// Register
args := structs.TestRegisterRequestProxy(t)
Expand Down
18 changes: 10 additions & 8 deletions command/connect/proxy/register_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ func TestRegisterMonitor_heartbeat(t *testing.T) {
testrpc.WaitForTestAgent(t, a.RPC, "dc1")
m, _ := testMonitor(t, client)
defer m.Close()
retry.Run(t, func(r *retry.R) {
// Get the check and verify that it is passing
checks, err := client.Agent().Checks()
require.NoError(err)
require.Contains(checks, m.checkID())
require.Equal("passing", checks[m.checkID()].Status)
// Purposely fail the TTL check, verify it becomes healthy again
require.NoError(client.Agent().FailTTL(m.checkID(), ""))
})

// Get the check and verify that it is passing
checks, err := client.Agent().Checks()
require.NoError(err)
require.Contains(checks, m.checkID())
require.Equal("passing", checks[m.checkID()].Status)

// Purposely fail the TTL check, verify it becomes healthy again
require.NoError(client.Agent().FailTTL(m.checkID(), ""))
retry.Run(t, func(r *retry.R) {

checks, err := client.Agent().Checks()
if err != nil {
r.Fatalf("err: %s", err)
Expand Down
3 changes: 1 addition & 2 deletions command/watch/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"strings"
"testing"

"github.com/hashicorp/consul/testrpc"

"github.com/hashicorp/consul/agent"
"github.com/hashicorp/consul/testrpc"
"github.com/mitchellh/cli"
)

Expand Down

0 comments on commit 3a99d79

Please sign in to comment.