Update TestNoRestraint and TestWindup

Make TestNoRestraint verify that fairness is NOT achieved
when there is real competition.

Make TestWindup run two cases, to show that 0.1 is too narrow
a margin and 0.26 is wide enough.

Kubernetes-commit: c4945fdf0c14ba2032a5c8edf192678d9fe00374
This commit is contained in:
Mike Spreitzer 2021-09-17 01:40:16 -04:00 committed by Kubernetes Publisher
parent 72b61b4046
commit c505aa64af
1 changed files with 42 additions and 34 deletions

View File

@ -413,6 +413,7 @@ func TestMain(m *testing.M) {
}
// TestNoRestraint tests whether the no-restraint factory gives every client what it asks for
// even though that is unfair.
func TestNoRestraint(t *testing.T) {
metrics.Register()
now := time.Now()
@ -428,9 +429,9 @@ func TestNoRestraint(t *testing.T) {
newUniformClient(1001001001, 5, 10, time.Second, time.Second),
newUniformClient(2002002002, 2, 10, time.Second, time.Second/2),
},
concurrencyLimit: 10,
concurrencyLimit: 2,
evalDuration: time.Second * 15,
expectedFair: []bool{true},
expectedFair: []bool{false},
expectedFairnessMargin: []float64{0.1},
expectAllRequests: true,
clk: clk,
@ -733,9 +734,9 @@ func TestTooWide(t *testing.T) {
newUniformClient(90090090090090, 15, 21, time.Second, time.Second-1).seats(7),
},
concurrencyLimit: 6,
evalDuration: time.Second * 40,
evalDuration: time.Second * 435,
expectedFair: []bool{true},
expectedFairnessMargin: []float64{0.38},
expectedFairnessMargin: []float64{0.375},
expectAllRequests: true,
evalInqueueMetrics: true,
evalExecutingMetrics: true,
@ -746,38 +747,45 @@ func TestTooWide(t *testing.T) {
func TestWindup(t *testing.T) {
metrics.Register()
now := time.Now()
for _, testcase := range []struct {
margin2 float64
expectFair2 bool
}{{margin2: 0.26, expectFair2: true}, {margin2: 0.1, expectFair2: false}} {
subName := fmt.Sprintf("m2=%v", testcase.margin2)
t.Run(subName, func(t *testing.T) {
now := time.Now()
clk, counter := testeventclock.NewFake(now, 0, nil)
qsf := newTestableQueueSetFactory(clk, countingPromiseFactoryFactory(counter))
qCfg := fq.QueuingConfig{
Name: "TestWindup/" + subName,
DesiredNumQueues: 9,
QueueLengthLimit: 6,
HandSize: 1,
RequestWaitLimit: 10 * time.Minute,
}
qsc, err := qsf.BeginConstruction(qCfg, newObserverPair(clk))
if err != nil {
t.Fatal(err)
}
qs := qsc.Complete(fq.DispatchingConfig{ConcurrencyLimit: 3})
clk, counter := testeventclock.NewFake(now, 0, nil)
qsf := newTestableQueueSetFactory(clk, countingPromiseFactoryFactory(counter))
qCfg := fq.QueuingConfig{
Name: "TestWindup",
DesiredNumQueues: 9,
QueueLengthLimit: 6,
HandSize: 1,
RequestWaitLimit: 10 * time.Minute,
uniformScenario{name: qCfg.Name, qs: qs,
clients: []uniformClient{
newUniformClient(1001001001, 2, 40, time.Second, -1),
newUniformClient(2002002002, 2, 40, time.Second, -1).setSplit(),
},
concurrencyLimit: 3,
evalDuration: time.Second * 40,
expectedFair: []bool{true, testcase.expectFair2},
expectedFairnessMargin: []float64{0.1, testcase.margin2},
expectAllRequests: true,
evalInqueueMetrics: true,
evalExecutingMetrics: true,
clk: clk,
counter: counter,
}.exercise(t)
})
}
qsc, err := qsf.BeginConstruction(qCfg, newObserverPair(clk))
if err != nil {
t.Fatal(err)
}
qs := qsc.Complete(fq.DispatchingConfig{ConcurrencyLimit: 3})
uniformScenario{name: qCfg.Name, qs: qs,
clients: []uniformClient{
newUniformClient(1001001001, 2, 40, time.Second, -1),
newUniformClient(2002002002, 2, 40, time.Second, -1).setSplit(),
},
concurrencyLimit: 3,
evalDuration: time.Second * 40,
expectedFair: []bool{true, true},
expectedFairnessMargin: []float64{0.1, 0.26},
expectAllRequests: true,
evalInqueueMetrics: true,
evalExecutingMetrics: true,
clk: clk,
counter: counter,
}.exercise(t)
}
func TestDifferentFlowsWithoutQueuing(t *testing.T) {