Skip to content

Commit 40f3242

Browse files
committed
apf integration test: ensure no rejection
1 parent e6ee924 commit 40f3242

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

test/integration/apiserver/flowcontrol/concurrency_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
const (
4545
sharedConcurrencyMetricsName = "apiserver_flowcontrol_request_concurrency_limit"
4646
dispatchedRequestCountMetricsName = "apiserver_flowcontrol_dispatched_requests_total"
47+
rejectedRequestCountMetricsName = "apiserver_flowcontrol_rejected_requests_total"
4748
labelPriorityLevel = "priorityLevel"
4849
timeout = time.Second * 10
4950
)
@@ -122,13 +123,20 @@ func TestPriorityLevelIsolation(t *testing.T) {
122123

123124
time.Sleep(time.Second * 10) // running in background for a while
124125

125-
reqCounts, err := getRequestCountOfPriorityLevel(loopbackClient)
126+
allDispatchedReqCounts, rejectedReqCounts, err := getRequestCountOfPriorityLevel(loopbackClient)
126127
if err != nil {
127128
t.Error(err)
128129
}
129130

130-
noxu1RequestCount := reqCounts[priorityLevelNoxu1.Name]
131-
noxu2RequestCount := reqCounts[priorityLevelNoxu2.Name]
131+
noxu1RequestCount := allDispatchedReqCounts[priorityLevelNoxu1.Name]
132+
noxu2RequestCount := allDispatchedReqCounts[priorityLevelNoxu2.Name]
133+
134+
if rejectedReqCounts[priorityLevelNoxu1.Name] > 0 {
135+
t.Errorf(`%v requests from the "elephant" stream were rejected unexpectedly`, rejectedReqCounts[priorityLevelNoxu2.Name])
136+
}
137+
if rejectedReqCounts[priorityLevelNoxu2.Name] > 0 {
138+
t.Errorf(`%v requests from the "mouse" stream were rejected unexpectedly`, rejectedReqCounts[priorityLevelNoxu2.Name])
139+
}
132140

133141
// Theoretically, the actual expected value of request counts upon the two priority-level should be
134142
// the equal. We're deliberately lax to make flakes super rare.
@@ -192,10 +200,10 @@ func getSharedConcurrencyOfPriorityLevel(c clientset.Interface) (map[string]int,
192200
}
193201
}
194202

195-
func getRequestCountOfPriorityLevel(c clientset.Interface) (map[string]int, error) {
203+
func getRequestCountOfPriorityLevel(c clientset.Interface) (map[string]int, map[string]int, error) {
196204
resp, err := getMetrics(c)
197205
if err != nil {
198-
return nil, err
206+
return nil, nil, err
199207
}
200208

201209
dec := expfmt.NewDecoder(strings.NewReader(string(resp)), expfmt.FmtText)
@@ -204,20 +212,23 @@ func getRequestCountOfPriorityLevel(c clientset.Interface) (map[string]int, erro
204212
Opts: &expfmt.DecodeOptions{},
205213
}
206214

207-
reqCounts := make(map[string]int)
215+
allReqCounts := make(map[string]int)
216+
rejectReqCounts := make(map[string]int)
208217
for {
209218
var v model.Vector
210219
if err := decoder.Decode(&v); err != nil {
211220
if err == io.EOF {
212221
// Expected loop termination condition.
213-
return reqCounts, nil
222+
return allReqCounts, rejectReqCounts, nil
214223
}
215-
return nil, fmt.Errorf("failed decoding metrics: %v", err)
224+
return nil, nil, fmt.Errorf("failed decoding metrics: %v", err)
216225
}
217226
for _, metric := range v {
218227
switch name := string(metric.Metric[model.MetricNameLabel]); name {
219228
case dispatchedRequestCountMetricsName:
220-
reqCounts[string(metric.Metric[labelPriorityLevel])] = int(metric.Value)
229+
allReqCounts[string(metric.Metric[labelPriorityLevel])] = int(metric.Value)
230+
case rejectedRequestCountMetricsName:
231+
rejectReqCounts[string(metric.Metric[labelPriorityLevel])] = int(metric.Value)
221232
}
222233
}
223234
}

0 commit comments

Comments
 (0)