Skip to content

Commit 320edbd

Browse files
Fix vsphere session tests
1 parent 0b13f4e commit 320edbd

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

pkg/controller/vsphere/session/session_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,17 @@ func TestClientTimeout(t *testing.T) {
277277

278278
model.DelayConfig = simulator.DelayConfig{
279279
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),
281282
},
282283
}
283284
simulatorVM := simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine)
284285

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")))
288291
})
289292

290293
t.Run("Globally laggy vcenter", func(t *testing.T) {
@@ -296,18 +299,22 @@ func TestClientTimeout(t *testing.T) {
296299
g.Expect(err).NotTo(HaveOccurred())
297300
model.Service.TLS = new(tls.Config)
298301
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),
300304
}
301305

302306
server := model.Service.NewServer()
303307
pass, _ := server.URL.User.Password()
304308

309+
ctx, cancel := context.WithTimeout(context.TODO(), time.Duration(time.Millisecond*100))
310+
defer cancel()
311+
305312
_, err = GetOrCreate(
306-
context.TODO(),
313+
ctx,
307314
server.URL.Host, "",
308315
server.URL.User.Username(), pass, true)
309316
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")))
312319
})
313320
}

0 commit comments

Comments
 (0)