@@ -8,20 +8,21 @@ import (
8
8
"os/exec"
9
9
"strings"
10
10
"testing"
11
- "time"
12
11
13
- "github.com/coder/coder/pty"
14
12
"github.com/hinshun/vt10x"
15
13
"github.com/stretchr/testify/assert"
16
14
"github.com/stretchr/testify/require"
15
+
16
+ "github.com/coder/coder/pty"
17
+ "github.com/coder/coder/testutil"
17
18
)
18
19
19
20
// Test_Start_copy tests that we can use io.Copy() on command output
20
21
// without deadlocking.
21
22
func Test_Start_copy (t * testing.T ) {
22
23
t .Parallel ()
23
24
24
- ctx , cancel := context .WithTimeout (context .Background (), time . Second * 10 )
25
+ ctx , cancel := context .WithTimeout (context .Background (), testutil . WaitShort )
25
26
defer cancel ()
26
27
27
28
pc , cmd , err := pty .Start (exec .CommandContext (ctx , cmdEcho , argEcho ... ))
@@ -54,12 +55,12 @@ func Test_Start_copy(t *testing.T) {
54
55
}
55
56
}
56
57
57
- // Test_Start_truncation tests that we can read command ouput without truncation
58
+ // Test_Start_truncation tests that we can read command output without truncation
58
59
// even after the command has exited.
59
60
func Test_Start_trucation (t * testing.T ) {
60
61
t .Parallel ()
61
62
62
- ctx , cancel := context .WithTimeout (context .Background (), time . Second * 1000 )
63
+ ctx , cancel := context .WithTimeout (context .Background (), testutil . WaitLong )
63
64
defer cancel ()
64
65
65
66
pc , cmd , err := pty .Start (exec .CommandContext (ctx , cmdCount , argCount ... ))
@@ -73,7 +74,10 @@ func Test_Start_trucation(t *testing.T) {
73
74
for n < countEnd - 25 {
74
75
want := fmt .Sprintf ("%d" , n )
75
76
err := readUntil (ctx , t , want , pc .OutputReader ())
76
- require .NoError (t , err , "want: %s" , want )
77
+ assert .NoError (t , err , "want: %s" , want )
78
+ if err != nil {
79
+ return
80
+ }
77
81
n ++
78
82
}
79
83
}()
@@ -106,14 +110,16 @@ func Test_Start_trucation(t *testing.T) {
106
110
for n <= countEnd {
107
111
want := fmt .Sprintf ("%d" , n )
108
112
err := readUntil (ctx , t , want , pc .OutputReader ())
109
- require .NoError (t , err , "want: %s" , want )
113
+ assert .NoError (t , err , "want: %s" , want )
114
+ if err != nil {
115
+ return
116
+ }
110
117
n ++
111
118
}
112
119
// ensure we still get to EOF
113
120
endB := & bytes.Buffer {}
114
121
_ , err := io .Copy (endB , pc .OutputReader ())
115
- require .NoError (t , err )
116
-
122
+ assert .NoError (t , err )
117
123
}()
118
124
119
125
select {
0 commit comments