@@ -38,9 +38,10 @@ const (
38
38
39
39
var (
40
40
testDeviceHealth = state.DeviceHealth {
41
- PoolName : testPool ,
42
- DeviceName : testDevice ,
43
- Health : state .DeviceHealthStatusHealthy ,
41
+ PoolName : testPool ,
42
+ DeviceName : testDevice ,
43
+ Health : state .DeviceHealthStatusHealthy ,
44
+ HealthCheckTimeout : DefaultHealthTimeout ,
44
45
}
45
46
)
46
47
@@ -206,7 +207,7 @@ func TestGetHealthInfo(t *testing.T) {
206
207
driverState := (* cache .HealthInfo )[testDriver ]
207
208
deviceKey := testPool + "/" + testDevice
208
209
device := driverState .Devices [deviceKey ]
209
- device .LastUpdated = time .Now ().Add ((- healthTimeout ) - time .Second )
210
+ device .LastUpdated = time .Now ().Add ((- DefaultHealthTimeout ) - time .Second )
210
211
driverState .Devices [deviceKey ] = device
211
212
(* cache .HealthInfo )[testDriver ] = driverState
212
213
return nil
@@ -237,7 +238,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
237
238
name : "device exists and is healthy" ,
238
239
initialState : & state.DevicesHealthMap {
239
240
testDriver : {Devices : map [string ]state.DeviceHealth {
240
- testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now ()},
241
+ testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now (), HealthCheckTimeout : DefaultHealthTimeout },
241
242
}},
242
243
},
243
244
driverName : testDriver ,
@@ -249,7 +250,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
249
250
name : "device exists and is unhealthy" ,
250
251
initialState : & state.DevicesHealthMap {
251
252
testDriver : {Devices : map [string ]state.DeviceHealth {
252
- testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusUnhealthy , LastUpdated : time .Now ()},
253
+ testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusUnhealthy , LastUpdated : time .Now (), HealthCheckTimeout : DefaultHealthTimeout },
253
254
}},
254
255
},
255
256
driverName : testDriver ,
@@ -261,7 +262,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
261
262
name : "device exists but timed out" ,
262
263
initialState : & state.DevicesHealthMap {
263
264
testDriver : {Devices : map [string ]state.DeviceHealth {
264
- testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now ().Add ((- 1 * healthTimeout ) - time .Second )},
265
+ testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now ().Add ((- 1 * DefaultHealthTimeout ) - time .Second ), HealthCheckTimeout : DefaultHealthTimeout },
265
266
}},
266
267
},
267
268
driverName : testDriver ,
@@ -273,7 +274,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
273
274
name : "device exists, just within timeout" ,
274
275
initialState : & state.DevicesHealthMap {
275
276
testDriver : {Devices : map [string ]state.DeviceHealth {
276
- testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now ().Add ((- 1 * healthTimeout ) + time .Second )},
277
+ testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now ().Add ((- 1 * DefaultHealthTimeout ) + time .Second ), HealthCheckTimeout : DefaultHealthTimeout },
277
278
}},
278
279
},
279
280
driverName : testDriver ,
@@ -285,7 +286,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
285
286
name : "device does not exist, just outside of timeout" ,
286
287
initialState : & state.DevicesHealthMap {
287
288
testDriver : {Devices : map [string ]state.DeviceHealth {
288
- testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now ().Add ((- 1 * healthTimeout ) - time .Second )},
289
+ testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now ().Add ((- 1 * DefaultHealthTimeout ) - time .Second ), HealthCheckTimeout : DefaultHealthTimeout },
289
290
}},
290
291
},
291
292
driverName : testDriver ,
@@ -297,7 +298,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
297
298
name : "device does not exist" ,
298
299
initialState : & state.DevicesHealthMap {
299
300
testDriver : {Devices : map [string ]state.DeviceHealth {
300
- testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now ()},
301
+ testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now (), HealthCheckTimeout : DefaultHealthTimeout },
301
302
}},
302
303
},
303
304
driverName : testDriver ,
@@ -309,7 +310,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
309
310
name : "driver does not exist" ,
310
311
initialState : & state.DevicesHealthMap {
311
312
testDriver : {Devices : map [string ]state.DeviceHealth {
312
- testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now ()},
313
+ testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now (), HealthCheckTimeout : DefaultHealthTimeout },
313
314
}},
314
315
},
315
316
driverName : "driver2" ,
@@ -321,7 +322,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
321
322
name : "pool does not exist" ,
322
323
initialState : & state.DevicesHealthMap {
323
324
testDriver : {Devices : map [string ]state.DeviceHealth {
324
- testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now ()},
325
+ testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now (), HealthCheckTimeout : DefaultHealthTimeout },
325
326
}},
326
327
},
327
328
driverName : testDriver ,
@@ -333,8 +334,8 @@ func TestGetHealthInfoRobust(t *testing.T) {
333
334
name : "multiple devices" ,
334
335
initialState : & state.DevicesHealthMap {
335
336
testDriver : {Devices : map [string ]state.DeviceHealth {
336
- testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now ()},
337
- testPool + "/device2" : {PoolName : testPool , DeviceName : "device2" , Health : state .DeviceHealthStatusUnhealthy , LastUpdated : time .Now ()},
337
+ testPool + "/" + testDevice : {PoolName : testPool , DeviceName : testDevice , Health : state .DeviceHealthStatusHealthy , LastUpdated : time .Now (), HealthCheckTimeout : DefaultHealthTimeout },
338
+ testPool + "/device2" : {PoolName : testPool , DeviceName : "device2" , Health : state .DeviceHealthStatusUnhealthy , LastUpdated : time .Now (), HealthCheckTimeout : DefaultHealthTimeout },
338
339
}},
339
340
},
340
341
driverName : testDriver ,
@@ -382,7 +383,7 @@ func TestUpdateHealthInfo(t *testing.T) {
382
383
assert .Equal (t , state .DeviceHealthStatusUnhealthy , cache .getHealthInfo (testDriver , testPool , testDevice ))
383
384
384
385
// 4 -- Add second device, omit first
385
- secondDevice := state.DeviceHealth {PoolName : testPool , DeviceName : "device2" , Health : state .DeviceHealthStatusHealthy }
386
+ secondDevice := state.DeviceHealth {PoolName : testPool , DeviceName : "device2" , Health : state .DeviceHealthStatusHealthy , HealthCheckTimeout : DefaultHealthTimeout }
386
387
// When the first device is omitted, it should be marked as "Unknown" after a timeout.
387
388
// For this test, we simulate the timeout by not reporting it.
388
389
firstDeviceAsUnknown := newHealth
@@ -392,7 +393,7 @@ func TestUpdateHealthInfo(t *testing.T) {
392
393
err = cache .withLock (func () error {
393
394
deviceKey := testPool + "/" + testDevice
394
395
device := (* cache .HealthInfo )[testDriver ].Devices [deviceKey ]
395
- device .LastUpdated = time .Now ().Add (- healthTimeout * 2 )
396
+ device .LastUpdated = time .Now ().Add (- DefaultHealthTimeout * 2 )
396
397
(* cache .HealthInfo )[testDriver ].Devices [deviceKey ] = device
397
398
return nil
398
399
})
@@ -411,7 +412,7 @@ func TestUpdateHealthInfo(t *testing.T) {
411
412
assert .Equal (t , state .DeviceHealthStatusUnknown , cache2 .getHealthInfo (testDriver , testPool , testDevice ))
412
413
413
414
// 6 -- Test how updateHealthInfo handles device timeouts
414
- timeoutDevice := state.DeviceHealth {PoolName : testPool , DeviceName : "timeoutDevice" , Health : "Unhealthy" }
415
+ timeoutDevice := state.DeviceHealth {PoolName : testPool , DeviceName : "timeoutDevice" , Health : "Unhealthy" , HealthCheckTimeout : DefaultHealthTimeout }
415
416
_ , err = cache .updateHealthInfo (testDriver , []state.DeviceHealth {timeoutDevice })
416
417
require .NoError (t , err )
417
418
@@ -420,14 +421,14 @@ func TestUpdateHealthInfo(t *testing.T) {
420
421
driverState := (* cache .HealthInfo )[testDriver ]
421
422
deviceKey := testPool + "/timeoutDevice"
422
423
device := driverState .Devices [deviceKey ]
423
- device .LastUpdated = time .Now ().Add ((- healthTimeout ) - time .Second )
424
+ device .LastUpdated = time .Now ().Add ((- DefaultHealthTimeout ) - time .Second )
424
425
driverState .Devices [deviceKey ] = device
425
426
(* cache .HealthInfo )[testDriver ] = driverState
426
427
return nil
427
428
})
428
429
require .NoError (t , err )
429
430
430
- expectedTimeoutDeviceUnknown := state.DeviceHealth {PoolName : testPool , DeviceName : "timeoutDevice" , Health : state .DeviceHealthStatusUnknown }
431
+ expectedTimeoutDeviceUnknown := state.DeviceHealth {PoolName : testPool , DeviceName : "timeoutDevice" , Health : state .DeviceHealthStatusUnknown , HealthCheckTimeout : DefaultHealthTimeout }
431
432
expectedChanged6 := []state.DeviceHealth {expectedTimeoutDeviceUnknown }
432
433
changedDevices , err = cache .updateHealthInfo (testDriver , []state.DeviceHealth {})
433
434
require .NoError (t , err )
0 commit comments