Skip to content

Commit 225d8f5

Browse files
committed
tsnet: validate sent data in metrics test
Updates tailscale#13420 Signed-off-by: Kristoffer Dalby <[email protected]>
1 parent e558993 commit 225d8f5

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

tsnet/tsnet_test.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -894,23 +894,29 @@ func sendData(logf func(format string, args ...any), ctx context.Context, bytesC
894894
for {
895895
got := make([]byte, bytesCount)
896896
n, err := conn.Read(got)
897-
if n != bytesCount {
898-
logf("read %d bytes, want %d", n, bytesCount)
897+
if err != nil {
898+
allReceived <- fmt.Errorf("failed reading packet, %s", err)
899+
return
899900
}
901+
got = got[:n]
900902

901903
select {
902904
case <-stopReceive:
903905
return
904906
default:
905907
}
906908

907-
if err != nil {
908-
allReceived <- fmt.Errorf("failed reading packet, %s", err)
909-
return
910-
}
911-
912909
total += n
913910
logf("received %d/%d bytes, %.2f %%", total, bytesCount, (float64(total) / (float64(bytesCount)) * 100))
911+
912+
// Validate the received bytes to be the same as the sent bytes.
913+
for _, b := range string(got) {
914+
if b != 'A' {
915+
allReceived <- fmt.Errorf("received unexpected byte: %c", b)
916+
return
917+
}
918+
}
919+
914920
if total == bytesCount {
915921
break
916922
}

0 commit comments

Comments
 (0)