Skip to content

Commit

Permalink
Merge pull request #5347 from hashicorp/moduli-flake-worker-test
Browse files Browse the repository at this point in the history
Observed one instance of a test failure when the test failed to connect to the target after changing an API tag on the worker.
  • Loading branch information
moduli authored Dec 11, 2024
2 parents 4e59352 + 08c245c commit 8d7a9d7
Showing 1 changed file with 104 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ package base_with_worker_test
import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
"testing"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/hashicorp/boundary/api/workers"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/testing/internal/e2e"
Expand Down Expand Up @@ -234,19 +237,32 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
),
)
require.NoError(t, output.Err, string(output.Stderr))
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", targetId,
"-remote-command", "hostname -i",
"--",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
),
err = backoff.RetryNotify(
func() error {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", targetId,
"-remote-command", "hostname -i",
"--",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
),
)
if output.Err != nil {
return errors.New(string(output.Stderr))
}

require.Equal(t, c.TargetAddress, strings.TrimSpace(string(output.Stdout)))
return nil
},
backoff.WithMaxRetries(backoff.NewConstantBackOff(3*time.Second), 5),
func(err error, td time.Duration) {
t.Logf("%s. Retrying...", err.Error())
},
)
require.NoError(t, output.Err, string(output.Stderr))
require.Equal(t, c.TargetAddress, strings.TrimSpace(string(output.Stdout)))
require.NoError(t, err)
t.Log("Successfully connected to target with new filter")

// Update worker to have a different tag. This should result in a failed connection
Expand Down Expand Up @@ -293,19 +309,32 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
),
)
require.NoError(t, output.Err, string(output.Stderr))
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", targetId,
"-remote-command", "hostname -i",
"--",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
),
err = backoff.RetryNotify(
func() error {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", targetId,
"-remote-command", "hostname -i",
"--",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
),
)
if output.Err != nil {
return errors.New(string(output.Stderr))
}

require.Equal(t, c.TargetAddress, strings.TrimSpace(string(output.Stdout)))
return nil
},
backoff.WithMaxRetries(backoff.NewConstantBackOff(3*time.Second), 5),
func(err error, td time.Duration) {
t.Logf("%s. Retrying...", err.Error())
},
)
require.NoError(t, output.Err, string(output.Stderr))
require.Equal(t, c.TargetAddress, strings.TrimSpace(string(output.Stdout)))
require.NoError(t, err)
t.Log("Successfully connected to target with new filter")

// Remove API tags
Expand Down Expand Up @@ -359,22 +388,36 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
),
)
require.NoError(t, output.Err, string(output.Stderr))
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", targetId,
"-remote-command", "hostname -i",
"--",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
),
err = backoff.RetryNotify(
func() error {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", targetId,
"-remote-command", "hostname -i",
"--",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
),
)
if output.Err != nil {
return errors.New(string(output.Stderr))
}

require.Equal(t, c.TargetAddress, strings.TrimSpace(string(output.Stdout)))
return nil
},
backoff.WithMaxRetries(backoff.NewConstantBackOff(3*time.Second), 5),
func(err error, td time.Duration) {
t.Logf("%s. Retrying...", err.Error())
},
)
require.NoError(t, output.Err, string(output.Stderr))
require.Equal(t, c.TargetAddress, strings.TrimSpace(string(output.Stdout)))
require.NoError(t, err)
t.Log("Successfully connected to target")

// Remove API tag
t.Log("Removing API tag...")
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"workers", "remove-worker-tags",
Expand All @@ -383,18 +426,31 @@ func TestCliTcpTargetWorkerConnectTarget(t *testing.T) {
),
)
require.NoError(t, output.Err, string(output.Stderr))
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", targetId,
"-remote-command", "hostname -i",
"--",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
),
err = backoff.RetryNotify(
func() error {
output = e2e.RunCommand(ctx, "boundary",
e2e.WithArgs(
"connect", "ssh",
"-target-id", targetId,
"-remote-command", "hostname -i",
"--",
"-o", "UserKnownHostsFile=/dev/null",
"-o", "StrictHostKeyChecking=no",
"-o", "IdentitiesOnly=yes", // forces the use of the provided key
),
)
if output.Err != nil {
return errors.New(string(output.Stderr))
}

require.Equal(t, c.TargetAddress, strings.TrimSpace(string(output.Stdout)))
return nil
},
backoff.WithMaxRetries(backoff.NewConstantBackOff(3*time.Second), 5),
func(err error, td time.Duration) {
t.Logf("%s. Retrying...", err.Error())
},
)
require.NoError(t, output.Err, string(output.Stderr))
require.Equal(t, c.TargetAddress, strings.TrimSpace(string(output.Stdout)))
require.NoError(t, err)
t.Log("Successfully connected to target")
}

0 comments on commit 8d7a9d7

Please sign in to comment.