magicsock: test sequence of pings

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
David Crawshaw 2020-03-03 11:42:31 -05:00 committed by David Crawshaw
parent 9f584414d9
commit caec2c7e8b

View File

@ -353,4 +353,31 @@ func TestTwoDevicePing(t *testing.T) {
ping1(t)
ping2(t)
})
t.Run("ping 1.0.0.1 x50", func(t *testing.T) {
const count = 50
msg := func(i int) []byte {
b := tuntest.Ping(net.ParseIP("1.0.0.2"), net.ParseIP("1.0.0.1"))
b[len(b)-1] = byte(i) // set seq num
return b
}
for i := 0; i < count; i++ {
b := msg(i)
tun1.Outbound <- b
}
for i := 0; i < count; i++ {
b := msg(i)
select {
case msgRecv := <-tun2.Inbound:
if !bytes.Equal(b, msgRecv) {
t.Errorf("return ping %d did not transit correctly", i)
}
case <-time.After(1 * time.Second):
t.Fatalf("return ping %d did not transit", i)
}
}
})
}