-
Notifications
You must be signed in to change notification settings - Fork 34
/
pool_test.go
64 lines (53 loc) · 1.14 KB
/
pool_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package socks5lb
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func NewProxyPool(t *testing.T) (pool *Pool, err error) {
pool = NewPool()
proxies := []string{
"10.0.20.254:1086",
"192.168.100.254:1086",
"192.168.1.254:1086",
"172.16.1.254:1086",
}
for _, v := range proxies {
err = pool.Add(NewBackend(v, BackendCheckConfig{
CheckURL: "https://www.google.com/robots.txt",
Timeout: 5,
InitialAlive: false,
}))
}
for i := 0; i < 100; i++ {
p := NewPool()
assert.Equal(t, &pool, &p, "proxyPool should be singleton")
}
return
}
func TestPool_HealthCheck(t *testing.T) {
pool, _ := NewProxyPool(t)
assert.NotNil(t, pool)
pool.Check()
for i := 0; i < 100; i++ {
b := pool.Next()
if b != nil {
fmt.Printf("%v | ", pool.current)
fmt.Printf("%v\n", b)
}
}
}
func TestPool_NextCheck(t *testing.T) {
pool, _ := NewProxyPool(t)
assert.NotNil(t, pool)
for i := 0; i < 100; i++ {
err := pool.Add(NewBackend(fmt.Sprintf("%d", i), BackendCheckConfig{
InitialAlive: true,
}))
assert.NoError(t, err)
}
for i := 0; i < 100; i++ {
next := pool.Next()
assert.NotNil(t, next)
}
}