2022-05-18 19:52:26 +00:00
|
|
|
package upgrade
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/api"
|
|
|
|
"github.com/hashicorp/consul/integration/consul-container/libs/cluster"
|
|
|
|
"github.com/hashicorp/consul/sdk/testutil/retry"
|
|
|
|
)
|
|
|
|
|
|
|
|
const retryTimeout = 20 * time.Second
|
|
|
|
const retryFrequency = 500 * time.Millisecond
|
|
|
|
|
|
|
|
func LongFailer() *retry.Timer {
|
|
|
|
return &retry.Timer{Timeout: retryTimeout, Wait: retryFrequency}
|
|
|
|
}
|
|
|
|
|
2022-05-19 19:05:41 +00:00
|
|
|
func waitForLeader(t *testing.T, Cluster *cluster.Cluster, client *api.Client) {
|
2022-05-18 19:52:26 +00:00
|
|
|
retry.RunWith(LongFailer(), t, func(r *retry.R) {
|
|
|
|
leader, err := Cluster.Leader()
|
|
|
|
require.NoError(r, err)
|
|
|
|
require.NotEmpty(r, leader)
|
|
|
|
})
|
2022-05-19 19:05:41 +00:00
|
|
|
|
|
|
|
if client != nil {
|
|
|
|
waitForLeaderFromClient(t, client)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func waitForLeaderFromClient(t *testing.T, client *api.Client) {
|
|
|
|
retry.RunWith(LongFailer(), t, func(r *retry.R) {
|
|
|
|
leader, err := cluster.GetLeader(client)
|
|
|
|
require.NoError(r, err)
|
|
|
|
require.NotEmpty(r, leader)
|
|
|
|
})
|
2022-05-18 19:52:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func waitForMembers(t *testing.T, client *api.Client, expectN int) {
|
|
|
|
retry.RunWith(LongFailer(), t, func(r *retry.R) {
|
|
|
|
members, err := client.Agent().Members(false)
|
|
|
|
require.NoError(r, err)
|
|
|
|
require.Len(r, members, expectN)
|
|
|
|
})
|
|
|
|
}
|