mirror of https://github.com/gorilla/websocket.git
add: call compress method test
This commit is contained in:
parent
a9475f2ccf
commit
f2a68e2d21
|
@ -79,6 +79,76 @@ func BenchmarkWriteWithCompressionOfContextTakeover(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkCallWriteWithCompressionOfContextTakeover(b *testing.B) {
|
||||||
|
w := ioutil.Discard
|
||||||
|
c := newConn(fakeNetConn{Reader: nil, Writer: w}, false, 1024, 1024)
|
||||||
|
// messages := textMessages(100)
|
||||||
|
c.enableWriteCompression = true
|
||||||
|
c.contextTakeover = true
|
||||||
|
c.newCompressionWriter = compressContextTakeover
|
||||||
|
mw := &messageWriter{
|
||||||
|
c: c,
|
||||||
|
frameType: 2,
|
||||||
|
pos: maxFrameHeaderSize,
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
// c.txDict = &messages[i%len(messages)]
|
||||||
|
c.newCompressionWriter(mw, 2, &[]byte{})
|
||||||
|
}
|
||||||
|
b.ReportAllocs()
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkCallWriteWithCompression(b *testing.B) {
|
||||||
|
w := ioutil.Discard
|
||||||
|
c := newConn(fakeNetConn{Reader: nil, Writer: w}, false, 1024, 1024)
|
||||||
|
// messages := textMessages(100)
|
||||||
|
c.enableWriteCompression = true
|
||||||
|
c.newCompressionWriter = compressNoContextTakeover
|
||||||
|
mw := &messageWriter{
|
||||||
|
c: c,
|
||||||
|
frameType: 2,
|
||||||
|
pos: maxFrameHeaderSize,
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
// c.txDict = &messages[i%len(messages)]
|
||||||
|
c.newCompressionWriter(mw, 2, nil)
|
||||||
|
}
|
||||||
|
b.ReportAllocs()
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkReadWithCompression(b *testing.B) {
|
||||||
|
w := ioutil.Discard
|
||||||
|
c := newConn(fakeNetConn{Reader: nil, Writer: w}, false, 1024, 1024)
|
||||||
|
c.enableWriteCompression = true
|
||||||
|
c.newDecompressionReader = decompressNoContextTakeover
|
||||||
|
messages := textMessages(100)
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
r := bytes.NewReader(messages[i%len(messages)])
|
||||||
|
reader := c.newDecompressionReader(r, nil)
|
||||||
|
ioutil.ReadAll(reader)
|
||||||
|
}
|
||||||
|
b.ReportAllocs()
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkReadWithCompressionOfContextTakeover(b *testing.B) {
|
||||||
|
w := ioutil.Discard
|
||||||
|
c := newConn(fakeNetConn{Reader: nil, Writer: w}, false, 1024, 1024)
|
||||||
|
c.enableWriteCompression = true
|
||||||
|
c.contextTakeover = true
|
||||||
|
c.newDecompressionReader = decompressContextTakeover
|
||||||
|
messages := textMessages(100)
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
r := bytes.NewReader(messages[i%len(messages)])
|
||||||
|
reader := c.newDecompressionReader(r, c.rxDict)
|
||||||
|
ioutil.ReadAll(reader)
|
||||||
|
}
|
||||||
|
b.ReportAllocs()
|
||||||
|
}
|
||||||
|
|
||||||
func TestValidCompressionLevel(t *testing.T) {
|
func TestValidCompressionLevel(t *testing.T) {
|
||||||
c := newConn(fakeNetConn{}, false, 1024, 1024)
|
c := newConn(fakeNetConn{}, false, 1024, 1024)
|
||||||
for _, level := range []int{minCompressionLevel - 1, maxCompressionLevel + 1} {
|
for _, level := range []int{minCompressionLevel - 1, maxCompressionLevel + 1} {
|
||||||
|
|
Loading…
Reference in New Issue