[WIP] magicsock: infinite ping test

Run this for ~2 minutes to see the connection fail and not recover.
This commit is contained in:
David Crawshaw 2020-03-04 17:37:56 -05:00
parent 07106e9898
commit bdc894fc4c
2 changed files with 70 additions and 0 deletions

View File

@ -772,6 +772,9 @@ func (c *Conn) ReceiveIPv4(b []byte) (n int, ep conn.Endpoint, addr *net.UDPAddr
continue
}
// DERP always wins in tests
//time.Sleep(100 * time.Millisecond)
addr := pAddr.(*net.UDPAddr)
addr.IP = addr.IP.To4()
select {

View File

@ -13,6 +13,7 @@
"net"
"net/http"
"net/http/httptest"
"strconv"
"strings"
"sync"
"testing"
@ -519,4 +520,70 @@ func TestTwoDevicePing(t *testing.T) {
t.Error("handshake spray failed to find real route")
}
})
//cfgs[0] = *dev1.Config()
//cfgs[1] = *dev2.Config()
// Start collecting endpoint updates and Reconfig'ing using them.
var cfgsMu sync.Mutex
go func() {
for epstrs := range epCh1 {
eps := append([]wgcfg.Endpoint{derpEp}, makeEps(epstrs)...)
//eps[2].Port = 1111
old := dev2.Config().Peers[0].Endpoints
log.Printf("dev2: replacing %v with %v", old, eps)
cfgsMu.Lock()
cfgs[1].Peers[0].Endpoints = eps
if err := dev2.Reconfig(&cfgs[1]); err != nil {
log.Printf("dev2.Reconfig: %v", err)
}
cfgsMu.Unlock()
}
}()
go func() {
for epstrs := range epCh2 {
eps := append([]wgcfg.Endpoint{derpEp}, makeEps(epstrs)...)
//eps[2].Port = 1111
old := dev1.Config().Peers[0].Endpoints
log.Printf("dev1: replacing %v with %v", old, eps)
cfgsMu.Lock()
cfgs[0].Peers[0].Endpoints = eps
if err := dev1.Reconfig(&cfgs[0]); err != nil {
log.Printf("dev1.Reconfig: %v", err)
}
cfgsMu.Unlock()
}
}()
t.Run("infping", func(t *testing.T) {
//t.Skipf("used for manual testing only")
for i := 0; true; i++ {
t.Logf("long running ping %v", time.Now())
ping1(t)
ping2(t)
time.Sleep(1 * time.Second)
}
})
}
func makeEps(epstrs []string) (eps []wgcfg.Endpoint) {
for _, str := range epstrs {
host, port, err := net.SplitHostPort(str)
if err != nil {
log.Fatalf("bad endpoint %q: %v", str, err)
}
portNum, err := strconv.Atoi(port)
if err != nil {
log.Fatalf("bad endpoint port %q: %v", str, err)
}
eps = append(eps, wgcfg.Endpoint{
Host: host,
Port: uint16(portNum),
})
}
return eps
}