Skip to content

Commit a815078

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
net: enable most tests on wasip1 and js
To get them to pass, implement more fake syscalls. To make those syscalls easier to reason about, replace the use of sync.Cond with selectable channels. Fixes #59718. Fixes #50216. Change-Id: I135a6656f5c48f0e5c43dc4d4bcbdb48ee5535d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/526117 Run-TryBot: Bryan Mills <[email protected]> Reviewed-by: Johan Brandhorst-Satzkorn <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Achille Roussel <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent c631297 commit a815078

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1906
-1123
lines changed

src/net/cgo_stub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// (Darwin always provides the cgo functions, in cgo_unix_syscall.go)
1010
// - on wasip1, where cgo is never available
1111

12-
//go:build (netgo && unix) || (unix && !cgo && !darwin) || wasip1
12+
//go:build (netgo && unix) || (unix && !cgo && !darwin) || js || wasip1
1313

1414
package net
1515

src/net/conf.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !js
6-
75
package net
86

97
import (

src/net/conn_test.go

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// This file implements API tests across platforms and will never have a build
6-
// tag.
7-
8-
//go:build !js && !wasip1
5+
// This file implements API tests across platforms and should never have a build
6+
// constraint.
97

108
package net
119

@@ -21,44 +19,46 @@ const someTimeout = 1 * time.Hour
2119

2220
func TestConnAndListener(t *testing.T) {
2321
for i, network := range []string{"tcp", "unix", "unixpacket"} {
24-
if !testableNetwork(network) {
25-
t.Logf("skipping %s test", network)
26-
continue
27-
}
22+
i, network := i, network
23+
t.Run(network, func(t *testing.T) {
24+
if !testableNetwork(network) {
25+
t.Skipf("skipping %s test", network)
26+
}
2827

29-
ls := newLocalServer(t, network)
30-
defer ls.teardown()
31-
ch := make(chan error, 1)
32-
handler := func(ls *localServer, ln Listener) { ls.transponder(ln, ch) }
33-
if err := ls.buildup(handler); err != nil {
34-
t.Fatal(err)
35-
}
36-
if ls.Listener.Addr().Network() != network {
37-
t.Fatalf("got %s; want %s", ls.Listener.Addr().Network(), network)
38-
}
28+
ls := newLocalServer(t, network)
29+
defer ls.teardown()
30+
ch := make(chan error, 1)
31+
handler := func(ls *localServer, ln Listener) { ls.transponder(ln, ch) }
32+
if err := ls.buildup(handler); err != nil {
33+
t.Fatal(err)
34+
}
35+
if ls.Listener.Addr().Network() != network {
36+
t.Fatalf("got %s; want %s", ls.Listener.Addr().Network(), network)
37+
}
3938

40-
c, err := Dial(ls.Listener.Addr().Network(), ls.Listener.Addr().String())
41-
if err != nil {
42-
t.Fatal(err)
43-
}
44-
defer c.Close()
45-
if c.LocalAddr().Network() != network || c.RemoteAddr().Network() != network {
46-
t.Fatalf("got %s->%s; want %s->%s", c.LocalAddr().Network(), c.RemoteAddr().Network(), network, network)
47-
}
48-
c.SetDeadline(time.Now().Add(someTimeout))
49-
c.SetReadDeadline(time.Now().Add(someTimeout))
50-
c.SetWriteDeadline(time.Now().Add(someTimeout))
39+
c, err := Dial(ls.Listener.Addr().Network(), ls.Listener.Addr().String())
40+
if err != nil {
41+
t.Fatal(err)
42+
}
43+
defer c.Close()
44+
if c.LocalAddr().Network() != network || c.RemoteAddr().Network() != network {
45+
t.Fatalf("got %s->%s; want %s->%s", c.LocalAddr().Network(), c.RemoteAddr().Network(), network, network)
46+
}
47+
c.SetDeadline(time.Now().Add(someTimeout))
48+
c.SetReadDeadline(time.Now().Add(someTimeout))
49+
c.SetWriteDeadline(time.Now().Add(someTimeout))
5150

52-
if _, err := c.Write([]byte("CONN AND LISTENER TEST")); err != nil {
53-
t.Fatal(err)
54-
}
55-
rb := make([]byte, 128)
56-
if _, err := c.Read(rb); err != nil {
57-
t.Fatal(err)
58-
}
51+
if _, err := c.Write([]byte("CONN AND LISTENER TEST")); err != nil {
52+
t.Fatal(err)
53+
}
54+
rb := make([]byte, 128)
55+
if _, err := c.Read(rb); err != nil {
56+
t.Fatal(err)
57+
}
5958

60-
for err := range ch {
61-
t.Errorf("#%d: %v", i, err)
62-
}
59+
for err := range ch {
60+
t.Errorf("#%d: %v", i, err)
61+
}
62+
})
6363
}
6464
}

src/net/dial_test.go

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !js && !wasip1
6-
75
package net
86

97
import (
@@ -983,6 +981,8 @@ func TestDialerControl(t *testing.T) {
983981
switch runtime.GOOS {
984982
case "plan9":
985983
t.Skipf("not supported on %s", runtime.GOOS)
984+
case "js", "wasip1":
985+
t.Skipf("skipping: fake net does not support Dialer.Control")
986986
}
987987

988988
t.Run("StreamDial", func(t *testing.T) {
@@ -1026,28 +1026,32 @@ func TestDialerControlContext(t *testing.T) {
10261026
switch runtime.GOOS {
10271027
case "plan9":
10281028
t.Skipf("%s does not have full support of socktest", runtime.GOOS)
1029+
case "js", "wasip1":
1030+
t.Skipf("skipping: fake net does not support Dialer.ControlContext")
10291031
}
10301032
t.Run("StreamDial", func(t *testing.T) {
10311033
for i, network := range []string{"tcp", "tcp4", "tcp6", "unix", "unixpacket"} {
1032-
if !testableNetwork(network) {
1033-
continue
1034-
}
1035-
ln := newLocalListener(t, network)
1036-
defer ln.Close()
1037-
var id int
1038-
d := Dialer{ControlContext: func(ctx context.Context, network string, address string, c syscall.RawConn) error {
1039-
id = ctx.Value("id").(int)
1040-
return controlOnConnSetup(network, address, c)
1041-
}}
1042-
c, err := d.DialContext(context.WithValue(context.Background(), "id", i+1), network, ln.Addr().String())
1043-
if err != nil {
1044-
t.Error(err)
1045-
continue
1046-
}
1047-
if id != i+1 {
1048-
t.Errorf("got id %d, want %d", id, i+1)
1049-
}
1050-
c.Close()
1034+
t.Run(network, func(t *testing.T) {
1035+
if !testableNetwork(network) {
1036+
t.Skipf("skipping: %s not available", network)
1037+
}
1038+
1039+
ln := newLocalListener(t, network)
1040+
defer ln.Close()
1041+
var id int
1042+
d := Dialer{ControlContext: func(ctx context.Context, network string, address string, c syscall.RawConn) error {
1043+
id = ctx.Value("id").(int)
1044+
return controlOnConnSetup(network, address, c)
1045+
}}
1046+
c, err := d.DialContext(context.WithValue(context.Background(), "id", i+1), network, ln.Addr().String())
1047+
if err != nil {
1048+
t.Fatal(err)
1049+
}
1050+
if id != i+1 {
1051+
t.Errorf("got id %d, want %d", id, i+1)
1052+
}
1053+
c.Close()
1054+
})
10511055
}
10521056
})
10531057
}
@@ -1059,7 +1063,8 @@ func mustHaveExternalNetwork(t *testing.T) {
10591063
t.Helper()
10601064
definitelyHasLongtestBuilder := runtime.GOOS == "linux"
10611065
mobile := runtime.GOOS == "android" || runtime.GOOS == "ios"
1062-
if testenv.Builder() != "" && !definitelyHasLongtestBuilder && !mobile {
1066+
fake := runtime.GOOS == "js" || runtime.GOOS == "wasip1"
1067+
if testenv.Builder() != "" && !definitelyHasLongtestBuilder && !mobile && !fake {
10631068
// On a non-Linux, non-mobile builder (e.g., freebsd-amd64-13_0).
10641069
//
10651070
// Don't skip testing because otherwise the test may never run on

src/net/dnsclient_unix.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !js
6-
75
// DNS client: see RFC 1035.
86
// Has to be linked into package net for Dial.
97

src/net/dnsconfig_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !js && !windows
5+
//go:build !windows
66

77
// Read system DNS config from /etc/resolv.conf
88

src/net/dnsname_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !js && !wasip1
6-
75
package net
86

97
import (

src/net/error_posix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build unix || (js && wasm) || wasip1 || windows
5+
//go:build unix || js || wasip1 || windows
66

77
package net
88

0 commit comments

Comments
 (0)