12 "www.bamsoftware.com/git/champa.git/turbotunnel"
15 // TestCloseCancelsPoll tests that calling Close cancels the context passed to
17 func TestCloseCancelsPoll(t
*testing
.T
) {
18 beginCh
:= make(chan struct{})
19 resultCh
:= make(chan error
)
20 // The poll function returns immediately with a nil error when its
21 // context is canceled. It returns after a delay with a non-nil error if
22 // its context is not canceled.
23 var poll PollFunc
= func(ctx context
.Context
, _
[]byte) (io
.ReadCloser
, error
) {
29 case <-time
.After(5 * time
.Second
):
30 resultCh
<- errors
.New("poll was not canceled")
32 return ioutil
.NopCloser(bytes
.NewReader(nil)), nil
34 pconn
:= NewPollingPacketConn(turbotunnel
.DummyAddr
{}, poll
)
35 // Wait until the poll function has been called.
37 // Close the connection.
42 // Observe what happened inside the poll function. Closing the
43 // connection should have canceled the context.