Commit 2190750c authored by Russ Cox's avatar Russ Cox Committed by Brad Fitzpatrick

net: add test for CL 17458

I thought that we avoided creating on-disk Unix sockets,
but I was mistaken. Use one to test CL 17458.

Fixes #11826.

Change-Id: Iaa1fb007b95fa6be48200586522a6d4789ecd346
Reviewed-on: https://go-review.googlesource.com/17725
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 91abab04
......@@ -405,6 +405,42 @@ func TestUnixgramConnLocalAndRemoteNames(t *testing.T) {
}
}
func TestUnixUnlink(t *testing.T) {
if !testableNetwork("unix") {
t.Skip("unix test")
}
name := testUnixAddr()
l, err := Listen("unix", name)
if err != nil {
t.Fatal(err)
}
if _, err := os.Stat(name); err != nil {
t.Fatalf("cannot stat unix socket after ListenUnix: %v", err)
}
f, _ := l.(*UnixListener).File()
l1, err := FileListener(f)
if err != nil {
t.Fatal(err)
}
if _, err := os.Stat(name); err != nil {
t.Fatalf("cannot stat unix socket after FileListener: %v", err)
}
if err := l1.Close(); err != nil {
t.Fatalf("closing file listener: %v", err)
}
if _, err := os.Stat(name); err != nil {
t.Fatalf("cannot stat unix socket after closing FileListener: %v", err)
}
f.Close()
if _, err := os.Stat(name); err != nil {
t.Fatalf("cannot stat unix socket after closing FileListener and fd: %v", err)
}
l.Close()
if _, err := os.Stat(name); err == nil {
t.Fatal("closing unix listener did not remove unix socket")
}
}
// forceGoDNS forces the resolver configuration to use the pure Go resolver
// and returns a fixup function to restore the old settings.
func forceGoDNS() func() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment