(t *testing.T)
| 479 | } |
| 480 | |
| 481 | func TestOutOfOrderWithEOF(t *testing.T) { |
| 482 | transport := newFakeTransport() |
| 483 | reader := NewReader("test-eof", 1024, transport) |
| 484 | |
| 485 | packet0 := wshrpc.CommandStreamData{ |
| 486 | Id: "test-eof", |
| 487 | Seq: 0, |
| 488 | Data64: base64.StdEncoding.EncodeToString([]byte("first")), |
| 489 | } |
| 490 | packet11 := wshrpc.CommandStreamData{ |
| 491 | Id: "test-eof", |
| 492 | Seq: 11, |
| 493 | Data64: base64.StdEncoding.EncodeToString([]byte("third")), |
| 494 | Eof: true, |
| 495 | } |
| 496 | packet5 := wshrpc.CommandStreamData{ |
| 497 | Id: "test-eof", |
| 498 | Seq: 5, |
| 499 | Data64: base64.StdEncoding.EncodeToString([]byte("second")), |
| 500 | } |
| 501 | |
| 502 | reader.RecvData(packet0) |
| 503 | reader.RecvData(packet11) // OOO with EOF |
| 504 | reader.RecvData(packet5) // Fill the gap |
| 505 | |
| 506 | // Read all data |
| 507 | buf := make([]byte, 20) |
| 508 | n, err := reader.Read(buf) |
| 509 | if err != nil { |
| 510 | t.Fatalf("Read failed: %v", err) |
| 511 | } |
| 512 | |
| 513 | expected := "firstsecondthird" |
| 514 | if string(buf[:n]) != expected { |
| 515 | t.Fatalf("Expected %q, got %q", expected, string(buf[:n])) |
| 516 | } |
| 517 | |
| 518 | // Should get EOF now |
| 519 | _, err = reader.Read(buf) |
| 520 | if err != io.EOF { |
| 521 | t.Fatalf("Expected EOF, got %v", err) |
| 522 | } |
| 523 | } |
nothing calls this directly
no test coverage detected