[#1] mclock: Fix time based scheduling
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
e18d1a7c45
commit
54b4bf7cc1
3 changed files with 223 additions and 182 deletions
|
@ -79,14 +79,17 @@ func TestMClockSharesScheduling(t *testing.T) {
|
|||
var _ clock = &noopClock{}
|
||||
|
||||
type noopClock struct {
|
||||
v float64
|
||||
v float64
|
||||
runAtValue *float64
|
||||
}
|
||||
|
||||
func (n *noopClock) now() float64 {
|
||||
return n.v
|
||||
}
|
||||
|
||||
func (n *noopClock) runAt(ts float64, f func()) {}
|
||||
func (n *noopClock) runAt(ts float64, f func()) {
|
||||
n.runAtValue = &ts
|
||||
}
|
||||
|
||||
func (n *noopClock) close() {}
|
||||
|
||||
|
@ -457,3 +460,36 @@ func (q *MClock) waitingCount() int {
|
|||
|
||||
return q.sharesQueue.Len()
|
||||
}
|
||||
|
||||
func TestMClockTimeBasedSchedule(t *testing.T) {
|
||||
t.Parallel()
|
||||
limit := 1.0 // 1 request per second allowed
|
||||
cl := &noopClock{v: float64(1.5)}
|
||||
q, err := NewMClock(100, math.MaxUint64, map[string]TagInfo{
|
||||
"class1": {Shares: 1, Limit: &limit},
|
||||
}, 100)
|
||||
require.NoError(t, err)
|
||||
defer q.Close()
|
||||
q.clock = cl
|
||||
|
||||
running := make(chan struct{})
|
||||
checked := make(chan struct{})
|
||||
eg, ctx := errgroup.WithContext(context.Background())
|
||||
eg.Go(func() error {
|
||||
release, err := q.RequestArrival(ctx, "class1")
|
||||
require.NoError(t, err)
|
||||
defer release()
|
||||
close(running)
|
||||
<-checked
|
||||
return nil
|
||||
})
|
||||
|
||||
<-running
|
||||
// request must be scheduled at 2.0
|
||||
_, _, err = q.pushRequest("class1")
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, cl.runAtValue)
|
||||
require.Equal(t, cl.v+1.0/limit, *cl.runAtValue)
|
||||
close(checked)
|
||||
require.NoError(t, eg.Wait())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue