@@ -1970,18 +1970,17 @@ func TestFeatureGateResourceHealthStatus(t *testing.T) {
1970
1970
ckm , err := checkpointmanager .NewCheckpointManager (tmpDir )
1971
1971
require .NoError (t , err , "err should be nil" )
1972
1972
resourceName := "domain1.com/resource1"
1973
- existDevices := map [string ]DeviceInstances {
1974
- resourceName : map [string ]pluginapi.Device {
1975
- "dev1" : {
1976
- ID : "dev1" ,
1977
- Health : pluginapi .Healthy ,
1978
- },
1979
- "dev2" : {
1980
- ID : "dev2" ,
1981
- Health : pluginapi .Unhealthy ,
1982
- },
1983
- },
1973
+ existDevices := map [string ]DeviceInstances {}
1974
+ resourceNameMap := make (map [string ]pluginapi.Device )
1975
+ deviceUpdateNumber , deviceUpdateChanBuffer := 200 , 100
1976
+ for i := 0 ; i < deviceUpdateNumber ; i ++ {
1977
+ resourceNameMap [fmt .Sprintf ("dev%d" , i )] = pluginapi.Device {
1978
+ ID : fmt .Sprintf ("dev%d" , i ),
1979
+ Health : pluginapi .Healthy ,
1980
+ }
1984
1981
}
1982
+ existDevices [resourceName ] = resourceNameMap
1983
+
1985
1984
testManager := & ManagerImpl {
1986
1985
allDevices : ResourceDeviceInstances (existDevices ),
1987
1986
endpoints : make (map [string ]endpointInfo ),
@@ -1990,43 +1989,42 @@ func TestFeatureGateResourceHealthStatus(t *testing.T) {
1990
1989
allocatedDevices : make (map [string ]sets.Set [string ]),
1991
1990
podDevices : newPodDevices (),
1992
1991
checkpointManager : ckm ,
1993
- update : make (chan resourceupdates.Update ),
1992
+ update : make (chan resourceupdates.Update , deviceUpdateChanBuffer ),
1994
1993
}
1995
1994
1996
- podID := "pod1"
1997
- contID := "con1"
1998
- devices := checkpoint.DevicesPerNUMA {0 : []string {"dev1" }, 1 : []string {"dev1" }}
1995
+ for i := 0 ; i < deviceUpdateNumber ; i ++ {
1996
+ podID := fmt .Sprintf ("pod%d" , i )
1997
+ contID := fmt .Sprintf ("con%d" , i )
1998
+ devices := checkpoint.DevicesPerNUMA {0 : []string {fmt .Sprintf ("dev%d" , i )}}
1999
+ testManager .podDevices .insert (podID , contID , resourceName ,
2000
+ devices ,
2001
+ newContainerAllocateResponse (
2002
+ withDevices (map [string ]string {"/dev/r1dev1" : "/dev/r1dev1" , "/dev/r1dev2" : "/dev/r1dev2" }),
2003
+ withMounts (map [string ]string {"/home/r1lib1" : "/usr/r1lib1" }),
2004
+ ),
2005
+ )
2006
+ }
1999
2007
2000
- testManager .podDevices .insert (podID , contID , resourceName ,
2001
- devices ,
2002
- newContainerAllocateResponse (
2003
- withDevices (map [string ]string {"/dev/r1dev1" : "/dev/r1dev1" , "/dev/r1dev2" : "/dev/r1dev2" }),
2004
- withMounts (map [string ]string {"/home/r1lib1" : "/usr/r1lib1" }),
2005
- ),
2006
- )
2007
2008
featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .ResourceHealthStatus , true )
2008
2009
2009
- testManager .genericDeviceUpdateCallback (resourceName , []pluginapi.Device {
2010
- {ID : "dev1" , Health : pluginapi .Healthy },
2011
- {ID : "dev2" , Health : pluginapi .Unhealthy },
2012
- })
2010
+ for i := 0 ; i < deviceUpdateNumber ; i ++ {
2011
+ testManager .genericDeviceUpdateCallback (resourceName , []pluginapi.Device {
2012
+ {ID : "dev1" , Health : pluginapi .Healthy },
2013
+ })
2014
+ }
2013
2015
// update chan no data
2014
2016
assert .Empty (t , testManager .update )
2015
2017
2016
- // update chan receive pod1
2017
- var wg sync.WaitGroup
2018
- go func () {
2019
- defer wg .Done ()
2018
+ // update device status, assume all device unhealthy.
2019
+ for i := 0 ; i < deviceUpdateNumber ; i ++ {
2020
+ testManager .genericDeviceUpdateCallback (resourceName , []pluginapi.Device {
2021
+ {ID : fmt .Sprintf ("dev%d" , i ), Health : pluginapi .Unhealthy },
2022
+ })
2023
+ }
2024
+ for i := 0 ; i < deviceUpdateChanBuffer ; i ++ {
2020
2025
u := <- testManager .update
2021
2026
assert .Equal (t , resourceupdates.Update {
2022
- PodUIDs : []string {"pod1" },
2027
+ PodUIDs : []string {fmt . Sprintf ( "pod%d" , i ) },
2023
2028
}, u )
2024
- }()
2025
- wg .Add (1 )
2026
- testManager .genericDeviceUpdateCallback (resourceName , []pluginapi.Device {
2027
- {ID : "dev1" , Health : pluginapi .Unhealthy },
2028
- {ID : "dev2" , Health : pluginapi .Healthy },
2029
- })
2030
- wg .Wait ()
2031
-
2029
+ }
2032
2030
}
0 commit comments