test(e2e): Add increased retries due to worker status report changes (#5424)

pull/5426/head
Michael Li 1 year ago committed by GitHub
parent dce336500e
commit 91c060ca44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -6,10 +6,14 @@ package base_test
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt"
"testing" "testing"
"time" "time"
"github.com/cenkalti/backoff/v4"
"github.com/hashicorp/boundary/api/sessions" "github.com/hashicorp/boundary/api/sessions"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/testing/internal/e2e" "github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/hashicorp/boundary/testing/internal/e2e/boundary" "github.com/hashicorp/boundary/testing/internal/e2e/boundary"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -17,7 +21,7 @@ import (
) )
// TestCliBytesUpDownEmpty uses the cli to verify that the bytes_up/bytes_down fields of a // TestCliBytesUpDownEmpty uses the cli to verify that the bytes_up/bytes_down fields of a
// session correctly increase when data is transmitting during a session. // session do not change when no data is transmitted during a session.
func TestCliBytesUpDownEmpty(t *testing.T) { func TestCliBytesUpDownEmpty(t *testing.T) {
e2e.MaybeSkipTest(t) e2e.MaybeSkipTest(t)
c, err := loadTestConfig() c, err := loadTestConfig()
@ -35,17 +39,13 @@ func TestCliBytesUpDownEmpty(t *testing.T) {
}) })
projectId, err := boundary.CreateProjectCli(t, ctx, orgId) projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err) require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId) targetId, err := boundary.CreateTargetCli(
require.NoError(t, err) t,
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId) ctx,
require.NoError(t, err) projectId,
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress) c.TargetPort,
require.NoError(t, err) target.WithAddress(c.TargetAddress),
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId) )
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err) require.NoError(t, err)
// Create a session where no additional commands are run // Create a session where no additional commands are run
@ -72,43 +72,53 @@ func TestCliBytesUpDownEmpty(t *testing.T) {
session := boundary.WaitForSessionCli(t, ctx, projectId) session := boundary.WaitForSessionCli(t, ctx, projectId)
assert.Equal(t, targetId, session.TargetId) assert.Equal(t, targetId, session.TargetId)
assert.Equal(t, hostId, session.HostId)
// Confirm that bytesUp and bytesDown do not change // Wait until bytes up and down is greater than 0
t.Log("Waiting for bytes_up/bytes_down to be greater than 0...")
bytesUp := 0 bytesUp := 0
bytesDown := 0 bytesDown := 0
err = backoff.RetryNotify(
func() error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("sessions", "read", "-id", session.Id, "-format", "json"),
)
if output.Err != nil {
return backoff.Permanent(errors.New(string(output.Stderr)))
}
var newSessionReadResult sessions.SessionReadResult
err = json.Unmarshal(output.Stdout, &newSessionReadResult)
if err != nil {
return backoff.Permanent(err)
}
// Wait until bytes up and down is greater than 0 if len(newSessionReadResult.Item.Connections) == 0 {
t.Log("Waiting for bytes_up/bytes_down to be greater than 0...") return fmt.Errorf("no connections found in session")
for i := 0; i < 3; i++ { }
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("sessions", "read", "-id", session.Id, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
var newSessionReadResult sessions.SessionReadResult
err = json.Unmarshal(output.Stdout, &newSessionReadResult)
require.NoError(t, err)
if len(newSessionReadResult.Item.Connections) > 0 {
bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp) bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown) bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
t.Logf("bytes_up: %d, bytes_down: %d", bytesUp, bytesDown) if !(bytesUp > 0 && bytesDown > 0) {
return fmt.Errorf(
if bytesUp > 0 && bytesDown > 0 { "bytes_up: %d, bytes_down: %d, bytes_up or bytes_down is not greater than 0",
break bytesUp,
bytesDown,
)
} }
} else {
t.Log("No connections found in session. Retrying...")
}
time.Sleep(2 * time.Second) t.Logf("bytes_up: %d, bytes_down: %d", bytesUp, bytesDown)
} return nil
require.Greater(t, bytesUp, 0) },
require.Greater(t, bytesDown, 0) backoff.WithMaxRetries(backoff.NewConstantBackOff(3*time.Second), 5),
func(err error, td time.Duration) {
t.Logf("%s. Retrying...", err.Error())
},
)
require.NoError(t, err)
t.Log("Reading bytes_up/bytes_down values...") // Confirm that bytesUp and bytesDown do not change
for i := 0; i < 3; i++ { t.Log("Verifying bytes_up/bytes_down values do not change...")
time.Sleep(2 * time.Second) for i := 0; i < 5; i++ {
time.Sleep(3 * time.Second)
output := e2e.RunCommand(ctx, "boundary", output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("sessions", "read", "-id", session.Id, "-format", "json"), e2e.WithArgs("sessions", "read", "-id", session.Id, "-format", "json"),
@ -117,14 +127,11 @@ func TestCliBytesUpDownEmpty(t *testing.T) {
var newSessionReadResult sessions.SessionReadResult var newSessionReadResult sessions.SessionReadResult
err = json.Unmarshal(output.Stdout, &newSessionReadResult) err = json.Unmarshal(output.Stdout, &newSessionReadResult)
require.NoError(t, err) require.NoError(t, err)
bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp) newBytesUp := int(newSessionReadResult.Item.Connections[0].BytesUp)
bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown) newBytesDown := int(newSessionReadResult.Item.Connections[0].BytesDown)
t.Logf("bytes_up: %d, bytes_down: %d", newBytesUp, newBytesDown)
if i != 1 {
require.Equal(t, bytesUp, int(newSessionReadResult.Item.Connections[0].BytesUp))
require.Equal(t, bytesDown, int(newSessionReadResult.Item.Connections[0].BytesDown))
}
t.Logf("bytes_up: %d, bytes_down: %d", bytesUp, bytesDown) require.Equal(t, bytesUp, newBytesUp)
require.Equal(t, bytesDown, newBytesDown)
} }
} }

@ -6,11 +6,15 @@ package base_test
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt"
"testing" "testing"
"time" "time"
"github.com/cenkalti/backoff/v4"
"github.com/hashicorp/boundary/api/sessions" "github.com/hashicorp/boundary/api/sessions"
"github.com/hashicorp/boundary/internal/session" "github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/testing/internal/e2e" "github.com/hashicorp/boundary/testing/internal/e2e"
"github.com/hashicorp/boundary/testing/internal/e2e/boundary" "github.com/hashicorp/boundary/testing/internal/e2e/boundary"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -36,17 +40,13 @@ func TestCliBytesUpDownTransferData(t *testing.T) {
}) })
projectId, err := boundary.CreateProjectCli(t, ctx, orgId) projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err) require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId) targetId, err := boundary.CreateTargetCli(
require.NoError(t, err) t,
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId) ctx,
require.NoError(t, err) projectId,
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress) c.TargetPort,
require.NoError(t, err) target.WithAddress(c.TargetAddress),
err = boundary.AddHostToHostSetCli(t, ctx, hostSetId, hostId) )
require.NoError(t, err)
targetId, err := boundary.CreateTargetCli(t, ctx, projectId, c.TargetPort)
require.NoError(t, err)
err = boundary.AddHostSourceToTargetCli(t, ctx, targetId, hostSetId)
require.NoError(t, err) require.NoError(t, err)
// Create a session where no additional commands are run // Create a session where no additional commands are run
@ -76,60 +76,88 @@ func TestCliBytesUpDownTransferData(t *testing.T) {
s := boundary.WaitForSessionCli(t, ctx, projectId) s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String()) boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
assert.Equal(t, targetId, s.TargetId) assert.Equal(t, targetId, s.TargetId)
assert.Equal(t, hostId, s.HostId)
// Wait until bytes up and down is greater than 0
t.Log("Waiting for bytes_up/bytes_down to be greater than 0...")
bytesUp := 0 bytesUp := 0
bytesDown := 0 bytesDown := 0
err = backoff.RetryNotify(
func() error {
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("sessions", "read", "-id", s.Id, "-format", "json"),
)
if output.Err != nil {
return backoff.Permanent(errors.New(string(output.Stderr)))
}
var newSessionReadResult sessions.SessionReadResult
err = json.Unmarshal(output.Stdout, &newSessionReadResult)
if err != nil {
return backoff.Permanent(err)
}
// Wait until bytes up and down is greater than 0 if len(newSessionReadResult.Item.Connections) == 0 {
t.Log("Waiting for bytes_up/bytes_down to be greater than 0...") return fmt.Errorf("no connections found in session")
for i := 0; i < 3; i++ { }
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("sessions", "read", "-id", s.Id, "-format", "json"),
)
require.NoError(t, output.Err, string(output.Stderr))
var newSessionReadResult sessions.SessionReadResult
err = json.Unmarshal(output.Stdout, &newSessionReadResult)
require.NoError(t, err)
if len(newSessionReadResult.Item.Connections) > 0 {
bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp) bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown) bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
t.Logf("bytes_up: %d, bytes_down: %d", bytesUp, bytesDown) if !(bytesUp > 0 && bytesDown > 0) {
return fmt.Errorf(
if bytesUp > 0 && bytesDown > 0 { "bytes_up: %d, bytes_down: %d, bytes_up or bytes_down is not greater than 0",
break bytesUp,
bytesDown,
)
} }
} else {
t.Log("No connections found in session. Retrying...")
}
time.Sleep(2 * time.Second) t.Logf("bytes_up: %d, bytes_down: %d", bytesUp, bytesDown)
} return nil
require.Greater(t, bytesUp, 0) },
require.Greater(t, bytesDown, 0) backoff.WithMaxRetries(backoff.NewConstantBackOff(3*time.Second), 5),
func(err error, td time.Duration) {
t.Logf("%s. Retrying...", err.Error())
},
)
require.NoError(t, err)
// Confirm that bytes up and down increases // Confirm that bytes up and down increases
t.Log("Waiting for bytes_up/bytes_down to increase...") t.Log("Waiting for bytes_up/bytes_down to increase...")
var newBytesUp, newBytesDown int var newBytesUp, newBytesDown int
for i := 0; i < 3; i++ { err = backoff.RetryNotify(
output := e2e.RunCommand(ctx, "boundary", func() error {
e2e.WithArgs("sessions", "read", "-id", s.Id, "-format", "json"), output := e2e.RunCommand(ctx, "boundary",
) e2e.WithArgs("sessions", "read", "-id", s.Id, "-format", "json"),
require.NoError(t, output.Err, string(output.Stderr)) )
var newSessionReadResult sessions.SessionReadResult if output.Err != nil {
err = json.Unmarshal(output.Stdout, &newSessionReadResult) return backoff.Permanent(errors.New(string(output.Stderr)))
require.NoError(t, err) }
newBytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp) var newSessionReadResult sessions.SessionReadResult
newBytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown) err = json.Unmarshal(output.Stdout, &newSessionReadResult)
t.Logf("bytes_up: %d, bytes_down: %d", newBytesUp, newBytesDown) if err != nil {
return backoff.Permanent(err)
if newBytesDown > bytesDown { }
break
} if len(newSessionReadResult.Item.Connections) == 0 {
return fmt.Errorf("no connections found in session")
time.Sleep(2 * time.Second) }
}
require.GreaterOrEqual(t, newBytesUp, bytesUp) newBytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
require.Greater(t, newBytesDown, bytesDown) newBytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
if !(newBytesDown > bytesDown) || !(newBytesUp > bytesUp) {
return fmt.Errorf(
"bytes_up: %d, bytes_down: %d, bytes_up/bytes_down is not greater than previous value",
newBytesUp,
newBytesDown,
)
}
t.Logf("bytes_up: %d, bytes_down: %d", newBytesUp, newBytesDown)
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, err)
} }

Loading…
Cancel
Save