Create clients with specific version for integration tests (#12978)

* tidy code and add some doc strings

* add doc strings to tests

* add partitions tests, need to adapt to run in both oss and ent

* split oss and enterprise versions

* remove parallel tests

* add error

* fix queryBackend in test

* revert unneeded change

* fix failing tests
This commit is contained in:
Dhia Ayachi 2022-05-09 14:36:49 -04:00 committed by GitHub
parent b895dd7d2d
commit feda67f4d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package consul_container
import ( import (
"context" "context"
"flag"
"fmt" "fmt"
"testing" "testing"
"time" "time"
@ -18,22 +17,19 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
var targetImage = flag.String("target-version", "local", "docker image to be used as UUT (unit under test)")
var latestImage = flag.String("latest-version", "latest", "docker image to be used as latest")
const retryTimeout = 10 * time.Second const retryTimeout = 10 * time.Second
const retryFrequency = 500 * time.Millisecond const retryFrequency = 500 * time.Millisecond
// Test health check GRPC call using Current Servers and Latest GA Clients // Test health check GRPC call using Current Servers and Latest GA Clients
func TestCurrentServersWithLatestGAClients(t *testing.T) { func TestCurrentServersWithLatestGAClients(t *testing.T) {
t.Parallel()
numServers := 3 numServers := 3
cluster, err := serversCluster(t, numServers, *targetImage) cluster, err := serversCluster(t, numServers, *targetImage)
require.NoError(t, err) require.NoError(t, err)
defer Terminate(t, cluster) defer Terminate(t, cluster)
numClients := 1 numClients := 1
clients, err := clientsCreate(numClients) clients, err := clientsCreate(numClients, *latestImage)
client := cluster.Nodes[0].GetClient() client := cluster.Nodes[0].GetClient()
err = cluster.AddNodes(clients) err = cluster.AddNodes(clients)
retry.RunWith(&retry.Timer{Timeout: retryTimeout, Wait: retryFrequency}, t, func(r *retry.R) { retry.RunWith(&retry.Timer{Timeout: retryTimeout, Wait: retryFrequency}, t, func(r *retry.R) {
@ -76,7 +72,7 @@ func TestCurrentServersWithLatestGAClients(t *testing.T) {
// Test health check GRPC call using Mixed (majority latest) Servers and Latest GA Clients // Test health check GRPC call using Mixed (majority latest) Servers and Latest GA Clients
func TestMixedServersMajorityLatestGAClient(t *testing.T) { func TestMixedServersMajorityLatestGAClient(t *testing.T) {
t.Parallel()
var configs []node.Config var configs []node.Config
configs = append(configs, configs = append(configs,
node.Config{ node.Config{
@ -105,7 +101,7 @@ func TestMixedServersMajorityLatestGAClient(t *testing.T) {
defer Terminate(t, cluster) defer Terminate(t, cluster)
numClients := 1 numClients := 1
clients, err := clientsCreate(numClients) clients, err := clientsCreate(numClients, *latestImage)
client := clients[0].GetClient() client := clients[0].GetClient()
err = cluster.AddNodes(clients) err = cluster.AddNodes(clients)
retry.RunWith(&retry.Timer{Timeout: retryTimeout, Wait: retryFrequency}, t, func(r *retry.R) { retry.RunWith(&retry.Timer{Timeout: retryTimeout, Wait: retryFrequency}, t, func(r *retry.R) {
@ -148,8 +144,9 @@ func TestMixedServersMajorityLatestGAClient(t *testing.T) {
// Test health check GRPC call using Mixed (majority current) Servers and Latest GA Clients // Test health check GRPC call using Mixed (majority current) Servers and Latest GA Clients
func TestMixedServersMajorityCurrentGAClient(t *testing.T) { func TestMixedServersMajorityCurrentGAClient(t *testing.T) {
t.Parallel()
var configs []node.Config var configs []node.Config
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
configs = append(configs, configs = append(configs,
node.Config{ node.Config{
@ -158,25 +155,26 @@ func TestMixedServersMajorityCurrentGAClient(t *testing.T) {
bootstrap_expect=3 bootstrap_expect=3
server=true`, server=true`,
Cmd: []string{"agent", "-client=0.0.0.0"}, Cmd: []string{"agent", "-client=0.0.0.0"},
Version: *targetImage, Version: *latestImage,
}) })
} }
configs = append(configs, configs = append(configs,
node.Config{ node.Config{
HCL: `node_name="` + utils.RandName("consul-server") + `" HCL: `node_name="` + utils.RandName("consul-server") + `"
log_level="TRACE" log_level="TRACE"
bootstrap_expect=3
server=true`, server=true`,
Cmd: []string{"agent", "-client=0.0.0.0"}, Cmd: []string{"agent", "-client=0.0.0.0"},
Version: *latestImage, Version: *targetImage,
}) })
cluster, err := cluster.New(configs) cluster, err := cluster.New(configs)
require.NoError(t, err) require.NoError(t, err)
defer Terminate(t, cluster) defer Terminate(t, cluster)
numClients := 1 numClients := 1
clients, err := clientsCreate(numClients) clients, err := clientsCreate(numClients, *latestImage)
client := clients[0].GetClient() client := clients[0].GetClient()
err = cluster.AddNodes(clients) err = cluster.AddNodes(clients)
retry.RunWith(&retry.Timer{Timeout: retryTimeout, Wait: retryFrequency}, t, func(r *retry.R) { retry.RunWith(&retry.Timer{Timeout: retryTimeout, Wait: retryFrequency}, t, func(r *retry.R) {
@ -217,7 +215,7 @@ func TestMixedServersMajorityCurrentGAClient(t *testing.T) {
} }
} }
func clientsCreate(numClients int) ([]node.Node, error) { func clientsCreate(numClients int, version string) ([]node.Node, error) {
clients := make([]node.Node, numClients) clients := make([]node.Node, numClients)
var err error var err error
for i := 0; i < numClients; i++ { for i := 0; i < numClients; i++ {
@ -226,7 +224,7 @@ func clientsCreate(numClients int) ([]node.Node, error) {
HCL: `node_name="` + utils.RandName("consul-client") + `" HCL: `node_name="` + utils.RandName("consul-client") + `"
log_level="TRACE"`, log_level="TRACE"`,
Cmd: []string{"agent", "-client=0.0.0.0"}, Cmd: []string{"agent", "-client=0.0.0.0"},
Version: *targetImage, Version: version,
}) })
} }
return clients, err return clients, err

View File

@ -0,0 +1,9 @@
//go:build !consulent
// +build !consulent
package consul_container
import "flag"
var targetImage = flag.String("target-version", "local", "docker image to be used as UUT (unit under test)")
var latestImage = flag.String("latest-version", "1.11", "docker image to be used as latest")