summaryrefslogtreecommitdiff
path: root/src/net/interface_unix_test.go
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@google.com>2018-11-02 11:23:54 +0100
committerMikio Hara <mikioh.public.networking@gmail.com>2018-11-06 00:05:32 +0000
commit9fc22d29092933460fe00bdaccea179f29e9960d (patch)
tree74b30bd25c397797fd3d4baa82aecf0ef89cf7f2 /src/net/interface_unix_test.go
parent5848b6c9b854546473814c8752ee117a71bb8b54 (diff)
downloadgo-git-9fc22d29092933460fe00bdaccea179f29e9960d.tar.gz
net: update zoneCache on cache misses to cover appearing interfaces
performance differences are in measurement noise as per benchcmp: benchmark old ns/op new ns/op delta BenchmarkUDP6LinkLocalUnicast-12 5012 5009 -0.06% Fixes #28535 Change-Id: Id022e2ed089ce8388a2398e755848ec94e77e653 Reviewed-on: https://go-review.googlesource.com/c/146941 Run-TryBot: Mikio Hara <mikioh.public.networking@gmail.com> Reviewed-by: Mikio Hara <mikioh.public.networking@gmail.com>
Diffstat (limited to 'src/net/interface_unix_test.go')
-rw-r--r--src/net/interface_unix_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/net/interface_unix_test.go b/src/net/interface_unix_test.go
index c3d981dc5c..20e75cd036 100644
--- a/src/net/interface_unix_test.go
+++ b/src/net/interface_unix_test.go
@@ -176,3 +176,37 @@ func TestInterfaceArrivalAndDeparture(t *testing.T) {
}
}
}
+
+func TestInterfaceArrivalAndDepartureZoneCache(t *testing.T) {
+ if testing.Short() {
+ t.Skip("avoid external network")
+ }
+ if os.Getuid() != 0 {
+ t.Skip("must be root")
+ }
+
+ // Ensure zoneCache is filled:
+ _, _ = Listen("tcp", "[fe80::1%nonexistant]:0")
+
+ ti := &testInterface{local: "fe80::1"}
+ if err := ti.setLinkLocal(0); err != nil {
+ t.Skipf("test requires external command: %v", err)
+ }
+ if err := ti.setup(); err != nil {
+ t.Fatal(err)
+ }
+ defer ti.teardown()
+
+ time.Sleep(3 * time.Millisecond)
+
+ // If Listen fails (on Linux with “bind: invalid argument”), zoneCache was
+ // not updated when encountering a nonexistant interface:
+ ln, err := Listen("tcp", "[fe80::1%"+ti.name+"]:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ ln.Close()
+ if err := ti.teardown(); err != nil {
+ t.Fatal(err)
+ }
+}