diff options
author | Aliaksandr Valialkin <valyala@gmail.com> | 2016-06-10 15:31:02 +0300 |
---|---|---|
committer | Aliaksandr Valialkin <valyala@gmail.com> | 2016-06-10 15:31:05 +0300 |
commit | ce9d1d2224df0b32cf58b6ce92e0c37b30007932 (patch) | |
tree | a37c8a0e99fbe1357cd6361c0c8536ef23b0997e /stream_test.go | |
parent | typo fix (diff) | |
download | fasthttp-ce9d1d2224df0b32cf58b6ce92e0c37b30007932.tar.gz fasthttp-ce9d1d2224df0b32cf58b6ce92e0c37b30007932.tar.bz2 fasthttp-ce9d1d2224df0b32cf58b6ce92e0c37b30007932.zip |
Use fasthttp.PipeConns instead of io.Pipe in StreamReader
This improves StreamReader performance by more than 2x.
Diffstat (limited to 'stream_test.go')
-rw-r--r-- | stream_test.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/stream_test.go b/stream_test.go index f783369..8dd7b82 100644 --- a/stream_test.go +++ b/stream_test.go @@ -39,18 +39,16 @@ func TestNewStreamReader(t *testing.T) { func TestStreamReaderClose(t *testing.T) { firstLine := "the first line must pass" - ch := make(chan struct{}) + ch := make(chan error, 1) r := NewStreamReader(func(w *bufio.Writer) { fmt.Fprintf(w, "%s", firstLine) if err := w.Flush(); err != nil { - t.Fatalf("unexpected error: %s", err) + ch <- fmt.Errorf("unexpected error on first flush: %s", err) + return } fmt.Fprintf(w, "the second line must fail") - if err := w.Flush(); err == nil { - t.Fatalf("expecting error") - } - close(ch) + ch <- nil }) result := firstLine + "the" @@ -71,7 +69,10 @@ func TestStreamReaderClose(t *testing.T) { } select { - case <-ch: + case err := <-ch: + if err != nil { + t.Fatalf("error returned from stream reader: %s", err) + } case <-time.After(time.Second): t.Fatalf("timeout") } |