Skip to content

Commit b186ee8

Browse files
authored
test/bufconn: add Listener.DialContext(context.Context) (#4763)
1 parent 7cf9689 commit b186ee8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/bufconn/bufconn.go

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package bufconn
2222

2323
import (
24+
"context"
2425
"fmt"
2526
"io"
2627
"net"
@@ -86,8 +87,17 @@ func (l *Listener) Addr() net.Addr { return addr{} }
8687
// providing it the server half of the connection, and returns the client half
8788
// of the connection.
8889
func (l *Listener) Dial() (net.Conn, error) {
90+
return l.DialContext(context.Background())
91+
}
92+
93+
// DialContext creates an in-memory full-duplex network connection, unblocks Accept by
94+
// providing it the server half of the connection, and returns the client half
95+
// of the connection. If ctx is Done, returns ctx.Err()
96+
func (l *Listener) DialContext(ctx context.Context) (net.Conn, error) {
8997
p1, p2 := newPipe(l.sz), newPipe(l.sz)
9098
select {
99+
case <-ctx.Done():
100+
return nil, ctx.Err()
91101
case <-l.done:
92102
return nil, errClosed
93103
case l.ch <- &conn{p1, p2}:

0 commit comments

Comments
 (0)