Code cleaning

This commit is contained in:
Zoltán Papp 2024-07-26 15:41:40 +02:00
parent d2c9a44953
commit 4b37311e54

View File

@ -5,6 +5,7 @@ import (
"crypto/rand" "crypto/rand"
"fmt" "fmt"
"net" "net"
"os"
"sync" "sync"
"testing" "testing"
"time" "time"
@ -17,18 +18,24 @@ import (
"github.com/netbirdio/netbird/relay/auth/hmac" "github.com/netbirdio/netbird/relay/auth/hmac"
"github.com/netbirdio/netbird/relay/client" "github.com/netbirdio/netbird/relay/client"
"github.com/netbirdio/netbird/relay/server" "github.com/netbirdio/netbird/relay/server"
"github.com/netbirdio/netbird/util"
) )
var ( var (
av = &auth.AllowAllAuth{} av = &auth.AllowAllAuth{}
hmacTokenStore = &hmac.TokenStore{} hmacTokenStore = &hmac.TokenStore{}
pairs = []int{1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100} pairs = []int{1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}
dataSize = 1024 * 1024 * 10
) )
func TestRelayDataTransfer(t *testing.T) { func TestMain(m *testing.M) {
//t.SkipNow() // skip this test on CI because it is a benchmark test _ = util.InitLog("error", "console")
dataSize := 1024 * 1024 * 10 code := m.Run()
os.Exit(code)
}
func TestRelayDataTransfer(t *testing.T) {
t.SkipNow() // skip this test on CI because it is a benchmark test
testData, err := seedRandomData(dataSize) testData, err := seedRandomData(dataSize)
if err != nil { if err != nil {
t.Fatalf("failed to seed random data: %s", err) t.Fatalf("failed to seed random data: %s", err)
@ -41,6 +48,22 @@ func TestRelayDataTransfer(t *testing.T) {
} }
} }
// TestTurnDataTransfer run turn server:
// docker run --rm --name coturn -d --network=host coturn/coturn --user test:test
func TestTurnDataTransfer(t *testing.T) {
t.SkipNow() // skip this test on CI because it is a benchmark test
testData, err := seedRandomData(dataSize)
if err != nil {
t.Fatalf("failed to seed random data: %s", err)
}
for _, peerPairs := range pairs {
t.Run(fmt.Sprintf("peerPairs-%d", peerPairs), func(t *testing.T) {
tunTurnTest(t, testData, peerPairs)
})
}
}
func transfer(t *testing.T, testData []byte, peerPairs int) { func transfer(t *testing.T, testData []byte, peerPairs int) {
t.Helper() t.Helper()
ctx := context.Background() ctx := context.Background()
@ -186,23 +209,6 @@ func transfer(t *testing.T, testData []byte, peerPairs int) {
} }
} }
// TestTurnDataTransfer run turn server:
// docker run --rm --name coturn -d --network=host coturn/coturn --user test:test
func TestTurnDataTransfer(t *testing.T) {
dataSize := 1024 * 1024 * 10
testData, err := seedRandomData(dataSize)
if err != nil {
t.Fatalf("failed to seed random data: %s", err)
}
for _, peerPairs := range pairs {
t.Run(fmt.Sprintf("peerPairs-%d", peerPairs), func(t *testing.T) {
tunTurnTest(t, testData, peerPairs)
})
}
}
func tunTurnTest(t *testing.T, testData []byte, maxPairs int) { func tunTurnTest(t *testing.T, testData []byte, maxPairs int) {
var transferDuration []time.Duration var transferDuration []time.Duration
var wg sync.WaitGroup var wg sync.WaitGroup