Fix goroutine leak in the nullio reader

This commit is contained in:
Maximilian Paß
2021-12-11 22:04:20 +01:00
parent c565ca217e
commit 9f0b04660f
3 changed files with 30 additions and 8 deletions

View File

@@ -1,8 +1,9 @@
package nullio
import (
"context"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io"
"testing"
"time"
)
@@ -10,12 +11,15 @@ import (
const shortTimeout = 100 * time.Millisecond
func TestReaderDoesNotReturnImmediately(t *testing.T) {
reader := &Reader{}
readingContext, cancel := context.WithCancel(context.Background())
defer cancel()
reader := &Reader{readingContext}
readerReturned := make(chan bool)
go func() {
p := make([]byte, 0, 5)
_, err := reader.Read(p)
require.NoError(t, err)
assert.ErrorIs(t, io.EOF, err)
close(readerReturned)
}()