Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3be783b

Browse files
authored
fix(scaletest/workspacetraffic): wait for non-zero metrics before cancelling in TestRun (#9663)
1 parent254f459 commit3be783b

File tree

1 file changed

+49
-22
lines changed

1 file changed

+49
-22
lines changed

‎scaletest/workspacetraffic/run_test.go

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/coder/coder/v2/provisionersdk/proto"
1717
"github.com/coder/coder/v2/scaletest/workspacetraffic"
1818
"github.com/coder/coder/v2/testutil"
19+
"golang.org/x/exp/slices"
1920

2021
"github.com/google/uuid"
2122
"github.com/stretchr/testify/assert"
@@ -97,7 +98,6 @@ func TestRun(t *testing.T) {
9798
var (
9899
bytesPerTick=1024
99100
tickInterval=1000*time.Millisecond
100-
cancelAfter=1500*time.Millisecond
101101
fudgeWrite=12// The ReconnectingPTY payload incurs some overhead
102102
readMetrics=&testMetrics{}
103103
writeMetrics=&testMetrics{}
@@ -113,12 +113,32 @@ func TestRun(t *testing.T) {
113113
})
114114

115115
varlogs strings.Builder
116-
// Stop the test after one 'tick'. This will cause an EOF.
116+
117+
runDone:=make(chanstruct{})
117118
gofunc() {
118-
<-time.After(cancelAfter)
119-
cancel()
119+
deferclose(runDone)
120+
err:=runner.Run(ctx,"",&logs)
121+
assert.NoError(t,err,"unexpected error calling Run()")
122+
}()
123+
124+
gotMetrics:=make(chanstruct{})
125+
gofunc() {
126+
deferclose(gotMetrics)
127+
// Wait until we get some non-zero metrics before canceling.
128+
assert.Eventually(t,func()bool {
129+
readLatencies:=readMetrics.Latencies()
130+
writeLatencies:=writeMetrics.Latencies()
131+
returnlen(readLatencies)>0&&
132+
len(writeLatencies)>0&&
133+
slices.ContainsFunc(readLatencies,func(ffloat64)bool {returnf>0.0 })&&
134+
slices.ContainsFunc(writeLatencies,func(ffloat64)bool {returnf>0.0 })
135+
},testutil.WaitLong,testutil.IntervalMedium,"expected non-zero metrics")
120136
}()
121-
require.NoError(t,runner.Run(ctx,"",&logs),"unexpected error calling Run()")
137+
138+
// Stop the test after we get some non-zero metrics.
139+
<-gotMetrics
140+
cancel()
141+
<-runDone
122142

123143
t.Logf("read errors: %.0f\n",readMetrics.Errors())
124144
t.Logf("write errors: %.0f\n",writeMetrics.Errors())
@@ -132,12 +152,6 @@ func TestRun(t *testing.T) {
132152
assert.NotZero(t,readMetrics.Total())
133153
// Latency should report non-zero values.
134154
assert.NotEmpty(t,readMetrics.Latencies())
135-
for_,l:=rangereadMetrics.Latencies()[1:] {// skip the first one, which is always zero
136-
assert.NotZero(t,l)
137-
}
138-
for_,l:=rangewriteMetrics.Latencies()[1:] {// skip the first one, which is always zero
139-
assert.NotZero(t,l)
140-
}
141155
assert.NotEmpty(t,writeMetrics.Latencies())
142156
// Should not report any errors!
143157
assert.Zero(t,readMetrics.Errors())
@@ -210,7 +224,6 @@ func TestRun(t *testing.T) {
210224
var (
211225
bytesPerTick=1024
212226
tickInterval=1000*time.Millisecond
213-
cancelAfter=1500*time.Millisecond
214227
fudgeWrite=2// We send \r\n, which is two bytes
215228
readMetrics=&testMetrics{}
216229
writeMetrics=&testMetrics{}
@@ -226,12 +239,32 @@ func TestRun(t *testing.T) {
226239
})
227240

228241
varlogs strings.Builder
229-
// Stop the test after one 'tick'. This will cause an EOF.
242+
243+
runDone:=make(chanstruct{})
230244
gofunc() {
231-
<-time.After(cancelAfter)
232-
cancel()
245+
deferclose(runDone)
246+
err:=runner.Run(ctx,"",&logs)
247+
assert.NoError(t,err,"unexpected error calling Run()")
248+
}()
249+
250+
gotMetrics:=make(chanstruct{})
251+
gofunc() {
252+
deferclose(gotMetrics)
253+
// Wait until we get some non-zero metrics before canceling.
254+
assert.Eventually(t,func()bool {
255+
readLatencies:=readMetrics.Latencies()
256+
writeLatencies:=writeMetrics.Latencies()
257+
returnlen(readLatencies)>0&&
258+
len(writeLatencies)>0&&
259+
slices.ContainsFunc(readLatencies,func(ffloat64)bool {returnf>0.0 })&&
260+
slices.ContainsFunc(writeLatencies,func(ffloat64)bool {returnf>0.0 })
261+
},testutil.WaitLong,testutil.IntervalMedium,"expected non-zero metrics")
233262
}()
234-
require.NoError(t,runner.Run(ctx,"",&logs),"unexpected error calling Run()")
263+
264+
// Stop the test after we get some non-zero metrics.
265+
<-gotMetrics
266+
cancel()
267+
<-runDone
235268

236269
t.Logf("read errors: %.0f\n",readMetrics.Errors())
237270
t.Logf("write errors: %.0f\n",writeMetrics.Errors())
@@ -245,12 +278,6 @@ func TestRun(t *testing.T) {
245278
assert.NotZero(t,readMetrics.Total())
246279
// Latency should report non-zero values.
247280
assert.NotEmpty(t,readMetrics.Latencies())
248-
for_,l:=rangereadMetrics.Latencies()[1:] {// skip the first one, which is always zero
249-
assert.NotZero(t,l)
250-
}
251-
for_,l:=rangewriteMetrics.Latencies()[1:] {// skip the first one, which is always zero
252-
assert.NotZero(t,l)
253-
}
254281
assert.NotEmpty(t,writeMetrics.Latencies())
255282
// Should not report any errors!
256283
assert.Zero(t,readMetrics.Errors())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp