@@ -18,7 +18,6 @@ package cache
18
18
19
19
import (
20
20
"context"
21
- "encoding/json"
22
21
"reflect"
23
22
"sort"
24
23
"testing"
@@ -207,57 +206,30 @@ func TestDirtyNodesUnmarkedOnReserve(t *testing.T) {
207
206
}
208
207
}
209
208
210
- func TestGetCachedNRTCopy (t * testing.T ) {
211
- fakeClient , err := tu .NewFakeClient ()
212
- if err != nil {
213
- t .Fatal (err )
214
- }
215
-
216
- fakePodLister := & fakePodLister {}
217
-
218
- nrtCache := mustOverReserve (t , fakeClient , fakePodLister )
209
+ func TestOverreserveGetCachedNRTCopy (t * testing.T ) {
210
+ testNodeName := "worker-node-1"
211
+ nrt := makeTestNRT (testNodeName )
219
212
220
- ctx := context .Background ()
221
- var nrtObj * topologyv1alpha2.NodeResourceTopology
222
- nrtObj , _ = nrtCache .GetCachedNRTCopy (ctx , "node1" , & corev1.Pod {})
223
- if nrtObj != nil {
224
- t .Fatalf ("non-empty object from empty cache" )
225
- }
226
-
227
- nodeTopologies := []* topologyv1alpha2.NodeResourceTopology {
213
+ testCases := []testCaseGetCachedNRTCopy {
228
214
{
229
- ObjectMeta : metav1.ObjectMeta {Name : "node1" },
230
- TopologyPolicies : []string {string (topologyv1alpha2 .SingleNUMANodeContainerLevel )},
231
- Zones : topologyv1alpha2.ZoneList {
232
- {
233
- Name : "node-0" ,
234
- Type : "Node" ,
235
- Resources : topologyv1alpha2.ResourceInfoList {
236
- MakeTopologyResInfo (cpu , "20" , "4" ),
237
- MakeTopologyResInfo (memory , "8Gi" , "8Gi" ),
238
- MakeTopologyResInfo (nicResourceName , "30" , "10" ),
239
- },
240
- },
241
- {
242
- Name : "node-1" ,
243
- Type : "Node" ,
244
- Resources : topologyv1alpha2.ResourceInfoList {
245
- MakeTopologyResInfo (cpu , "30" , "8" ),
246
- MakeTopologyResInfo (memory , "8Gi" , "8Gi" ),
247
- MakeTopologyResInfo (nicResourceName , "30" , "10" ),
248
- },
249
- },
215
+ name : "data present with foreign pods" ,
216
+ nodeTopologies : []* topologyv1alpha2.NodeResourceTopology {
217
+ nrt ,
250
218
},
219
+ nodeName : testNodeName ,
220
+ hasForeignPods : true ,
221
+ expectedNRT : nil ,
222
+ expectedOK : false ,
251
223
},
252
224
}
253
- for _ , obj := range nodeTopologies {
254
- nrtCache .Store ().Update (obj )
255
- }
256
225
257
- nrtObj , _ = nrtCache .GetCachedNRTCopy (ctx , "node1" , & corev1.Pod {})
258
- if ! reflect .DeepEqual (nrtObj , nodeTopologies [0 ]) {
259
- t .Fatalf ("unexpected object from cache\n got: %s\n expected: %s\n " , dumpNRT (nrtObj ), dumpNRT (nodeTopologies [0 ]))
260
- }
226
+ checkGetCachedNRTCopy (
227
+ t ,
228
+ func (client ctrlclient.Client , podLister podlisterv1.PodLister ) (Interface , error ) {
229
+ return NewOverReserve (nil , client , podLister )
230
+ },
231
+ testCases ... ,
232
+ )
261
233
}
262
234
263
235
func TestGetCachedNRTCopyReserve (t * testing.T ) {
@@ -751,51 +723,6 @@ func TestNodeWithForeignPods(t *testing.T) {
751
723
}
752
724
}
753
725
754
- func dumpNRT (nrtObj * topologyv1alpha2.NodeResourceTopology ) string {
755
- nrtJson , err := json .MarshalIndent (nrtObj , "" , " " )
756
- if err != nil {
757
- return "marshallingError"
758
- }
759
- return string (nrtJson )
760
- }
761
-
762
- func MakeTopologyResInfo (name , capacity , available string ) topologyv1alpha2.ResourceInfo {
763
- return topologyv1alpha2.ResourceInfo {
764
- Name : name ,
765
- Capacity : resource .MustParse (capacity ),
766
- Available : resource .MustParse (available ),
767
- }
768
- }
769
-
770
- func makeDefaultTestTopology () []* topologyv1alpha2.NodeResourceTopology {
771
- return []* topologyv1alpha2.NodeResourceTopology {
772
- {
773
- ObjectMeta : metav1.ObjectMeta {Name : "node1" },
774
- TopologyPolicies : []string {string (topologyv1alpha2 .SingleNUMANodeContainerLevel )},
775
- Zones : topologyv1alpha2.ZoneList {
776
- {
777
- Name : "node-0" ,
778
- Type : "Node" ,
779
- Resources : topologyv1alpha2.ResourceInfoList {
780
- MakeTopologyResInfo (cpu , "32" , "30" ),
781
- MakeTopologyResInfo (memory , "64Gi" , "60Gi" ),
782
- MakeTopologyResInfo (nicResourceName , "16" , "16" ),
783
- },
784
- },
785
- {
786
- Name : "node-1" ,
787
- Type : "Node" ,
788
- Resources : topologyv1alpha2.ResourceInfoList {
789
- MakeTopologyResInfo (cpu , "32" , "30" ),
790
- MakeTopologyResInfo (memory , "64Gi" , "60Gi" ),
791
- MakeTopologyResInfo (nicResourceName , "16" , "16" ),
792
- },
793
- },
794
- },
795
- },
796
- }
797
- }
798
-
799
726
func mustOverReserve (t * testing.T , client ctrlclient.Client , podLister podlisterv1.PodLister ) * OverReserve {
800
727
obj , err := NewOverReserve (nil , client , podLister )
801
728
if err != nil {
0 commit comments