mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-21 02:08:40 +02:00
Fix test
This commit is contained in:
parent
fdf9756808
commit
8568fbffdd
@ -23,8 +23,6 @@ type State struct {
|
|||||||
PubKey string
|
PubKey string
|
||||||
FQDN string
|
FQDN string
|
||||||
ConnStatus ConnStatus
|
ConnStatus ConnStatus
|
||||||
connStatusRelay ConnStatus
|
|
||||||
connStatusICE ConnStatus
|
|
||||||
ConnStatusUpdate time.Time
|
ConnStatusUpdate time.Time
|
||||||
Relayed bool
|
Relayed bool
|
||||||
LocalIceCandidateType string
|
LocalIceCandidateType string
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/iface"
|
|
||||||
relayClient "github.com/netbirdio/netbird/relay/client"
|
relayClient "github.com/netbirdio/netbird/relay/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,7 +31,6 @@ type WorkerRelay struct {
|
|||||||
parentCtx context.Context
|
parentCtx context.Context
|
||||||
log *log.Entry
|
log *log.Entry
|
||||||
config ConnConfig
|
config ConnConfig
|
||||||
wgInterface iface.IWGIface
|
|
||||||
relayManager relayClient.ManagerService
|
relayManager relayClient.ManagerService
|
||||||
conn WorkerRelayCallbacks
|
conn WorkerRelayCallbacks
|
||||||
|
|
||||||
@ -120,7 +118,7 @@ func (w *WorkerRelay) wgStateCheck(conn net.Conn) {
|
|||||||
w.conn.OnDisconnected()
|
w.conn.OnDisconnected()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resetTime := (lastHandshake.Add(wgHandshakeOvertime + wgHandshakePeriod)).Sub(time.Now())
|
resetTime := time.Until(lastHandshake.Add(wgHandshakeOvertime + wgHandshakePeriod))
|
||||||
timer.Reset(resetTime)
|
timer.Reset(resetTime)
|
||||||
case <-w.ctx.Done():
|
case <-w.ctx.Done():
|
||||||
return
|
return
|
||||||
|
@ -200,10 +200,13 @@ func transfer(t *testing.T, testData []byte, peerPairs int) {
|
|||||||
|
|
||||||
var transferDuration []time.Duration
|
var transferDuration []time.Duration
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
|
var writeErr error
|
||||||
|
var readErr error
|
||||||
for i := 0; i < len(connsSender); i++ {
|
for i := 0; i < len(connsSender); i++ {
|
||||||
wg.Add(2)
|
wg.Add(2)
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
go func(i int) {
|
go func(i int) {
|
||||||
|
defer wg.Done()
|
||||||
pieceSize := 1024
|
pieceSize := 1024
|
||||||
testDataLen := len(testData)
|
testDataLen := len(testData)
|
||||||
|
|
||||||
@ -212,34 +215,43 @@ func transfer(t *testing.T, testData []byte, peerPairs int) {
|
|||||||
if end > testDataLen {
|
if end > testDataLen {
|
||||||
end = testDataLen
|
end = testDataLen
|
||||||
}
|
}
|
||||||
_, err := connsSender[i].Write(testData[j:end])
|
_, writeErr = connsSender[i].Write(testData[j:end])
|
||||||
if err != nil {
|
if writeErr != nil {
|
||||||
t.Fatalf("failed to write to channel: %s", err)
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wg.Done()
|
|
||||||
}(i)
|
}(i)
|
||||||
|
|
||||||
go func(i int, start time.Time) {
|
go func(i int, start time.Time) {
|
||||||
|
defer wg.Done()
|
||||||
buf := make([]byte, 8192)
|
buf := make([]byte, 8192)
|
||||||
rcv := 0
|
rcv := 0
|
||||||
|
var n int
|
||||||
for receivedSize := 0; receivedSize < len(testData); {
|
for receivedSize := 0; receivedSize < len(testData); {
|
||||||
|
|
||||||
n, err := connsReceiver[i].Read(buf)
|
n, readErr = connsReceiver[i].Read(buf)
|
||||||
if err != nil {
|
if readErr != nil {
|
||||||
t.Fatalf("failed to read from channel: %s", err)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
receivedSize += n
|
receivedSize += n
|
||||||
rcv += n
|
rcv += n
|
||||||
}
|
}
|
||||||
transferDuration = append(transferDuration, time.Since(start))
|
transferDuration = append(transferDuration, time.Since(start))
|
||||||
wg.Done()
|
|
||||||
}(i, start)
|
}(i, start)
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
|
if writeErr != nil {
|
||||||
|
t.Fatalf("failed to write to channel: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if readErr != nil {
|
||||||
|
t.Fatalf("failed to read from channel: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
// calculate the megabytes per second from the average transferDuration against the dataSize
|
// calculate the megabytes per second from the average transferDuration against the dataSize
|
||||||
var totalDuration time.Duration
|
var totalDuration time.Duration
|
||||||
for _, d := range transferDuration {
|
for _, d := range transferDuration {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user