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 (
"context"
"encoding/json"
"errors"
"fmt"
"testing"
"time"
"github.com/cenkalti/backoff/v4"
"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/boundary"
"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
// 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) {
e2e.MaybeSkipTest(t)
c, err := loadTestConfig()
@ -35,17 +39,13 @@ func TestCliBytesUpDownEmpty(t *testing.T) {
})
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
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)
targetId, err := boundary.CreateTargetCli(
t,
ctx,
projectId,
c.TargetPort,
target.WithAddress(c.TargetAddress),
)
require.NoError(t, err)
// Create a session where no additional commands are run
@ -72,43 +72,53 @@ func TestCliBytesUpDownEmpty(t *testing.T) {
session := boundary.WaitForSessionCli(t, ctx, projectId)
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
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
t.Log("Waiting for bytes_up/bytes_down to be greater than 0...")
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 {
return fmt.Errorf("no connections found in session")
}
if len(newSessionReadResult.Item.Connections) > 0 {
bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
t.Logf("bytes_up: %d, bytes_down: %d", bytesUp, bytesDown)
if bytesUp > 0 && bytesDown > 0 {
break
if !(bytesUp > 0 && bytesDown > 0) {
return fmt.Errorf(
"bytes_up: %d, bytes_down: %d, bytes_up or bytes_down is not greater than 0",
bytesUp,
bytesDown,
)
}
} else {
t.Log("No connections found in session. Retrying...")
}
time.Sleep(2 * time.Second)
}
require.Greater(t, bytesUp, 0)
require.Greater(t, bytesDown, 0)
t.Logf("bytes_up: %d, bytes_down: %d", bytesUp, bytesDown)
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)
t.Log("Reading bytes_up/bytes_down values...")
for i := 0; i < 3; i++ {
time.Sleep(2 * time.Second)
// Confirm that bytesUp and bytesDown do not change
t.Log("Verifying bytes_up/bytes_down values do not change...")
for i := 0; i < 5; i++ {
time.Sleep(3 * time.Second)
output := e2e.RunCommand(ctx, "boundary",
e2e.WithArgs("sessions", "read", "-id", session.Id, "-format", "json"),
@ -117,14 +127,11 @@ func TestCliBytesUpDownEmpty(t *testing.T) {
var newSessionReadResult sessions.SessionReadResult
err = json.Unmarshal(output.Stdout, &newSessionReadResult)
require.NoError(t, err)
bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
if i != 1 {
require.Equal(t, bytesUp, int(newSessionReadResult.Item.Connections[0].BytesUp))
require.Equal(t, bytesDown, int(newSessionReadResult.Item.Connections[0].BytesDown))
}
newBytesUp := int(newSessionReadResult.Item.Connections[0].BytesUp)
newBytesDown := int(newSessionReadResult.Item.Connections[0].BytesDown)
t.Logf("bytes_up: %d, bytes_down: %d", newBytesUp, newBytesDown)
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 (
"context"
"encoding/json"
"errors"
"fmt"
"testing"
"time"
"github.com/cenkalti/backoff/v4"
"github.com/hashicorp/boundary/api/sessions"
"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/boundary"
"github.com/stretchr/testify/assert"
@ -36,17 +40,13 @@ func TestCliBytesUpDownTransferData(t *testing.T) {
})
projectId, err := boundary.CreateProjectCli(t, ctx, orgId)
require.NoError(t, err)
hostCatalogId, err := boundary.CreateHostCatalogCli(t, ctx, projectId)
require.NoError(t, err)
hostSetId, err := boundary.CreateHostSetCli(t, ctx, hostCatalogId)
require.NoError(t, err)
hostId, err := boundary.CreateHostCli(t, ctx, hostCatalogId, c.TargetAddress)
require.NoError(t, err)
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)
targetId, err := boundary.CreateTargetCli(
t,
ctx,
projectId,
c.TargetPort,
target.WithAddress(c.TargetAddress),
)
require.NoError(t, err)
// Create a session where no additional commands are run
@ -76,60 +76,88 @@ func TestCliBytesUpDownTransferData(t *testing.T) {
s := boundary.WaitForSessionCli(t, ctx, projectId)
boundary.WaitForSessionStatusCli(t, ctx, s.Id, session.StatusActive.String())
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
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
t.Log("Waiting for bytes_up/bytes_down to be greater than 0...")
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 {
return fmt.Errorf("no connections found in session")
}
if len(newSessionReadResult.Item.Connections) > 0 {
bytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
bytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
t.Logf("bytes_up: %d, bytes_down: %d", bytesUp, bytesDown)
if bytesUp > 0 && bytesDown > 0 {
break
if !(bytesUp > 0 && bytesDown > 0) {
return fmt.Errorf(
"bytes_up: %d, bytes_down: %d, bytes_up or bytes_down is not greater than 0",
bytesUp,
bytesDown,
)
}
} else {
t.Log("No connections found in session. Retrying...")
}
time.Sleep(2 * time.Second)
}
require.Greater(t, bytesUp, 0)
require.Greater(t, bytesDown, 0)
t.Logf("bytes_up: %d, bytes_down: %d", bytesUp, bytesDown)
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)
// Confirm that bytes up and down increases
t.Log("Waiting for bytes_up/bytes_down to increase...")
var newBytesUp, newBytesDown int
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)
newBytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
newBytesDown = int(newSessionReadResult.Item.Connections[0].BytesDown)
t.Logf("bytes_up: %d, bytes_down: %d", newBytesUp, newBytesDown)
if newBytesDown > bytesDown {
break
}
time.Sleep(2 * time.Second)
}
require.GreaterOrEqual(t, newBytesUp, bytesUp)
require.Greater(t, newBytesDown, bytesDown)
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)
}
if len(newSessionReadResult.Item.Connections) == 0 {
return fmt.Errorf("no connections found in session")
}
newBytesUp = int(newSessionReadResult.Item.Connections[0].BytesUp)
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