addr netip.AddrPort
locPort uint16
- onDial func() // called when making a new connection
+ onDial func() // called when making a new connection
+ onClose func(*fakeNetConn) // called when closing a connection
trackConns bool // set this to record all created conns
conns []*fakeNetConn
locAddr := netip.AddrPortFrom(netip.AddrFrom4([4]byte{127, 0, 0, 1}), li.locPort)
li.locPort++
c0, c1 := fakeNetPipe(li.addr, locAddr)
+ c0.onClose = li.onClose
+ c1.onClose = li.onClose
li.queue = append(li.queue, c0)
if li.trackConns {
li.conns = append(li.conns, c0)
// peer is the other endpoint.
peer *fakeNetConn
- onClose func() // called when closing
+ onClose func(*fakeNetConn) // called when closing
}
// Read reads data from the connection.
// Close closes the connection.
func (c *fakeNetConn) Close() error {
if c.onClose != nil {
- c.onClose()
+ c.onClose(c)
}
// Local half of the conn is now closed.
c.loc.lock()
cst.li.onDial = func() {
<-dialc
}
+ closec := make(chan struct{})
+ cst.li.onClose = func(*fakeNetConn) {
+ <-closec
+ }
ctx, cancel := context.WithCancel(context.Background())
req1c := make(chan error)
go func() {
//
// First: Wait for IdleConnTimeout. The net.Conn.Close blocks.
synctest.Wait()
- closec := make(chan struct{})
- cst.li.conns[0].peer.onClose = func() {
- <-closec
- }
time.Sleep(timeout)
synctest.Wait()
// Make a request, which will use a new connection (since the existing one is closing).