Skip to content

Commit 8250fbd

Browse files
committed
Fix: killAllConns and improve test versatility + CI
1 parent 471f769 commit 8250fbd

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

.github/workflows/go.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
name: tests
22
on:
33
push:
4-
branches: [ "main", "development" ]
4+
branches: ["main", "development"]
55
pull_request:
6-
branches: [ "main" ]
6+
branches: ["main"]
77
jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
12-
- name: Set up Go
13-
uses: actions/setup-go@v4
14-
with:
15-
go-version: 1.19
16-
- name: vet
17-
run: go vet ./...
18-
- name: test
19-
run: go test -v ./...
11+
- uses: actions/checkout@v3
12+
- name: Set up Go
13+
uses: actions/setup-go@v4
14+
with:
15+
go-version: 1.19
16+
- name: vet
17+
run: go vet ./...
18+
- name: test
19+
run: go test -race -v -coverprofile=coverage.txt -covermode=atomic ./...
20+
- name: codecov
21+
run: bash <(curl -s https://codecov.io/bash)

conductor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package prox5
22

33
import (
4+
"context"
45
"errors"
56
"sync/atomic"
67
)
@@ -69,4 +70,6 @@ func (p5 *ProxyEngine) Resume() error {
6970
// Note this does not effect the proxy pool, it will continue to operate as normal.
7071
func (p5 *ProxyEngine) CloseAllConns() {
7172
p5.killConns()
73+
p5.mu.Lock()
74+
p5.ctx, p5.killConns = context.WithCancel(context.Background())
7275
}

prox5_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"net"
88
"net/http"
9+
"os"
910
"strconv"
1011
"sync/atomic"
1112
"testing"
@@ -27,7 +28,9 @@ func (rf *randomFail) fail() bool {
2728
if rf.failOneOutOf == 0 {
2829
return false
2930
}
30-
doFail := entropy.OneInA(rf.failOneOutOf)
31+
32+
doFail := entropy.GetOptimizedRand().Intn(rf.failOneOutOf) == 1
33+
3134
if !doFail {
3235
return false
3336
}
@@ -88,7 +91,7 @@ func dummySOCKSServer(t *testing.T, port int, rf ...*randomFail) {
8891
if failure.fail() {
8992
return nil, ErrRandomFail
9093
}
91-
time.Sleep(time.Duration(entropy.RNG(300)) * time.Millisecond)
94+
time.Sleep(time.Duration(entropy.GetOptimizedRand().Intn(300)) * time.Millisecond)
9295
return net.Dial(network, addr)
9396
}
9497

@@ -115,11 +118,19 @@ func (tl p5TestLogger) Print(args ...interface{}) {
115118
tl.t.Log(args...)
116119
}
117120
func TestProx5(t *testing.T) {
118-
for i := 0; i < 100; i++ {
121+
numTest := 100
122+
if envCount := os.Getenv("PROX5_TEST_COUNT"); envCount != "" {
123+
n, e := strconv.Atoi(envCount)
124+
if e != nil {
125+
t.Skip(e.Error())
126+
}
127+
numTest = n
128+
}
129+
for i := 0; i < numTest; i++ {
119130
dummySOCKSServer(t, 5555+i, &randomFail{
120131
t: t,
121132
failedCount: int64(0),
122-
failOneOutOf: entropy.RNG(100),
133+
failOneOutOf: entropy.RNG(200),
123134
maxFail: 50,
124135
})
125136
time.Sleep(time.Millisecond * 5)
@@ -140,7 +151,7 @@ func TestProx5(t *testing.T) {
140151
defer cancel()
141152

142153
load := func() {
143-
if index > 5655 {
154+
if index > 5555+numTest {
144155
return
145156
}
146157
time.Sleep(time.Millisecond * 100)

0 commit comments

Comments
 (0)