Skip to content

Commit 3311ab1

Browse files
committed
Fix flaky ListCommand integration test
1 parent e8a439e commit 3311ab1

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

qa-plugin/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ require (
2828
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
2929
github.com/go-git/go-billy/v5 v5.6.0 // indirect
3030
github.com/go-git/go-git/v5 v5.13.0 // indirect
31-
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
31+
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
3232
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
3333
github.com/golang/snappy v0.0.4 // indirect
3434
github.com/google/uuid v1.6.0 // indirect
@@ -83,7 +83,7 @@ require (
8383
golang.org/x/crypto v0.35.0 // indirect
8484
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
8585
golang.org/x/mod v0.22.0 // indirect
86-
golang.org/x/net v0.33.0 // indirect
86+
golang.org/x/net v0.36.0 // indirect
8787
golang.org/x/sync v0.11.0 // indirect
8888
golang.org/x/sys v0.30.0 // indirect
8989
golang.org/x/term v0.29.0 // indirect

qa-plugin/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ github.com/go-git/go-git/v5 v5.13.0 h1:vLn5wlGIh/X78El6r3Jr+30W16Blk0CTcxTYcYPWi
6969
github.com/go-git/go-git/v5 v5.13.0/go.mod h1:Wjo7/JyVKtQgUNdXYXIepzWfJQkUEIGvkvVkiXRR/zw=
7070
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
7171
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
72+
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
7273
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
7374
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
7475
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
@@ -235,6 +236,7 @@ golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
235236
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
236237
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
237238
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
239+
golang.org/x/net v0.36.0/go.mod h1:bFmbeoIPfrw4sMHNhb4J9f6+tPziuGjq7Jk/38fxi1I=
238240
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
239241
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
240242
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=

test/commands/show_execution_history_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestShowExecutionHistory(t *testing.T) {
6767

6868
for _, tt := range tests {
6969
it.Run(tt.name, func(t *infra.Test) {
70-
it.ResetOutput()
70+
it.ResetIO()
7171
tt.test(t, workerKey)
7272
})
7373
}

test/infra/itest_runner.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ type Test struct {
4242
AccessToken string
4343
dataDir string
4444
platformUrl string
45-
output *bytes.Buffer
45+
input string
46+
stdout *bytes.Buffer
47+
stdin *bytes.Reader
4648
t *testing.T
4749
}
4850

@@ -124,10 +126,12 @@ func runTest(t *testing.T, testSpec TestDefinition) {
124126
AccessToken: accessToken,
125127
dataDir: homeDir,
126128
platformUrl: platformUrl,
129+
input: testSpec.Input,
127130
}
128131

129132
if testSpec.Input != "" {
130-
common.SetCliIn(bytes.NewReader([]byte(testSpec.Input)))
133+
it.stdin = bytes.NewReader([]byte(testSpec.Input))
134+
common.SetCliIn(it.stdin)
131135
t.Cleanup(func() {
132136
common.SetCliIn(os.Stdin)
133137
})
@@ -139,7 +143,7 @@ func runTest(t *testing.T, testSpec TestDefinition) {
139143
t.Cleanup(func() {
140144
common.SetCliOut(os.Stdout)
141145
})
142-
it.output = &newOutput
146+
it.stdout = &newOutput
143147
}
144148

145149
testSpec.Test(it)
@@ -187,6 +191,7 @@ func (it *Test) RetryCommand(args []string, backoff time.Duration, timeout time.
187191

188192
for shouldRetryCommandOnError(err, onErrorContaining) && elapsed < timeout {
189193
time.Sleep(waitDuration)
194+
it.ResetIO()
190195
err = runPlugin()
191196
elapsed = time.Since(start)
192197
}
@@ -209,8 +214,8 @@ func shouldRetryCommandOnError(err error, onErrorContaining []string) bool {
209214
}
210215

211216
func (it *Test) CapturedOutput() []byte {
212-
if it.output != nil {
213-
return it.output.Bytes()
217+
if it.stdout != nil {
218+
return it.stdout.Bytes()
214219
}
215220
return nil
216221
}
@@ -271,9 +276,12 @@ func (it *Test) DeleteWorker(workerKey string) {
271276
}
272277
}
273278

274-
func (it *Test) ResetOutput() {
275-
if it.output != nil {
276-
it.output.Reset()
279+
func (it *Test) ResetIO() {
280+
if it.stdin != nil {
281+
it.stdin.Reset([]byte(it.input))
282+
}
283+
if it.stdout != nil {
284+
it.stdout.Reset()
277285
}
278286
}
279287

@@ -347,7 +355,7 @@ func (it *Test) Helper() {
347355

348356
func (it *Test) Run(name string, f func(t *Test)) bool {
349357
return it.t.Run(name, func(t *testing.T) {
350-
f(&Test{t: t, ServerId: it.ServerId, AccessToken: it.AccessToken, dataDir: it.dataDir, output: it.output})
358+
f(&Test{t: t, ServerId: it.ServerId, AccessToken: it.AccessToken, dataDir: it.dataDir, stdout: it.stdout, stdin: it.stdin, input: it.input})
351359
})
352360
}
353361

0 commit comments

Comments
 (0)