tsnet: validate sent data in metrics test

Updates #13420

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2024-11-25 14:14:08 +01:00 committed by Kristoffer Dalby
parent e55899386b
commit 225d8f5a88

View File

@ -894,9 +894,11 @@ func sendData(logf func(format string, args ...any), ctx context.Context, bytesC
for { for {
got := make([]byte, bytesCount) got := make([]byte, bytesCount)
n, err := conn.Read(got) n, err := conn.Read(got)
if n != bytesCount { if err != nil {
logf("read %d bytes, want %d", n, bytesCount) allReceived <- fmt.Errorf("failed reading packet, %s", err)
return
} }
got = got[:n]
select { select {
case <-stopReceive: case <-stopReceive:
@ -904,13 +906,17 @@ func sendData(logf func(format string, args ...any), ctx context.Context, bytesC
default: default:
} }
if err != nil {
allReceived <- fmt.Errorf("failed reading packet, %s", err)
return
}
total += n total += n
logf("received %d/%d bytes, %.2f %%", total, bytesCount, (float64(total) / (float64(bytesCount)) * 100)) logf("received %d/%d bytes, %.2f %%", total, bytesCount, (float64(total) / (float64(bytesCount)) * 100))
// Validate the received bytes to be the same as the sent bytes.
for _, b := range string(got) {
if b != 'A' {
allReceived <- fmt.Errorf("received unexpected byte: %c", b)
return
}
}
if total == bytesCount { if total == bytesCount {
break break
} }