Skip to content

Commit

Permalink
Testing: Make integration test more realistic
Browse files Browse the repository at this point in the history
  • Loading branch information
yunginnanet committed Aug 7, 2023
1 parent bbbc9b7 commit 05b9e36
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func (p5 *ProxyEngine) msgBadProxRate(sock *Proxy) {
buf.MustWriteString("badProx ratelimited: ")
buf.MustWriteString(sockString)
p5.dbgPrint(buf)
p5.lastBadProxAnnnounced.Store(sock.Endpoint)
}

// ------------
Expand Down
22 changes: 14 additions & 8 deletions prox5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func newDummyHTTPSServer(t *testing.T, port int) {
}
go func() {
if err = http.Serve(dtcp, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(time.Duration(entropy.RNG(500)) * time.Millisecond)
time.Sleep(time.Duration(entropy.RNG(300)) * time.Millisecond)
if _, err = w.Write(timeNowJSON()); err != nil {
t.Error("[FAIL] http server failed to write JSON: " + err.Error())
}
Expand Down Expand Up @@ -88,7 +88,7 @@ func dummySOCKSServer(t *testing.T, port int, rf ...*randomFail) {
if failure.fail() {
return nil, ErrRandomFail
}
time.Sleep(time.Duration(entropy.RNG(250)) * time.Millisecond)
time.Sleep(time.Duration(entropy.RNG(300)) * time.Millisecond)
return net.Dial(network, addr)
}

Expand Down Expand Up @@ -128,9 +128,10 @@ func TestProx5(t *testing.T) {
time.Sleep(time.Millisecond * 350)
p5 := NewProxyEngine()
p5.SetAndEnableDebugLogger(p5TestLogger{t: t})
p5.SetMaxWorkers(1)
p5.SetMaxWorkers(10)
p5.EnableAutoScaler()
p5.SetAutoScalerThreshold(1)
p5.SetAutoScalerThreshold(10)
p5.SetAutoScalerMaxScale(100)
// p5.DisableRecycling()
p5.SetRemoveAfter(2)
var index = 5555
Expand Down Expand Up @@ -172,12 +173,13 @@ func TestProx5(t *testing.T) {
}

ticker := time.NewTicker(time.Millisecond * 100)
loadTicker := time.NewTicker(time.Millisecond * 5)

if err := p5.Start(); err != nil {
t.Fatal(err)
}

wait := 0

testLoop:
for {
select {
Expand All @@ -189,9 +191,13 @@ testLoop:
t.Logf("total successful requests: %d", successCountFinal)
break testLoop
case <-ticker.C:
go makeReq()
case <-loadTicker.C:
go load()
// pre-warm
wait++
if wait >= 50 {
go makeReq()
}
default:
load()
}
}
cancel()
Expand Down
2 changes: 1 addition & 1 deletion proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var defaultUseProxyRatelimiter = rl.Policy{

var defaultBadProxyRateLimiter = rl.Policy{
Window: 55,
Burst: 5,
Burst: 10,
}

const (
Expand Down

0 comments on commit 05b9e36

Please sign in to comment.