@@ -53,7 +53,8 @@ func TestWorkspaceAgent(t *testing.T) {
53
53
pty := ptytest .New (t ).Attach (inv )
54
54
55
55
clitest .Start (t , inv )
56
- pty .ExpectMatch ("starting agent" )
56
+ ctx := inv .Context ()
57
+ pty .ExpectMatchContext (ctx , "starting agent" )
57
58
58
59
coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
59
60
@@ -99,8 +100,7 @@ func TestWorkspaceAgent(t *testing.T) {
99
100
//nolint:revive,staticcheck
100
101
context .WithValue (inv .Context (), "azure-client" , metadataClient ),
101
102
)
102
- ctx , cancelFunc := context .WithCancel (context .Background ())
103
- defer cancelFunc ()
103
+ ctx := inv .Context ()
104
104
clitest .Start (t , inv )
105
105
coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
106
106
workspace , err := client .Workspace (ctx , workspace .ID )
@@ -112,7 +112,7 @@ func TestWorkspaceAgent(t *testing.T) {
112
112
dialer , err := client .DialWorkspaceAgent (ctx , resources [0 ].Agents [0 ].ID , nil )
113
113
require .NoError (t , err )
114
114
defer dialer .Close ()
115
- require .True (t , dialer .AwaitReachable (context . Background () ))
115
+ require .True (t , dialer .AwaitReachable (ctx ))
116
116
})
117
117
118
118
t .Run ("AWS" , func (t * testing.T ) {
@@ -153,17 +153,18 @@ func TestWorkspaceAgent(t *testing.T) {
153
153
context .WithValue (inv .Context (), "aws-client" , metadataClient ),
154
154
)
155
155
clitest .Start (t , inv )
156
+ ctx := inv .Context ()
156
157
coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
157
- workspace , err := client .Workspace (inv . Context () , workspace .ID )
158
+ workspace , err := client .Workspace (ctx , workspace .ID )
158
159
require .NoError (t , err )
159
160
resources := workspace .LatestBuild .Resources
160
161
if assert .NotEmpty (t , resources ) && assert .NotEmpty (t , resources [0 ].Agents ) {
161
162
assert .NotEmpty (t , resources [0 ].Agents [0 ].Version )
162
163
}
163
- dialer , err := client .DialWorkspaceAgent (inv . Context () , resources [0 ].Agents [0 ].ID , nil )
164
+ dialer , err := client .DialWorkspaceAgent (ctx , resources [0 ].Agents [0 ].ID , nil )
164
165
require .NoError (t , err )
165
166
defer dialer .Close ()
166
- require .True (t , dialer .AwaitReachable (context . Background () ))
167
+ require .True (t , dialer .AwaitReachable (ctx ))
167
168
})
168
169
169
170
t .Run ("GoogleCloud" , func (t * testing.T ) {
@@ -204,7 +205,7 @@ func TestWorkspaceAgent(t *testing.T) {
204
205
clitest .Start (t ,
205
206
inv .WithContext (
206
207
//nolint:revive,staticcheck
207
- context .WithValue (context . Background (), "gcp-client" , metadataClient ),
208
+ context .WithValue (inv . Context (), "gcp-client" , metadataClient ),
208
209
),
209
210
)
210
211
@@ -220,7 +221,7 @@ func TestWorkspaceAgent(t *testing.T) {
220
221
dialer , err := client .DialWorkspaceAgent (ctx , resources [0 ].Agents [0 ].ID , nil )
221
222
require .NoError (t , err )
222
223
defer dialer .Close ()
223
- require .True (t , dialer .AwaitReachable (context . Background () ))
224
+ require .True (t , dialer .AwaitReachable (ctx ))
224
225
sshClient , err := dialer .SSHClient (ctx )
225
226
require .NoError (t , err )
226
227
defer sshClient .Close ()
@@ -269,7 +270,7 @@ func TestWorkspaceAgent(t *testing.T) {
269
270
pty := ptytest .New (t ).Attach (inv )
270
271
271
272
clitest .Start (t , inv )
272
- pty .ExpectMatch ( "starting agent" )
273
+ pty .ExpectMatchContext ( inv . Context (), "starting agent" )
273
274
274
275
resources := coderdtest .AwaitWorkspaceAgents (t , client , workspace .ID )
275
276
require .Len (t , resources , 1 )
0 commit comments