summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Crawshaw <crawshaw@tailscale.com>2020-03-04 17:37:56 -0500
committerDavid Crawshaw <crawshaw@tailscale.com>2020-03-04 17:37:56 -0500
commitbdc894fc4c3fd4e1ce131a9a0cabd9bb919dae7a (patch)
tree1b58354c1b05c4d1569a653ec5e9b716edfe3118
parent07106e989830ec93f8659aefb1d47f24633c880c (diff)
downloadtailscale-crawshaw/magicsock-infping.tar.xz
tailscale-crawshaw/magicsock-infping.zip
[WIP] magicsock: infinite ping testcrawshaw/magicsock-infping
Run this for ~2 minutes to see the connection fail and not recover.
-rw-r--r--wgengine/magicsock/magicsock.go3
-rw-r--r--wgengine/magicsock/magicsock_test.go67
2 files changed, 70 insertions, 0 deletions
diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go
index 537ba1c13..2b19f979a 100644
--- a/wgengine/magicsock/magicsock.go
+++ b/wgengine/magicsock/magicsock.go
@@ -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 {
diff --git a/wgengine/magicsock/magicsock_test.go b/wgengine/magicsock/magicsock_test.go
index 6d1d2c14e..4e9da483f 100644
--- a/wgengine/magicsock/magicsock_test.go
+++ b/wgengine/magicsock/magicsock_test.go
@@ -13,6 +13,7 @@ import (
"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
}