@@ -26,6 +26,15 @@ import (
26
26
27
27
var loggerPerNode = logf .Log .WithName ("unit-tests" )
28
28
29
+ func GetTargetsWithNodeName (targets []* target.Item ) (targetsWithNodeName []* target.Item ) {
30
+ for _ , item := range targets {
31
+ if item .GetNodeName () != "" {
32
+ targetsWithNodeName = append (targetsWithNodeName , item )
33
+ }
34
+ }
35
+ return targetsWithNodeName
36
+ }
37
+
29
38
// Tests that two targets with the same target url and job name but different label set are both added.
30
39
func TestAllocationPerNode (t * testing.T ) {
31
40
// prepare allocator with initial targets and collectors
@@ -83,13 +92,18 @@ func TestAllocationPerNode(t *testing.T) {
83
92
// only the first two targets should be allocated
84
93
itemsForCollector := s .GetTargetsForCollectorAndJob (actualItem .CollectorName , actualItem .JobName )
85
94
86
- // first two should be assigned one to each collector; if third target, should not be assigned
95
+ // first two should be assigned one to each collector; if third target, it should be assigned
96
+ // according to the fallback strategy which may assign it to the otherwise empty collector or
97
+ // one of the others, depending on the strategy and collector loop order
87
98
if targetHash == thirdTarget .Hash () {
88
- assert .Len (t , itemsForCollector , 0 )
99
+ assert .Empty (t , item .GetNodeName ())
100
+ assert .LessOrEqual (t , len (itemsForCollector ), 2 )
89
101
continue
90
102
}
91
- assert .Len (t , itemsForCollector , 1 )
92
- assert .Equal (t , actualItem , itemsForCollector [0 ])
103
+
104
+ // Only check targets that have been assigned using the per-node (not fallback) strategy here
105
+ assert .Len (t , GetTargetsWithNodeName (itemsForCollector ), 1 )
106
+ assert .Equal (t , actualItem , GetTargetsWithNodeName (itemsForCollector )[0 ])
93
107
}
94
108
}
95
109
0 commit comments