Skip to content

Commit

Permalink
Fix: killAllConns and improve test versatility + CI
Browse files Browse the repository at this point in the history
  • Loading branch information
yunginnanet committed Aug 29, 2023
1 parent 471f769 commit 8250fbd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions conductor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package prox5

import (
"context"
"errors"
"sync/atomic"
)
Expand Down Expand Up @@ -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())
}
21 changes: 16 additions & 5 deletions prox5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net"
"net/http"
"os"
"strconv"
"sync/atomic"
"testing"
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 8250fbd

Please sign in to comment.