(t *testing.T)
| 379 | } |
| 380 | |
| 381 | func TestOutOfOrderWithGaps(t *testing.T) { |
| 382 | transport := newFakeTransport() |
| 383 | reader := NewReader("test-gaps", 1024, transport) |
| 384 | |
| 385 | packet0 := wshrpc.CommandStreamData{ |
| 386 | Id: "test-gaps", |
| 387 | Seq: 0, |
| 388 | Data64: base64.StdEncoding.EncodeToString([]byte("aaaaa")), |
| 389 | } |
| 390 | packet20 := wshrpc.CommandStreamData{ |
| 391 | Id: "test-gaps", |
| 392 | Seq: 20, |
| 393 | Data64: base64.StdEncoding.EncodeToString([]byte("eeeee")), |
| 394 | } |
| 395 | packet40 := wshrpc.CommandStreamData{ |
| 396 | Id: "test-gaps", |
| 397 | Seq: 40, |
| 398 | Data64: base64.StdEncoding.EncodeToString([]byte("iiiii")), |
| 399 | } |
| 400 | packet5 := wshrpc.CommandStreamData{ |
| 401 | Id: "test-gaps", |
| 402 | Seq: 5, |
| 403 | Data64: base64.StdEncoding.EncodeToString([]byte("bbbbb")), |
| 404 | } |
| 405 | |
| 406 | reader.RecvData(packet0) |
| 407 | reader.RecvData(packet40) // Way ahead - should be buffered |
| 408 | reader.RecvData(packet20) // Still ahead - should be buffered |
| 409 | |
| 410 | // Read first packet |
| 411 | buf := make([]byte, 10) |
| 412 | n, err := reader.Read(buf) |
| 413 | if err != nil { |
| 414 | t.Fatalf("Read failed: %v", err) |
| 415 | } |
| 416 | if n != 5 || string(buf[:n]) != "aaaaa" { |
| 417 | t.Fatalf("Expected 'aaaaa', got %q", string(buf[:n])) |
| 418 | } |
| 419 | |
| 420 | // Send packet to partially fill gap |
| 421 | reader.RecvData(packet5) |
| 422 | |
| 423 | // Should be able to read it now |
| 424 | n, err = reader.Read(buf) |
| 425 | if err != nil { |
| 426 | t.Fatalf("Second read failed: %v", err) |
| 427 | } |
| 428 | if n != 5 || string(buf[:n]) != "bbbbb" { |
| 429 | t.Fatalf("Expected 'bbbbb', got %q", string(buf[:n])) |
| 430 | } |
| 431 | |
| 432 | packet10 := wshrpc.CommandStreamData{ |
| 433 | Id: "test-gaps", |
| 434 | Seq: 10, |
| 435 | Data64: base64.StdEncoding.EncodeToString([]byte("ccccc")), |
| 436 | } |
| 437 | packet15 := wshrpc.CommandStreamData{ |
| 438 | Id: "test-gaps", |
nothing calls this directly
no test coverage detected