MCPcopy
hub / github.com/syncthing/syncthing / TestWriteCompressed

Function TestWriteCompressed

lib/protocol/protocol_test.go:277–310  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

275}
276
277func TestWriteCompressed(t *testing.T) {
278 for _, random := range []bool{false, true} {
279 buf := new(bytes.Buffer)
280 c := &rawConnection{
281 cr: &countingReader{Reader: buf},
282 cw: &countingWriter{Writer: buf},
283 compression: CompressionAlways,
284 }
285
286 msg := (&Response{Data: make([]byte, 10240)}).toWire()
287 if random {
288 // This should make the message incompressible.
289 rand.Read(msg.Data)
290 }
291
292 if err := c.writeMessage(msg); err != nil {
293 t.Fatal(err)
294 }
295 got, err := c.readMessage(make([]byte, 4))
296 if err != nil {
297 t.Fatal(err)
298 }
299 if !bytes.Equal(got.(*bep.Response).Data, msg.Data) {
300 t.Error("received the wrong message")
301 }
302
303 hdr := &bep.Header{Type: typeOf(msg)}
304 size := int64(2 + proto.Size(hdr) + 4 + proto.Size(msg))
305 if c.cr.Tot() > size {
306 t.Errorf("compression enlarged message from %d to %d",
307 size, c.cr.Tot())
308 }
309 }
310}
311
312func TestLZ4Compression(t *testing.T) {
313 for i := 0; i < 10; i++ {

Callers

nothing calls this directly

Calls 10

writeMessageMethod · 0.95
readMessageMethod · 0.95
ReadFunction · 0.92
typeOfFunction · 0.85
FatalMethod · 0.80
ErrorMethod · 0.65
SizeMethod · 0.65
toWireMethod · 0.45
EqualMethod · 0.45
TotMethod · 0.45

Tested by

no test coverage detected