diff --git a/channel_provider.go b/channel_provider.go index 72f7e2eb1..70068f1da 100644 --- a/channel_provider.go +++ b/channel_provider.go @@ -7,16 +7,20 @@ import ( type channelProvider struct { n *Node eca endpointChannelProvider + + terminate chan struct{} } func newChannelProvider(n *Node, eca endpointChannelProvider) (*channelProvider, error) { return &channelProvider{ - n: n, - eca: eca, + n: n, + eca: eca, + terminate: make(chan struct{}), }, nil } func (cp *channelProvider) close() { + close(cp.terminate) cp.eca.close() } @@ -49,7 +53,8 @@ func (cp *channelProvider) run() { // before creating another channel select { case <-ch.done: - case <-cp.n.terminate: + case <-cp.terminate: + return } } } diff --git a/endpoint_serial_test.go b/endpoint_serial_test.go index aa3fc4716..fd0cdd45a 100644 --- a/endpoint_serial_test.go +++ b/endpoint_serial_test.go @@ -14,15 +14,20 @@ var _ endpointChannelProvider = (*endpointSerial)(nil) func TestEndpointSerial(t *testing.T) { done := make(chan struct{}) - first := false + n := 0 serialOpenFunc = func(name string, baud int) (io.ReadWriteCloser, error) { remote, local := newDummyReadWriterPair() - // skip first call to serialOpenFunc() - if !first { - first = true + n++ + switch n { + case 1: return remote, nil + + case 2: + + default: + t.Errorf("should not happen") } go func() {