Skip to content

Commit

Permalink
add sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlu committed Aug 26, 2024
1 parent 66a752a commit 036bfaa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/network/tracer/tracer_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1270,12 +1270,17 @@ func testUDPPacketSumming(t *testing.T, udpnet, ip string) {
_, err := c.Write(msg[:i+1])
require.NoError(t, err)
}
expectedBytes := 1 + 2 + 3 + 4

buf := make([]byte, 256)
recvBytes := 0
for range msg {
_, _, err := ln.ReadFrom(buf)
n, _, err := ln.ReadFrom(buf)
require.NoError(t, err)
recvBytes += n
}
// sanity check: did userspace get all four expected packets?
require.Equal(t, recvBytes, expectedBytes)

var incoming *network.ConnectionStats
var outgoing *network.ConnectionStats
Expand All @@ -1291,9 +1296,8 @@ func testUDPPacketSumming(t *testing.T, udpnet, ip string) {
return outgoing != nil && incoming != nil
}, 3*time.Second, 100*time.Millisecond, "couldn't find incoming and outgoing connections matching")

totalLen := 1 + 2 + 3 + 4
m := outgoing.Monotonic
require.Equal(t, totalLen, int(m.SentBytes))
require.Equal(t, expectedBytes, int(m.SentBytes))
require.Equal(t, 0, int(m.RecvBytes))
require.Equal(t, int(len(msg)), int(m.SentPackets))
require.Equal(t, 0, int(m.RecvPackets))
Expand All @@ -1302,7 +1306,7 @@ func testUDPPacketSumming(t *testing.T, udpnet, ip string) {
// make sure the inverse values are seen for the other message
m = incoming.Monotonic
require.Equal(t, 0, int(m.SentBytes))
require.Equal(t, totalLen, int(m.RecvBytes))
require.Equal(t, expectedBytes, int(m.RecvBytes))
require.Equal(t, 0, int(m.SentPackets))
require.Equal(t, int(len(msg)), int(m.RecvPackets))
require.True(t, incoming.IntraHost)
Expand Down

0 comments on commit 036bfaa

Please sign in to comment.