From e3c6d68288ad283754fbe51f3b7dbd103ad0ad31 Mon Sep 17 00:00:00 2001 From: Patricio Whittingslow Date: Wed, 5 Nov 2025 20:12:02 -0300 Subject: [PATCH] rigurously fix all tests --- tcp/txqueue.go | 5 ++++- tcp/txqueue_test.go | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tcp/txqueue.go b/tcp/txqueue.go index 52dbf09..337a294 100644 --- a/tcp/txqueue.go +++ b/tcp/txqueue.go @@ -179,11 +179,14 @@ func (rtx *ringTx) RecvACK(ack Value) error { } func (rtx *ringTx) sentAndUnsentBuffer() internal.Ring { + off := rtx.sentoff end := rtx.unsentend if end == 0 { end = rtx.sentend + } else if rtx.sentend == 0 { + off = rtx.unsentoff } - return internal.Ring{Buf: rtx.rawbuf, Off: rtx.sentoff, End: end} + return internal.Ring{Buf: rtx.rawbuf, Off: off, End: end} } func (rtx *ringTx) unsentRing() (internal.Ring, int) { diff --git a/tcp/txqueue_test.go b/tcp/txqueue_test.go index b82b05f..a85c41c 100644 --- a/tcp/txqueue_test.go +++ b/tcp/txqueue_test.go @@ -13,7 +13,7 @@ import ( func TestRingTx_op(t *testing.T) { const maxBuf = 32 const maxpkt = 3 - const Nops = 33 + const Nops = 6 const log = false type op uint8 const ( @@ -116,6 +116,17 @@ func TestRingTx_op(t *testing.T) { default: panic("unknown op") } + wantFree := bufsize - nsent - nunsent + gotFree := rtx.Free() + if wantFree != gotFree { + t.Fatalf("free mismatch got=%d want=%d size=%d sent=%d nunsent=%d", gotFree, wantFree, bufsize, nsent, nunsent) + } + minlen := min(len(dataSent), len(dataWritten)) + matched := bytes.Equal(dataSent[:minlen], dataWritten[:minlen]) + if !matched { + t.Fatal("mismatched data written\n", dataSent, "\n", dataWritten) + } + testQueueSanity(t, &rtx) } } }