@@ -7,12 +7,14 @@ import (
7
7
"net"
8
8
"os/exec"
9
9
"testing"
10
- "time"
11
10
12
- "cdr.dev/slog/sloggers/slogtest"
13
11
gliderssh "github.com/gliderlabs/ssh"
14
12
"github.com/stretchr/testify/assert"
15
13
"github.com/stretchr/testify/require"
14
+
15
+ "github.com/coder/coder/testutil"
16
+
17
+ "cdr.dev/slog/sloggers/slogtest"
16
18
)
17
19
18
20
const longScript = `
@@ -28,7 +30,7 @@ echo "done"
28
30
func Test_sessionStart_orphan (t * testing.T ) {
29
31
t .Parallel ()
30
32
31
- ctx , cancel := context .WithTimeout (context .Background (), 10 * time . Second )
33
+ ctx , cancel := context .WithTimeout (context .Background (), testutil . WaitMedium )
32
34
defer cancel ()
33
35
logger := slogtest .Make (t , nil )
34
36
s , err := NewServer (ctx , logger , 0 )
@@ -62,12 +64,12 @@ func Test_sessionStart_orphan(t *testing.T) {
62
64
go func () {
63
65
defer close (readDone )
64
66
s := bufio .NewScanner (toClient )
65
- require .True (t , s .Scan ())
67
+ assert .True (t , s .Scan ())
66
68
txt := s .Text ()
67
69
assert .Equal (t , "started" , txt , "output corrupted" )
68
70
}()
69
71
70
- waitForChan (t , readDone , ctx , "read timeout" )
72
+ waitForChan (ctx , t , readDone , "read timeout" )
71
73
// process is started, and should be sleeping for ~30 seconds
72
74
73
75
sessionCancel ()
@@ -77,13 +79,13 @@ func Test_sessionStart_orphan(t *testing.T) {
77
79
// that the server isn't properly shutting down sessions when they are
78
80
// disconnected client side, which could lead to processes hanging around
79
81
// indefinitely.
80
- waitForChan (t , done , ctx , "handler timeout" )
82
+ waitForChan (ctx , t , done , "handler timeout" )
81
83
82
84
err = fromClient .Close ()
83
85
require .NoError (t , err )
84
86
}
85
87
86
- func waitForChan (t * testing.T , c <- chan struct {}, ctx context. Context , msg string ) {
88
+ func waitForChan (ctx context. Context , t * testing.T , c <- chan struct {}, msg string ) {
87
89
t .Helper ()
88
90
select {
89
91
case <- c :
@@ -121,12 +123,12 @@ func (s *testSession) Context() gliderssh.Context {
121
123
return s .ctx
122
124
}
123
125
124
- func (s * testSession ) DisablePTYEmulation () {}
126
+ func (* testSession ) DisablePTYEmulation () {}
125
127
126
128
// RawCommand returns "quiet logon" so that the PTY handler doesn't attempt to
127
129
// write the message of the day, which will interfere with our tests. It writes
128
130
// the message of the day if it's a shell login (zero length RawCommand()).
129
- func (s * testSession ) RawCommand () string { return "quiet logon" }
131
+ func (* testSession ) RawCommand () string { return "quiet logon" }
130
132
131
133
func (s * testSession ) Read (p []byte ) (n int , err error ) {
132
134
return s .toPty .Read (p )
@@ -136,49 +138,49 @@ func (s *testSession) Write(p []byte) (n int, err error) {
136
138
return s .fromPty .Write (p )
137
139
}
138
140
139
- func (c testSSHContext ) Lock () {
141
+ func (testSSHContext ) Lock () {
140
142
panic ("not implemented" )
141
143
}
142
- func (c testSSHContext ) Unlock () {
144
+ func (testSSHContext ) Unlock () {
143
145
panic ("not implemented" )
144
146
}
145
147
146
148
// User returns the username used when establishing the SSH connection.
147
- func (c testSSHContext ) User () string {
149
+ func (testSSHContext ) User () string {
148
150
panic ("not implemented" )
149
151
}
150
152
151
153
// SessionID returns the session hash.
152
- func (c testSSHContext ) SessionID () string {
154
+ func (testSSHContext ) SessionID () string {
153
155
panic ("not implemented" )
154
156
}
155
157
156
158
// ClientVersion returns the version reported by the client.
157
- func (c testSSHContext ) ClientVersion () string {
159
+ func (testSSHContext ) ClientVersion () string {
158
160
panic ("not implemented" )
159
161
}
160
162
161
163
// ServerVersion returns the version reported by the server.
162
- func (c testSSHContext ) ServerVersion () string {
164
+ func (testSSHContext ) ServerVersion () string {
163
165
panic ("not implemented" )
164
166
}
165
167
166
168
// RemoteAddr returns the remote address for this connection.
167
- func (c testSSHContext ) RemoteAddr () net.Addr {
169
+ func (testSSHContext ) RemoteAddr () net.Addr {
168
170
panic ("not implemented" )
169
171
}
170
172
171
173
// LocalAddr returns the local address for this connection.
172
- func (c testSSHContext ) LocalAddr () net.Addr {
174
+ func (testSSHContext ) LocalAddr () net.Addr {
173
175
panic ("not implemented" )
174
176
}
175
177
176
178
// Permissions returns the Permissions object used for this connection.
177
- func (c testSSHContext ) Permissions () * gliderssh.Permissions {
179
+ func (testSSHContext ) Permissions () * gliderssh.Permissions {
178
180
panic ("not implemented" )
179
181
}
180
182
181
183
// SetValue allows you to easily write new values into the underlying context.
182
- func (c testSSHContext ) SetValue (key , value interface {}) {
184
+ func (testSSHContext ) SetValue (_ , _ interface {}) {
183
185
panic ("not implemented" )
184
186
}
0 commit comments