mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
review changes
This commit is contained in:
parent
24065cf5be
commit
396e2d4aa3
@ -453,7 +453,7 @@ func (qs *queueSet) selectQueue() *fq.Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// dequeue dequeues a request from the queueSet
|
// dequeue dequeues a request from the queueSet
|
||||||
func (qs *queueSet) dequeue() (*fq.Request, bool) {
|
func (qs *queueSet) dequeueLocked() (*fq.Request, bool) {
|
||||||
queue := qs.selectQueue()
|
queue := qs.selectQueue()
|
||||||
if queue == nil {
|
if queue == nil {
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -491,7 +491,7 @@ func (qs *queueSet) dequeueWithChannelAsMuchAsPossible() {
|
|||||||
// require a message to be sent through the requests channel
|
// require a message to be sent through the requests channel
|
||||||
// this is a required pattern for the QueueSet the queueSet supports
|
// this is a required pattern for the QueueSet the queueSet supports
|
||||||
func (qs *queueSet) dequeueWithChannel() (*fq.Request, bool) {
|
func (qs *queueSet) dequeueWithChannel() (*fq.Request, bool) {
|
||||||
req, ok := qs.dequeue()
|
req, ok := qs.dequeueLocked()
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
@ -32,16 +32,24 @@ import (
|
|||||||
type uniformScenario []uniformClient
|
type uniformScenario []uniformClient
|
||||||
|
|
||||||
type uniformClient struct {
|
type uniformClient struct {
|
||||||
hash uint64
|
hash uint64
|
||||||
nThreads int
|
nThreads int
|
||||||
nCalls int
|
nCalls int
|
||||||
execDuration time.Duration
|
// duration for a simulated synchronous call
|
||||||
|
execDuration time.Duration
|
||||||
|
// duration for simulated "other work"
|
||||||
thinkDuration time.Duration
|
thinkDuration time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// exerciseQueueSetUniformScenario. Simple logic, only works if each
|
// exerciseQueueSetUniformScenario runs a scenario based on the given set of uniform clients.
|
||||||
// client's offered load is at least as large as its fair share of
|
// Each uniform client specifies a number of threads, each of which alternates between thinking
|
||||||
// capacity.
|
// and making a synchronous request through the QueueSet.
|
||||||
|
// This function measures how much concurrency each client got, on average, over
|
||||||
|
// the intial totalDuration and tests to see whether they all got about the same amount.
|
||||||
|
// Each client needs to be demanding enough to use this amount, otherwise the fair result
|
||||||
|
// is not equal amounts and the simple test in this function would not accurately test fairness.
|
||||||
|
// expectPass indicates whether the QueueSet is expected to be fair.
|
||||||
|
// expectedAllRequests indicates whether all requests are expected to get dispatched.
|
||||||
func exerciseQueueSetUniformScenario(t *testing.T, qs fq.QueueSet, sc uniformScenario,
|
func exerciseQueueSetUniformScenario(t *testing.T, qs fq.QueueSet, sc uniformScenario,
|
||||||
totalDuration time.Duration, expectPass bool, expectedAllRequests bool,
|
totalDuration time.Duration, expectPass bool, expectedAllRequests bool,
|
||||||
clk *clock.FakeEventClock, counter counter.GoRoutineCounter) {
|
clk *clock.FakeEventClock, counter counter.GoRoutineCounter) {
|
||||||
@ -112,6 +120,18 @@ func exerciseQueueSetUniformScenario(t *testing.T, qs fq.QueueSet, sc uniformSce
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ClockWait(clk *clock.FakeEventClock, counter counter.GoRoutineCounter, duration time.Duration) {
|
||||||
|
dunch := make(chan struct{})
|
||||||
|
clk.EventAfterDuration(func(time.Time) {
|
||||||
|
counter.Add(1)
|
||||||
|
close(dunch)
|
||||||
|
}, duration)
|
||||||
|
counter.Add(-1)
|
||||||
|
select {
|
||||||
|
case <-dunch:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestNoRestraint should fail because the dummy QueueSet exercises no control
|
// TestNoRestraint should fail because the dummy QueueSet exercises no control
|
||||||
func TestNoRestraint(t *testing.T) {
|
func TestNoRestraint(t *testing.T) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@ -198,15 +218,3 @@ func TestTimeout(t *testing.T) {
|
|||||||
{1001001001, 5, 100, time.Second, time.Second},
|
{1001001001, 5, 100, time.Second, time.Second},
|
||||||
}, time.Second*10, true, false, clk, counter)
|
}, time.Second*10, true, false, clk, counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClockWait(clk *clock.FakeEventClock, counter counter.GoRoutineCounter, duration time.Duration) {
|
|
||||||
dunch := make(chan struct{})
|
|
||||||
clk.EventAfterDuration(func(time.Time) {
|
|
||||||
counter.Add(1)
|
|
||||||
close(dunch)
|
|
||||||
}, duration)
|
|
||||||
counter.Add(-1)
|
|
||||||
select {
|
|
||||||
case <-dunch:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user