diff --git a/internal/testutils/channel.go b/internal/testutils/channel.go index 991d05cdd..6c4e20541 100644 --- a/internal/testutils/channel.go +++ b/internal/testutils/channel.go @@ -26,19 +26,21 @@ const DefaultChanBufferSize = 1 // Channel wraps a generic channel and provides a timed receive operation. type Channel struct { - ch chan any + // C is the underlying channel on which values sent using the SendXxx() methods are delivered. + // Tests which cannot use ReceiveXxx() for whatever reasons can use C to read the values. + C chan any } // Send sends value on the underlying channel. func (c *Channel) Send(value any) { - c.ch <- value + c.C <- value } // SendContext sends value on the underlying channel, or returns an error if // the context expires. func (c *Channel) SendContext(ctx context.Context, value any) error { select { - case c.ch <- value: + case c.C <- value: return nil case <-ctx.Done(): return ctx.Err() @@ -49,7 +51,7 @@ func (c *Channel) SendContext(ctx context.Context, value any) error { // if successful or false if the channel was full. func (c *Channel) SendOrFail(value any) bool { select { - case c.ch <- value: + case c.C <- value: return true default: return false @@ -60,7 +62,7 @@ func (c *Channel) SendOrFail(value any) bool { // and false if the channel was empty. func (c *Channel) ReceiveOrFail() (any, bool) { select { - case got := <-c.ch: + case got := <-c.C: return got, true default: return nil, false @@ -73,7 +75,7 @@ func (c *Channel) Receive(ctx context.Context) (any, error) { select { case <-ctx.Done(): return nil, ctx.Err() - case got := <-c.ch: + case got := <-c.C: return got, nil } } @@ -86,9 +88,9 @@ func (c *Channel) Receive(ctx context.Context) (any, error) { func (c *Channel) Replace(value any) { for { select { - case c.ch <- value: + case c.C <- value: return - case <-c.ch: + case <-c.C: } } } @@ -100,5 +102,5 @@ func NewChannel() *Channel { // NewChannelWithSize returns a new Channel with a buffer of bufSize. func NewChannelWithSize(bufSize int) *Channel { - return &Channel{ch: make(chan any, bufSize)} + return &Channel{C: make(chan any, bufSize)} }