Welcome to mirror list, hosted at ThFree Co, Russian Federation.

queue_test.go « queueing « internal « workhorse - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f5ed9154f4d614da78e59d9b6791be585108dc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package queueing

import (
	"testing"
	"time"
)

func TestNormalQueueing(t *testing.T) {
	q := newQueue("queue 1", 2, 1, time.Microsecond)
	err1 := q.Acquire()
	if err1 != nil {
		t.Fatal("we should acquire a new slot")
	}

	err2 := q.Acquire()
	if err2 != nil {
		t.Fatal("we should acquire a new slot")
	}

	err3 := q.Acquire()
	if err3 != ErrQueueingTimedout {
		t.Fatal("we should timeout")
	}

	q.Release()

	err4 := q.Acquire()
	if err4 != nil {
		t.Fatal("we should acquire a new slot")
	}
}

func TestQueueLimit(t *testing.T) {
	q := newQueue("queue 2", 1, 0, time.Microsecond)
	err1 := q.Acquire()
	if err1 != nil {
		t.Fatal("we should acquire a new slot")
	}

	err2 := q.Acquire()
	if err2 != ErrTooManyRequests {
		t.Fatal("we should fail because of not enough slots in queue")
	}
}

func TestQueueProcessing(t *testing.T) {
	q := newQueue("queue 3", 1, 1, time.Second)
	err1 := q.Acquire()
	if err1 != nil {
		t.Fatal("we should acquire a new slot")
	}

	go func() {
		time.Sleep(50 * time.Microsecond)
		q.Release()
	}()

	err2 := q.Acquire()
	if err2 != nil {
		t.Fatal("we should acquire slot after the previous one finished")
	}
}