MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / TestOutOfOrderWithDuplicates

Function TestOutOfOrderWithDuplicates

pkg/streamclient/stream_test.go:331–379  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

329}
330
331func TestOutOfOrderWithDuplicates(t *testing.T) {
332 transport := newFakeTransport()
333 reader := NewReader("test-dup", 1024, transport)
334
335 packet0 := wshrpc.CommandStreamData{
336 Id: "test-dup",
337 Seq: 0,
338 Data64: base64.StdEncoding.EncodeToString([]byte("aaaaa")),
339 }
340 packet10 := wshrpc.CommandStreamData{
341 Id: "test-dup",
342 Seq: 10,
343 Data64: base64.StdEncoding.EncodeToString([]byte("ccccc")),
344 }
345 packet5First := wshrpc.CommandStreamData{
346 Id: "test-dup",
347 Seq: 5,
348 Data64: base64.StdEncoding.EncodeToString([]byte("xxxxx")),
349 }
350 packet5Second := wshrpc.CommandStreamData{
351 Id: "test-dup",
352 Seq: 5,
353 Data64: base64.StdEncoding.EncodeToString([]byte("bbbbb")),
354 }
355
356 reader.RecvData(packet0)
357 reader.RecvData(packet10) // OOO - buffered
358 reader.RecvData(packet5First) // OOO - buffered
359 reader.RecvData(packet5First) // Duplicate - should be ignored
360 reader.RecvData(packet5Second) // Duplicate with different data - should be ignored
361
362 // Read all data - should get all 3 packets in order
363 buf := make([]byte, 20)
364 n, err := reader.Read(buf)
365 if err != nil {
366 t.Fatalf("Read failed: %v", err)
367 }
368
369 // Should get all 15 bytes (3 packets * 5 bytes)
370 if n != 15 {
371 t.Fatalf("Expected to read 15 bytes, got %d", n)
372 }
373
374 // Should be "aaaaaxxxxxccccc" (first packet received for each seq wins)
375 expected := "aaaaaxxxxxccccc"
376 if string(buf[:n]) != expected {
377 t.Fatalf("Expected %q, got %q", expected, string(buf[:n]))
378 }
379}
380
381func TestOutOfOrderWithGaps(t *testing.T) {
382 transport := newFakeTransport()

Callers

nothing calls this directly

Calls 4

RecvDataMethod · 0.95
ReadMethod · 0.95
newFakeTransportFunction · 0.85
NewReaderFunction · 0.85

Tested by

no test coverage detected