@@ -277,14 +277,17 @@ func TestClientTimeout(t *testing.T) {
277
277
278
278
model .DelayConfig = simulator.DelayConfig {
279
279
MethodDelay : map [string ]int {
280
- "RetrieveProperties" : int (18 * time .Second .Milliseconds ()),
280
+ // This is converted to milliseconds by the model simulator
281
+ "RetrievePropertiesEx" : int (300 ),
281
282
},
282
283
}
283
284
simulatorVM := simulator .Map .Any ("VirtualMachine" ).(* simulator.VirtualMachine )
284
285
285
- _ , err := session .findVMByName (context .TODO (), simulatorVM .Config .Name )
286
- g .Expect (err .Error ()).Should (ContainSubstring ("unable to find template by name" ))
287
- g .Expect (err .Error ()).Should (ContainSubstring ("context deadline exceeded (Client.Timeout exceeded while awaiting headers)" ))
286
+ ctx , cancel := context .WithTimeout (context .TODO (), time .Duration (time .Millisecond * 100 ))
287
+ defer cancel ()
288
+ _ , err := session .findVMByName (ctx , simulatorVM .Config .Name )
289
+ g .Expect (err ).To (MatchError (ContainSubstring ("unable to find template by name" )))
290
+ g .Expect (err ).To (MatchError (ContainSubstring ("context deadline exceeded" )))
288
291
})
289
292
290
293
t .Run ("Globally laggy vcenter" , func (t * testing.T ) {
@@ -296,18 +299,22 @@ func TestClientTimeout(t *testing.T) {
296
299
g .Expect (err ).NotTo (HaveOccurred ())
297
300
model .Service .TLS = new (tls.Config )
298
301
model .DelayConfig = simulator.DelayConfig {
299
- Delay : int (18 * time .Second .Milliseconds ()),
302
+ // This is converted to milliseconds by the model simulator
303
+ Delay : int (300 ),
300
304
}
301
305
302
306
server := model .Service .NewServer ()
303
307
pass , _ := server .URL .User .Password ()
304
308
309
+ ctx , cancel := context .WithTimeout (context .TODO (), time .Duration (time .Millisecond * 100 ))
310
+ defer cancel ()
311
+
305
312
_ , err = GetOrCreate (
306
- context . TODO () ,
313
+ ctx ,
307
314
server .URL .Host , "" ,
308
315
server .URL .User .Username (), pass , true )
309
316
g .Expect (err ).To (HaveOccurred ())
310
- g .Expect (err . Error ()). Should ( ContainSubstring ("error setting up new vSphere SOAP client" ))
311
- g .Expect (err . Error ()). Should ( ContainSubstring ("context deadline exceeded" ))
317
+ g .Expect (err ). To ( MatchError ( ContainSubstring ("error setting up new vSphere SOAP client" ) ))
318
+ g .Expect (err ). To ( MatchError ( ContainSubstring ("context deadline exceeded" ) ))
312
319
})
313
320
}
0 commit comments