@@ -38,9 +38,10 @@ const (
3838
3939var (
4040 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 ,
4445 }
4546)
4647
@@ -206,7 +207,7 @@ func TestGetHealthInfo(t *testing.T) {
206207 driverState := (* cache .HealthInfo )[testDriver ]
207208 deviceKey := testPool + "/" + testDevice
208209 device := driverState .Devices [deviceKey ]
209- device .LastUpdated = time .Now ().Add ((- healthTimeout ) - time .Second )
210+ device .LastUpdated = time .Now ().Add ((- DefaultHealthTimeout ) - time .Second )
210211 driverState .Devices [deviceKey ] = device
211212 (* cache .HealthInfo )[testDriver ] = driverState
212213 return nil
@@ -237,7 +238,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
237238 name : "device exists and is healthy" ,
238239 initialState : & state.DevicesHealthMap {
239240 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 },
241242 }},
242243 },
243244 driverName : testDriver ,
@@ -249,7 +250,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
249250 name : "device exists and is unhealthy" ,
250251 initialState : & state.DevicesHealthMap {
251252 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 },
253254 }},
254255 },
255256 driverName : testDriver ,
@@ -261,7 +262,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
261262 name : "device exists but timed out" ,
262263 initialState : & state.DevicesHealthMap {
263264 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 },
265266 }},
266267 },
267268 driverName : testDriver ,
@@ -273,7 +274,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
273274 name : "device exists, just within timeout" ,
274275 initialState : & state.DevicesHealthMap {
275276 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 },
277278 }},
278279 },
279280 driverName : testDriver ,
@@ -285,7 +286,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
285286 name : "device does not exist, just outside of timeout" ,
286287 initialState : & state.DevicesHealthMap {
287288 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 },
289290 }},
290291 },
291292 driverName : testDriver ,
@@ -297,7 +298,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
297298 name : "device does not exist" ,
298299 initialState : & state.DevicesHealthMap {
299300 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 },
301302 }},
302303 },
303304 driverName : testDriver ,
@@ -309,7 +310,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
309310 name : "driver does not exist" ,
310311 initialState : & state.DevicesHealthMap {
311312 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 },
313314 }},
314315 },
315316 driverName : "driver2" ,
@@ -321,7 +322,7 @@ func TestGetHealthInfoRobust(t *testing.T) {
321322 name : "pool does not exist" ,
322323 initialState : & state.DevicesHealthMap {
323324 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 },
325326 }},
326327 },
327328 driverName : testDriver ,
@@ -333,8 +334,8 @@ func TestGetHealthInfoRobust(t *testing.T) {
333334 name : "multiple devices" ,
334335 initialState : & state.DevicesHealthMap {
335336 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 },
338339 }},
339340 },
340341 driverName : testDriver ,
@@ -382,7 +383,7 @@ func TestUpdateHealthInfo(t *testing.T) {
382383 assert .Equal (t , state .DeviceHealthStatusUnhealthy , cache .getHealthInfo (testDriver , testPool , testDevice ))
383384
384385 // 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 }
386387 // When the first device is omitted, it should be marked as "Unknown" after a timeout.
387388 // For this test, we simulate the timeout by not reporting it.
388389 firstDeviceAsUnknown := newHealth
@@ -392,7 +393,7 @@ func TestUpdateHealthInfo(t *testing.T) {
392393 err = cache .withLock (func () error {
393394 deviceKey := testPool + "/" + testDevice
394395 device := (* cache .HealthInfo )[testDriver ].Devices [deviceKey ]
395- device .LastUpdated = time .Now ().Add (- healthTimeout * 2 )
396+ device .LastUpdated = time .Now ().Add (- DefaultHealthTimeout * 2 )
396397 (* cache .HealthInfo )[testDriver ].Devices [deviceKey ] = device
397398 return nil
398399 })
@@ -411,7 +412,7 @@ func TestUpdateHealthInfo(t *testing.T) {
411412 assert .Equal (t , state .DeviceHealthStatusUnknown , cache2 .getHealthInfo (testDriver , testPool , testDevice ))
412413
413414 // 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 }
415416 _ , err = cache .updateHealthInfo (testDriver , []state.DeviceHealth {timeoutDevice })
416417 require .NoError (t , err )
417418
@@ -420,14 +421,14 @@ func TestUpdateHealthInfo(t *testing.T) {
420421 driverState := (* cache .HealthInfo )[testDriver ]
421422 deviceKey := testPool + "/timeoutDevice"
422423 device := driverState .Devices [deviceKey ]
423- device .LastUpdated = time .Now ().Add ((- healthTimeout ) - time .Second )
424+ device .LastUpdated = time .Now ().Add ((- DefaultHealthTimeout ) - time .Second )
424425 driverState .Devices [deviceKey ] = device
425426 (* cache .HealthInfo )[testDriver ] = driverState
426427 return nil
427428 })
428429 require .NoError (t , err )
429430
430- expectedTimeoutDeviceUnknown := state.DeviceHealth {PoolName : testPool , DeviceName : "timeoutDevice" , Health : state .DeviceHealthStatusUnknown }
431+ expectedTimeoutDeviceUnknown := state.DeviceHealth {PoolName : testPool , DeviceName : "timeoutDevice" , Health : state .DeviceHealthStatusUnknown , HealthCheckTimeout : DefaultHealthTimeout }
431432 expectedChanged6 := []state.DeviceHealth {expectedTimeoutDeviceUnknown }
432433 changedDevices , err = cache .updateHealthInfo (testDriver , []state.DeviceHealth {})
433434 require .NoError (t , err )
0 commit comments