(t *testing.T, rp string)
| 287 | } |
| 288 | |
| 289 | func testWriteLargeData(t *testing.T, rp string) { |
| 290 | // Test sending and receiving messages larger than the maximum write |
| 291 | // buffer size. |
| 292 | clientConn, serverConn := newConnPair(rp, nil, nil) |
| 293 | // Message size is intentionally chosen to not be multiple of |
| 294 | // payloadLengthLimit. |
| 295 | msgSize := altsWriteBufferMaxSize + (100 * 1024) |
| 296 | clientMsg := make([]byte, msgSize) |
| 297 | for i := 0; i < msgSize; i++ { |
| 298 | clientMsg[i] = 0xAA |
| 299 | } |
| 300 | if n, err := clientConn.Write(clientMsg); n != len(clientMsg) || err != nil { |
| 301 | t.Fatalf("Client Write() = %v, %v; want %v, <nil>", n, err, len(clientMsg)) |
| 302 | } |
| 303 | // We need to keep reading until the entire message is received. The |
| 304 | // reason we set all bytes of the message to a value other than zero is |
| 305 | // to avoid ambiguous zero-init value of rcvClientMsg buffer and the |
| 306 | // actual received data. |
| 307 | rcvClientMsg := make([]byte, 0, msgSize) |
| 308 | numberOfExpectedFrames := int(math.Ceil(float64(msgSize) / float64(serverConn.payloadLengthLimit))) |
| 309 | for i := 0; i < numberOfExpectedFrames; i++ { |
| 310 | expectedRcvSize := serverConn.payloadLengthLimit |
| 311 | if i == numberOfExpectedFrames-1 { |
| 312 | // Last frame might be smaller. |
| 313 | expectedRcvSize = msgSize % serverConn.payloadLengthLimit |
| 314 | } |
| 315 | tmpBuf := make([]byte, expectedRcvSize) |
| 316 | if n, err := serverConn.Read(tmpBuf); n != len(tmpBuf) || err != nil { |
| 317 | t.Fatalf("Server Read() = %v, %v; want %v, <nil>", n, err, len(tmpBuf)) |
| 318 | } |
| 319 | rcvClientMsg = append(rcvClientMsg, tmpBuf...) |
| 320 | } |
| 321 | if !reflect.DeepEqual(clientMsg, rcvClientMsg) { |
| 322 | t.Fatalf("Client Write()/Server Read() = %v, want %v", rcvClientMsg, clientMsg) |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | func (s) TestWriteLargeData(t *testing.T) { |
| 327 | for _, rp := range recordProtocols { |
no test coverage detected