@ -425,7 +425,7 @@ func TestTwoDevicePing(t *testing.T) {
ping2 ( t )
ping2 ( t )
} )
} )
pingSeq := func ( t * testing . T , count int , totalTime time . Duration ) {
pingSeq := func ( t * testing . T , count int , totalTime time . Duration , strict bool ) {
msg := func ( i int ) [ ] byte {
msg := func ( i int ) [ ] byte {
b := tuntest . Ping ( net . ParseIP ( "1.0.0.2" ) , net . ParseIP ( "1.0.0.1" ) )
b := tuntest . Ping ( net . ParseIP ( "1.0.0.2" ) , net . ParseIP ( "1.0.0.1" ) )
b [ len ( b ) - 1 ] = byte ( i ) // set seq num
b [ len ( b ) - 1 ] = byte ( i ) // set seq num
@ -464,17 +464,21 @@ func TestTwoDevicePing(t *testing.T) {
select {
select {
case msgRecv := <- tun2 . Inbound :
case msgRecv := <- tun2 . Inbound :
if ! bytes . Equal ( b , msgRecv ) {
if ! bytes . Equal ( b , msgRecv ) {
if strict {
t . Errorf ( "return ping %d did not transit correctly: %s" , i , cmp . Diff ( b , msgRecv ) )
t . Errorf ( "return ping %d did not transit correctly: %s" , i , cmp . Diff ( b , msgRecv ) )
}
}
}
case <- time . After ( 3 * time . Second ) :
case <- time . After ( 3 * time . Second ) :
if strict {
t . Fatalf ( "return ping %d did not transit" , i )
t . Fatalf ( "return ping %d did not transit" , i )
}
}
}
}
}
}
}
t . Run ( "ping 1.0.0.1 x50" , func ( t * testing . T ) {
t . Run ( "ping 1.0.0.1 x50" , func ( t * testing . T ) {
pingSeq ( t , 50 , 0 )
pingSeq ( t , 50 , 0 , true )
} )
} )
// Add DERP relay.
// Add DERP relay.
@ -496,7 +500,7 @@ func TestTwoDevicePing(t *testing.T) {
defer func ( ) {
defer func ( ) {
t . Logf ( "DERP vars: %s" , derpServer . ExpVar ( ) . String ( ) )
t . Logf ( "DERP vars: %s" , derpServer . ExpVar ( ) . String ( ) )
} ( )
} ( )
pingSeq ( t , 20 , 0 )
pingSeq ( t , 20 , 0 , true )
} )
} )
// Disable real route.
// Disable real route.
@ -520,7 +524,7 @@ func TestTwoDevicePing(t *testing.T) {
t . Logf ( "cfg1: %v" , uapi2 )
t . Logf ( "cfg1: %v" , uapi2 )
}
}
} ( )
} ( )
pingSeq ( t , 20 , 0 )
pingSeq ( t , 20 , 0 , true )
} )
} )
dev1 . RemoveAllPeers ( )
dev1 . RemoveAllPeers ( )
@ -545,7 +549,7 @@ func TestTwoDevicePing(t *testing.T) {
//
//
// TODO(danderson): finish root-causing and de-flake this test.
// TODO(danderson): finish root-causing and de-flake this test.
t . Run ( "one real route is enough thanks to spray" , func ( t * testing . T ) {
t . Run ( "one real route is enough thanks to spray" , func ( t * testing . T ) {
pingSeq ( t , 50 , 700 * time . Millisecond )
pingSeq ( t , 50 , 700 * time . Millisecond , false )
ep2 := dev2 . Config ( ) . Peers [ 0 ] . Endpoints
ep2 := dev2 . Config ( ) . Peers [ 0 ] . Endpoints
if len ( ep2 ) != 2 {
if len ( ep2 ) != 2 {