Skip to content

Commit

Permalink
fix flate write pool size to work with best compression
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Jan 24, 2017
1 parent 2257eda commit eb45753
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compression.go
Expand Up @@ -19,7 +19,7 @@ const (
)

var (
flateWriterPools [maxCompressionLevel - minCompressionLevel]sync.Pool
flateWriterPools [maxCompressionLevel - minCompressionLevel + 1]sync.Pool
flateReaderPool = sync.Pool{New: func() interface{} {
return flate.NewReader(nil)
}}
Expand Down
22 changes: 22 additions & 0 deletions compression_test.go
Expand Up @@ -41,6 +41,28 @@ func textMessages(num int) [][]byte {
return messages
}

func TestCompressNoContextTakeover(t *testing.T) {
for level := minCompressionLevel; level <= maxCompressionLevel; level++ {
message := textMessages(1)[0]
c := fakeNetConn{Reader: nil, Writer: ioutil.Discard}
f := compressNoContextTakeover(c, level)
n, err := f.Write(message)
if err != nil {
t.Errorf("Error writing using compressNoContextTakeover on level %d: %v", level, err)
return
}
if n != len(message) {
t.Errorf("Error writing using compressNoContextTakeover on level %d: not enough bytes written", level)
return
}
err = f.Close()
if err != nil {
t.Errorf("Error closing writer on level %d: %v", level, err)
return
}
}
}

func BenchmarkWriteNoCompression(b *testing.B) {
w := ioutil.Discard
c := newConn(fakeNetConn{Reader: nil, Writer: w}, false, 1024, 1024)
Expand Down

0 comments on commit eb45753

Please sign in to comment.