Skip to content

Commit

Permalink
Cap priority value while dynamically increasing priority of goroutine…
Browse files Browse the repository at this point in the history
…s. (#12)

* update priority value only if it's not max

* update priority value in test

* use constants in test
  • Loading branch information
vivek-ng committed Nov 23, 2020
1 parent 974cfcb commit d2ecfbf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions priority/priorityRateLimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ func (p *PriorityLimiter) Wait(priority constants.PriorityValue) {
return
case <-ticker.C:
p.mu.Lock()
currentPriority := w.Priority
p.waitList.Update(w, currentPriority+1)
if w.Priority < int(constants.High) {
currentPriority := w.Priority
p.waitList.Update(w, currentPriority+1)
}
p.mu.Unlock()
}
}
Expand Down
4 changes: 2 additions & 2 deletions priority/priorityRateLimiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func TestDynamicPriority(t *testing.T) {
pVal = nl.waitList.Top()
pValItem = pVal.(queue.Item)
expectedVal2 := pValItem.Priority
assert.GreaterOrEqual(t, expectedVal1, 10)
assert.GreaterOrEqual(t, expectedVal2, 10)
assert.GreaterOrEqual(t, expectedVal1, int(constants.High))
assert.GreaterOrEqual(t, expectedVal2, int(constants.High))
}

func TestPriorityLimiter_Timeout(t *testing.T) {
Expand Down

0 comments on commit d2ecfbf

Please sign in to comment.