Commit 3f90655c authored by Kamil Trzcinski's avatar Kamil Trzcinski

Make apiQueueLimit to be a backlog of requests

parent 945e8b35
......@@ -23,7 +23,7 @@ type Queue struct {
func NewQueue(limit, queueLimit uint) *Queue {
return &Queue{
busyCh: make(chan struct{}, limit),
waitingCh: make(chan struct{}, queueLimit),
waitingCh: make(chan struct{}, limit+queueLimit),
}
}
......
......@@ -6,7 +6,7 @@ import (
)
func TestNormalQueueing(t *testing.T) {
q := NewQueue(2, 3)
q := NewQueue(2, 1)
err1 := q.Acquire(time.Microsecond)
if err1 != nil {
t.Fatal("we should acquire a new slot")
......@@ -31,7 +31,7 @@ func TestNormalQueueing(t *testing.T) {
}
func TestQueueLimit(t *testing.T) {
q := NewQueue(1, 1)
q := NewQueue(1, 0)
err1 := q.Acquire(time.Microsecond)
if err1 != nil {
t.Fatal("we should acquire a new slot")
......@@ -44,7 +44,7 @@ func TestQueueLimit(t *testing.T) {
}
func TestQueueProcessing(t *testing.T) {
q := NewQueue(1, 2)
q := NewQueue(1, 1)
err1 := q.Acquire(time.Microsecond)
if err1 != nil {
t.Fatal("we should acquire a new slot")
......
......@@ -21,7 +21,7 @@ func slowHttpHandler(closeCh chan struct{}) http.Handler {
func TestQueueRequests(t *testing.T) {
w := httptest.NewRecorder()
h := QueueRequests(httpHandler, 1, 2, time.Second)
h := QueueRequests(httpHandler, 1, 1, time.Second)
h.ServeHTTP(w, nil)
if w.Code != 200 {
t.Fatal("QueueRequests should process request")
......@@ -51,7 +51,7 @@ func testSlowRequestProcessing(count, limit, queueLimit uint, queueTimeout time.
}
func TestQueueingTimeout(t *testing.T) {
w := testSlowRequestProcessing(2, 1, 2, time.Microsecond)
w := testSlowRequestProcessing(2, 1, 1, time.Microsecond)
if w.Code != 503 {
t.Fatal("QueueRequests should timeout queued request")
......@@ -59,7 +59,7 @@ func TestQueueingTimeout(t *testing.T) {
}
func TestQueuedRequests(t *testing.T) {
w := testSlowRequestProcessing(3, 1, 2, time.Minute)
w := testSlowRequestProcessing(3, 1, 1, time.Minute)
if w.Code != 429 {
t.Fatal("QueueRequests should return immediately and return too many requests")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment