- Notifications
You must be signed in to change notification settings - Fork928
fix(scaletest/workspacetraffic): wait for non-zero metrics before cancelling in TestRun#9663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -16,6 +16,7 @@ import ( | ||
"github.com/coder/coder/v2/provisionersdk/proto" | ||
"github.com/coder/coder/v2/scaletest/workspacetraffic" | ||
"github.com/coder/coder/v2/testutil" | ||
"golang.org/x/exp/slices" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
@@ -97,7 +98,6 @@ func TestRun(t *testing.T) { | ||
var ( | ||
bytesPerTick = 1024 | ||
tickInterval = 1000 * time.Millisecond | ||
fudgeWrite = 12 // The ReconnectingPTY payload incurs some overhead | ||
readMetrics = &testMetrics{} | ||
writeMetrics = &testMetrics{} | ||
@@ -113,12 +113,32 @@ func TestRun(t *testing.T) { | ||
}) | ||
var logs strings.Builder | ||
runDone := make(chan struct{}) | ||
go func() { | ||
defer close(runDone) | ||
err := runner.Run(ctx, "", &logs) | ||
assert.NoError(t, err, "unexpected error calling Run()") | ||
}() | ||
gotMetrics := make(chan struct{}) | ||
go func() { | ||
defer close(gotMetrics) | ||
// Wait until we get some non-zero metrics before canceling. | ||
assert.Eventually(t, func() bool { | ||
readLatencies := readMetrics.Latencies() | ||
writeLatencies := writeMetrics.Latencies() | ||
return len(readLatencies) > 0 && | ||
len(writeLatencies) > 0 && | ||
slices.ContainsFunc(readLatencies, func(f float64) bool { return f > 0.0 }) && | ||
slices.ContainsFunc(writeLatencies, func(f float64) bool { return f > 0.0 }) | ||
}, testutil.WaitLong, testutil.IntervalMedium, "expected non-zero metrics") | ||
}() | ||
// Stop the test after we get some non-zero metrics. | ||
<-gotMetrics | ||
cancel() | ||
<-runDone | ||
t.Logf("read errors: %.0f\n", readMetrics.Errors()) | ||
t.Logf("write errors: %.0f\n", writeMetrics.Errors()) | ||
@@ -132,12 +152,6 @@ func TestRun(t *testing.T) { | ||
assert.NotZero(t, readMetrics.Total()) | ||
// Latency should report non-zero values. | ||
assert.NotEmpty(t, readMetrics.Latencies()) | ||
assert.NotEmpty(t, writeMetrics.Latencies()) | ||
// Should not report any errors! | ||
assert.Zero(t, readMetrics.Errors()) | ||
@@ -210,7 +224,6 @@ func TestRun(t *testing.T) { | ||
var ( | ||
bytesPerTick = 1024 | ||
tickInterval = 1000 * time.Millisecond | ||
fudgeWrite = 2 // We send \r\n, which is two bytes | ||
readMetrics = &testMetrics{} | ||
writeMetrics = &testMetrics{} | ||
@@ -226,12 +239,32 @@ func TestRun(t *testing.T) { | ||
}) | ||
var logs strings.Builder | ||
runDone := make(chan struct{}) | ||
go func() { | ||
defer close(runDone) | ||
err := runner.Run(ctx, "", &logs) | ||
assert.NoError(t, err, "unexpected error calling Run()") | ||
}() | ||
gotMetrics := make(chan struct{}) | ||
go func() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nit: I'm always confused if there is a possibility of a routine leak. defer goes first then routine is killed, right? MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Defer runs when the surrounding function returns. So I think | ||
defer close(gotMetrics) | ||
// Wait until we get some non-zero metrics before canceling. | ||
assert.Eventually(t, func() bool { | ||
readLatencies := readMetrics.Latencies() | ||
writeLatencies := writeMetrics.Latencies() | ||
return len(readLatencies) > 0 && | ||
len(writeLatencies) > 0 && | ||
slices.ContainsFunc(readLatencies, func(f float64) bool { return f > 0.0 }) && | ||
slices.ContainsFunc(writeLatencies, func(f float64) bool { return f > 0.0 }) | ||
}, testutil.WaitLong, testutil.IntervalMedium, "expected non-zero metrics") | ||
}() | ||
// Stop the test after we get some non-zero metrics. | ||
<-gotMetrics | ||
cancel() | ||
<-runDone | ||
t.Logf("read errors: %.0f\n", readMetrics.Errors()) | ||
t.Logf("write errors: %.0f\n", writeMetrics.Errors()) | ||
@@ -245,12 +278,6 @@ func TestRun(t *testing.T) { | ||
assert.NotZero(t, readMetrics.Total()) | ||
// Latency should report non-zero values. | ||
assert.NotEmpty(t, readMetrics.Latencies()) | ||
assert.NotEmpty(t, writeMetrics.Latencies()) | ||
// Should not report any errors! | ||
assert.Zero(t, readMetrics.Errors()) | ||