-
Notifications
You must be signed in to change notification settings - Fork 9
/
least_busy_test.go
46 lines (40 loc) · 1.33 KB
/
least_busy_test.go
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
package slb
import (
"container/heap"
"testing"
"github.com/stretchr/testify/require"
)
func TestLeastBusy_Dispatch(t *testing.T) {
testPool := newLeastBusy([]string{})
testPool.nodes = nodes{
{host: "localhost:9000", index: 0, pending: 7},
{host: "localhost:9002", index: 1, pending: 0},
{host: "localhost:9001", index: 2, pending: 2},
{host: "localhost:9003", index: 3, pending: 3},
{host: "localhost:9004", index: 4, pending: 1},
}
heap.Init(&testPool.nodes)
actual := testPool.Dispatch()
expected := node{host: "localhost:9002", index: 1, pending: 1}
require.Equal(t, expected, actual)
}
func TestLeastBusy_complete(t *testing.T) {
testPool := newLeastBusy([]string{})
testPool.nodes = nodes{
{host: "localhost:9000", index: 0, pending: 7},
{host: "localhost:9002", index: 1, pending: 0},
{host: "localhost:9001", index: 2, pending: 2},
{host: "localhost:9003", index: 3, pending: 3},
{host: "localhost:9004", index: 4, pending: 1},
}
heap.Init(&testPool.nodes)
testPool.complete("localhost:9003")
expected := nodes{
{host: "localhost:9002", index: 0, pending: 0},
{host: "localhost:9004", index: 1, pending: 1},
{host: "localhost:9001", index: 2, pending: 2},
{host: "localhost:9003", index: 3, pending: 2},
{host: "localhost:9000", index: 4, pending: 7},
}
require.Equal(t, expected, testPool.nodes)
}