50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
proxyprovider "douyu_go/internal/proxy"
|
|
"douyu_go/internal/types"
|
|
)
|
|
|
|
func TestProxyDrillPlanAndTargets(t *testing.T) {
|
|
if got := proxyDrillStandbyCount(6, 25); got != 2 {
|
|
t.Fatalf("proxyDrillStandbyCount(6, 25)=%d, want 2", got)
|
|
}
|
|
plan := proxyDrillPlan{accounts: 30, groupSize: 5, active: 6, standby: 2}
|
|
endpoints := make([]proxyprovider.Endpoint, 8)
|
|
targets := buildProxyDrillTargets(plan, endpoints)
|
|
if len(targets) != 8 {
|
|
t.Fatalf("targets=%d, want 8", len(targets))
|
|
}
|
|
totalRequests := 0
|
|
for _, target := range targets {
|
|
totalRequests += target.requests
|
|
}
|
|
if totalRequests != 40 {
|
|
t.Fatalf("totalRequests=%d, want 40 virtual requests", totalRequests)
|
|
}
|
|
}
|
|
|
|
func TestExtractProxyDrillPoolDeduplicates(t *testing.T) {
|
|
apiServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
for i := 0; i < 8; i++ {
|
|
fmt.Fprintf(w, "http://127.0.0.1:%d\n", 20000+i)
|
|
}
|
|
}))
|
|
defer apiServer.Close()
|
|
|
|
app := &App{}
|
|
cfg := types.Config{ProxyAPI: apiServer.URL}
|
|
endpoints, err := app.extractProxyDrillPool(cfg, 8)
|
|
if err != nil {
|
|
t.Fatalf("extractProxyDrillPool() error = %v", err)
|
|
}
|
|
if len(endpoints) != 8 {
|
|
t.Fatalf("endpoints=%d, want 8", len(endpoints))
|
|
}
|
|
}
|