1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // This file implements API tests across platforms and will never have a build
17 // someTimeout is used just to test that net.Conn implementations
18 // don't explode when their SetFooDeadline methods are called.
19 // It isn't actually used for testing timeouts.
20 const someTimeout
= 10 * time
.Second
22 func TestConnAndListener(t
*testing
.T
) {
23 for i
, network
:= range []string{"tcp", "unix", "unixpacket"} {
24 if !testableNetwork(network
) {
25 t
.Logf("skipping %s test", network
)
29 ls
, err
:= newLocalServer(network
)
34 ch
:= make(chan error
, 1)
35 handler
:= func(ls
*localServer
, ln Listener
) { transponder(ln
, ch
) }
36 if err
:= ls
.buildup(handler
); err
!= nil {
39 if ls
.Listener
.Addr().Network() != network
{
40 t
.Fatalf("got %s; want %s", ls
.Listener
.Addr().Network(), network
)
43 c
, err
:= Dial(ls
.Listener
.Addr().Network(), ls
.Listener
.Addr().String())
48 if c
.LocalAddr().Network() != network || c
.RemoteAddr().Network() != network
{
49 t
.Fatalf("got %s->%s; want %s->%s", c
.LocalAddr().Network(), c
.RemoteAddr().Network(), network
, network
)
51 c
.SetDeadline(time
.Now().Add(someTimeout
))
52 c
.SetReadDeadline(time
.Now().Add(someTimeout
))
53 c
.SetWriteDeadline(time
.Now().Add(someTimeout
))
55 if _
, err
:= c
.Write([]byte("CONN AND LISTENER TEST")); err
!= nil {
58 rb
:= make([]byte, 128)
59 if _
, err
:= c
.Read(rb
); err
!= nil {
64 t
.Errorf("#%d: %v", i
, err
)