From 45a9278c74e60682f54a1046aeae3d6e973c63cb Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 21 Feb 2017 23:33:59 +0100 Subject: [PATCH] Include channel testing in goroutine fore NotifyUploadProgress test --- patch_test.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/patch_test.go b/patch_test.go index 4848285..3ccb430 100644 --- a/patch_test.go +++ b/patch_test.go @@ -307,17 +307,34 @@ func TestPatch(t *testing.T) { NotifyUploadProgress: true, }) - c := make(chan FileInfo, 10) + c := make(chan FileInfo) handler.UploadProgress = c reader, writer := io.Pipe() + a := assert.New(t) go func() { writer.Write([]byte("first ")) - <-time.After(time.Second) + + info := <-c + a.Equal("yes", info.ID) + a.Equal(int64(100), info.Size) + a.Equal(int64(6), info.Offset) + writer.Write([]byte("second ")) writer.Write([]byte("third")) + + info = <-c + a.Equal("yes", info.ID) + a.Equal(int64(100), info.Size) + a.Equal(int64(18), info.Offset) + writer.Close() + + info = <-c + a.Equal("yes", info.ID) + a.Equal(int64(100), info.Size) + a.Equal(int64(18), info.Offset) }() (&httpTest{ @@ -340,18 +357,6 @@ func TestPatch(t *testing.T) { <-time.After(10 * time.Millisecond) close(handler.UploadProgress) - a := assert.New(t) - - info := <-c - a.Equal("yes", info.ID) - a.Equal(int64(100), info.Size) - a.Equal(int64(6), info.Offset) - - info = <-c - a.Equal("yes", info.ID) - a.Equal(int64(100), info.Size) - a.Equal(int64(18), info.Offset) - _, more := <-c a.False(more) })