diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 4c38f3e..551fcc1 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,19 +1,21 @@ name: tests on: push: - branches: [ "main", "development" ] + branches: ["main", "development"] pull_request: - branches: [ "main" ] + branches: ["main"] jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: 1.19 - - name: vet - run: go vet ./... - - name: test - run: go test -v ./... + - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.19 + - name: vet + run: go vet ./... + - name: test + run: go test -race -v -coverprofile=coverage.txt -covermode=atomic ./... + - name: codecov + run: bash <(curl -s https://codecov.io/bash) diff --git a/conductor.go b/conductor.go index 512c58a..d5f1793 100644 --- a/conductor.go +++ b/conductor.go @@ -1,6 +1,7 @@ package prox5 import ( + "context" "errors" "sync/atomic" ) @@ -69,4 +70,6 @@ func (p5 *ProxyEngine) Resume() error { // Note this does not effect the proxy pool, it will continue to operate as normal. func (p5 *ProxyEngine) CloseAllConns() { p5.killConns() + p5.mu.Lock() + p5.ctx, p5.killConns = context.WithCancel(context.Background()) } diff --git a/prox5_test.go b/prox5_test.go index 14cc4df..d48d705 100644 --- a/prox5_test.go +++ b/prox5_test.go @@ -6,6 +6,7 @@ import ( "io" "net" "net/http" + "os" "strconv" "sync/atomic" "testing" @@ -27,7 +28,9 @@ func (rf *randomFail) fail() bool { if rf.failOneOutOf == 0 { return false } - doFail := entropy.OneInA(rf.failOneOutOf) + + doFail := entropy.GetOptimizedRand().Intn(rf.failOneOutOf) == 1 + if !doFail { return false } @@ -88,7 +91,7 @@ func dummySOCKSServer(t *testing.T, port int, rf ...*randomFail) { if failure.fail() { return nil, ErrRandomFail } - time.Sleep(time.Duration(entropy.RNG(300)) * time.Millisecond) + time.Sleep(time.Duration(entropy.GetOptimizedRand().Intn(300)) * time.Millisecond) return net.Dial(network, addr) } @@ -115,11 +118,19 @@ func (tl p5TestLogger) Print(args ...interface{}) { tl.t.Log(args...) } func TestProx5(t *testing.T) { - for i := 0; i < 100; i++ { + numTest := 100 + if envCount := os.Getenv("PROX5_TEST_COUNT"); envCount != "" { + n, e := strconv.Atoi(envCount) + if e != nil { + t.Skip(e.Error()) + } + numTest = n + } + for i := 0; i < numTest; i++ { dummySOCKSServer(t, 5555+i, &randomFail{ t: t, failedCount: int64(0), - failOneOutOf: entropy.RNG(100), + failOneOutOf: entropy.RNG(200), maxFail: 50, }) time.Sleep(time.Millisecond * 5) @@ -140,7 +151,7 @@ func TestProx5(t *testing.T) { defer cancel() load := func() { - if index > 5655 { + if index > 5555+numTest { return } time.Sleep(time.Millisecond * 100)