| 498 | } |
| 499 | |
| 500 | func testConnWriteReadSequentially(t *testing.T, conn *Conn) { |
| 501 | for i := 0; i != 10; i++ { |
| 502 | if _, err := conn.Write([]byte(strconv.Itoa(i))); err != nil { |
| 503 | t.Fatal(err) |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | b := make([]byte, 128) |
| 508 | |
| 509 | for i := 0; i != 10; i++ { |
| 510 | n, err := conn.Read(b) |
| 511 | if err != nil { |
| 512 | t.Error(err) |
| 513 | continue |
| 514 | } |
| 515 | s := string(b[:n]) |
| 516 | if v, err := strconv.Atoi(s); err != nil { |
| 517 | t.Error(err) |
| 518 | } else if v != i { |
| 519 | t.Errorf("bad message read at offset %d: %s", i, s) |
| 520 | } |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | func testConnWriteBatchReadSequentially(t *testing.T, conn *Conn) { |
| 525 | msgs := makeTestSequence(10) |