summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@tailscale.com>2021-11-10 12:09:54 -0800
committerBrad Fitzpatrick <bradfitz@tailscale.com>2021-11-10 12:09:54 -0800
commitd972099c78dab2327fed94536750e6233084c846 (patch)
tree97fc52761dd3f6d477cb656d2a970f0f10eb115b
parentb56ba20549aedc0e56d09dca2552ca62421b2cbd (diff)
downloadtailscale-bradfitz/1_16_stress_netmap.tar.xz
tailscale-bradfitz/1_16_stress_netmap.zip
wgengine/magicsock: add a stress testbradfitz/1_16_stress_netmap
Updates tailscale/corp#3016 Change-Id: I23708e68ed44d81986d9e2be82029d4555547592 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
-rw-r--r--wgengine/magicsock/magicsock_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/wgengine/magicsock/magicsock_test.go b/wgengine/magicsock/magicsock_test.go
index 0872c9c7c..7b1ac3ff3 100644
--- a/wgengine/magicsock/magicsock_test.go
+++ b/wgengine/magicsock/magicsock_test.go
@@ -12,6 +12,7 @@ import (
"errors"
"fmt"
"io/ioutil"
+ "math/rand"
"net"
"net/http"
"net/http/httptest"
@@ -1639,3 +1640,59 @@ func epStrings(eps []tailcfg.Endpoint) (ret []string) {
}
return
}
+
+func TestStressSetNetworkMap(t *testing.T) {
+ conn := newTestConn(t)
+ t.Cleanup(func() { conn.Close() })
+ var buf tstest.MemLogger
+ conn.logf = buf.Logf
+
+ conn.SetPrivateKey(wgkey.Private{0: 1})
+
+ const num = 5
+ present := make([]bool, num)
+ allPeers := make([]*tailcfg.Node, 0, num)
+ for i := 0; i < num; i++ {
+ present[i] = true
+ allPeers = append(allPeers, &tailcfg.Node{
+ DiscoKey: randDiscoKey(),
+ Key: randNodeKey(),
+ Endpoints: []string{"192.168.1.2:345"},
+ })
+ }
+
+ var peers []*tailcfg.Node
+ for i := 0; i < 1000; i++ {
+ which := rand.Intn(num)
+ action := rand.Intn(3)
+ switch action {
+ case 0:
+ present[which] = !present[which]
+ case 1:
+ allPeers[which].DiscoKey = randDiscoKey()
+ case 2:
+ allPeers[which].Key = randNodeKey()
+ default:
+ panic("unreachable")
+ }
+ peers = peers[:0]
+ for peerIdx, p := range allPeers {
+ if present[peerIdx] {
+ peers = append(peers, p)
+ }
+ }
+ conn.SetNetworkMap(&netmap.NetworkMap{
+ Peers: peers,
+ })
+ }
+}
+
+func randDiscoKey() (k tailcfg.DiscoKey) {
+ crand.Read(k[:])
+ return
+}
+
+func randNodeKey() (k tailcfg.NodeKey) {
+ crand.Read(k[:])
+ return
+}