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"
"fmt"
"net"
"os"
"sync"
"testing"
"time"
@ -17,18 +18,24 @@ import (
"github.com/netbirdio/netbird/relay/auth/hmac"
"github.com/netbirdio/netbird/relay/client"
"github.com/netbirdio/netbird/relay/server"
"github.com/netbirdio/netbird/util"
)
var (
av = &auth.AllowAllAuth{}
hmacTokenStore = &hmac.TokenStore{}
pairs = []int{1, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100}
dataSize = 1024 * 1024 * 10
)
func TestRelayDataTransfer(t *testing.T) {
//t.SkipNow() // skip this test on CI because it is a benchmark test
dataSize := 1024 * 1024 * 10
func TestMain(m *testing.M) {
_ = util.InitLog("error", "console")
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)
if err != nil {
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) {
t.Helper()
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) {
var transferDuration []time.Duration
var wg sync.WaitGroup