Skip to content

Commit 3d38cd5

Browse files
authored
test(cli): attempt to fix TestGitSSH flake (#21230)
Since the failing test logs are gone, we can only guess at what went wrong. Given our parallel test-suite, and that tests typically run slow on Windows, it seems reasonable that the context timed out due to a single context being responsbile for setup and two command executions. This change fixes the issue by updating the context usage, if this flake ever resurfaces, we can re-investigate. Fixes coder/internal#770
1 parent 2e4aa72 commit 3d38cd5

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

cli/gitssh_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@ func TestGitSSH(t *testing.T) {
116116
t.Run("Dial", func(t *testing.T) {
117117
t.Parallel()
118118

119-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
120-
defer cancel()
121-
122-
client, token, pubkey := prepareTestGitSSH(ctx, t)
119+
setupCtx := testutil.Context(t, testutil.WaitLong)
120+
client, token, pubkey := prepareTestGitSSH(setupCtx, t)
123121
var inc int64
124122
errC := make(chan error, 1)
125123
addr := serveSSHForGitSSH(t, func(s ssh.Session) {
@@ -143,6 +141,7 @@ func TestGitSSH(t *testing.T) {
143141
"-o", "IdentitiesOnly=yes",
144142
"127.0.0.1",
145143
)
144+
ctx := testutil.Context(t, testutil.WaitMedium)
146145
err := inv.WithContext(ctx).Run()
147146
require.NoError(t, err)
148147
require.EqualValues(t, 1, inc)
@@ -166,10 +165,8 @@ func TestGitSSH(t *testing.T) {
166165
require.NoError(t, err)
167166
writePrivateKeyToFile(t, idFile, privkey)
168167

169-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
170-
defer cancel()
171-
172-
client, token, coderPubkey := prepareTestGitSSH(ctx, t)
168+
setupCtx := testutil.Context(t, testutil.WaitLong)
169+
client, token, coderPubkey := prepareTestGitSSH(setupCtx, t)
173170

174171
authkey := make(chan gossh.PublicKey, 1)
175172
addr := serveSSHForGitSSH(t, func(s ssh.Session) {
@@ -208,6 +205,7 @@ func TestGitSSH(t *testing.T) {
208205
inv, _ := clitest.New(t, cmdArgs...)
209206
inv.Stdout = pty.Output()
210207
inv.Stderr = pty.Output()
208+
ctx := testutil.Context(t, testutil.WaitMedium)
211209
err = inv.WithContext(ctx).Run()
212210
require.NoError(t, err)
213211
select {
@@ -225,6 +223,7 @@ func TestGitSSH(t *testing.T) {
225223
inv, _ = clitest.New(t, cmdArgs...)
226224
inv.Stdout = pty.Output()
227225
inv.Stderr = pty.Output()
226+
ctx = testutil.Context(t, testutil.WaitMedium) // Reset context for second cmd test.
228227
err = inv.WithContext(ctx).Run()
229228
require.NoError(t, err)
230229
select {

0 commit comments

Comments
 (0)