TestRoundtrip tests two connections, where one is reading and the other is writing
(t *testing.T)
| 58 | |
| 59 | // TestRoundtrip tests two connections, where one is reading and the other is writing |
| 60 | func TestRoundtrip(t *testing.T) { |
| 61 | tests := []struct { |
| 62 | uncompressed []byte |
| 63 | desc string |
| 64 | }{ |
| 65 | {uncompressed: []byte("a"), |
| 66 | desc: "a"}, |
| 67 | {uncompressed: []byte("hello world"), |
| 68 | desc: "hello world"}, |
| 69 | {uncompressed: make([]byte, 100), |
| 70 | desc: "100 bytes"}, |
| 71 | {uncompressed: make([]byte, 32768), |
| 72 | desc: "32768 bytes"}, |
| 73 | {uncompressed: make([]byte, 330000), |
| 74 | desc: "33000 bytes"}, |
| 75 | {uncompressed: makeRandByteSlice(10), |
| 76 | desc: "10 rand bytes", |
| 77 | }, |
| 78 | {uncompressed: makeRandByteSlice(100), |
| 79 | desc: "100 rand bytes", |
| 80 | }, |
| 81 | {uncompressed: makeRandByteSlice(32768), |
| 82 | desc: "32768 rand bytes", |
| 83 | }, |
| 84 | {uncompressed: bytes.Repeat(makeRandByteSlice(100), 10000), |
| 85 | desc: "100 rand * 10000 repeat bytes", |
| 86 | }, |
| 87 | } |
| 88 | |
| 89 | _, cSend := newRWMockConn(0) |
| 90 | cSend.compress = true |
| 91 | cSend.compIO = newCompIO(cSend) |
| 92 | _, cReceive := newRWMockConn(0) |
| 93 | cReceive.compress = true |
| 94 | cReceive.compIO = newCompIO(cReceive) |
| 95 | |
| 96 | for _, test := range tests { |
| 97 | t.Run(test.desc, func(t *testing.T) { |
| 98 | cSend.resetSequence() |
| 99 | cReceive.resetSequence() |
| 100 | |
| 101 | uncompressed := roundtripHelper(t, cSend, cReceive, test.uncompressed) |
| 102 | if len(uncompressed) != len(test.uncompressed) { |
| 103 | t.Errorf("uncompressed size is unexpected. expected %d but got %d", |
| 104 | len(test.uncompressed), len(uncompressed)) |
| 105 | } |
| 106 | if !bytes.Equal(uncompressed, test.uncompressed) { |
| 107 | t.Errorf("roundtrip failed") |
| 108 | } |
| 109 | if cSend.sequence != cReceive.sequence { |
| 110 | t.Errorf("inconsistent sequence number: send=%v recv=%v", |
| 111 | cSend.sequence, cReceive.sequence) |
| 112 | } |
| 113 | if cSend.compressSequence != cReceive.compressSequence { |
| 114 | t.Errorf("inconsistent compress sequence number: send=%v recv=%v", |
| 115 | cSend.compressSequence, cReceive.compressSequence) |
| 116 | } |
| 117 | }) |
nothing calls this directly
no test coverage detected