mirror of
https://github.com/soypat/lneto.git
synced 2026-09-05 14:29:11 +00:00
keep fixing ring queue things
This commit is contained in:
+2
-18
@@ -260,24 +260,8 @@ func (tx *ringTx) nextPkt() int {
|
|||||||
//
|
//
|
||||||
// | acked(free) | sent | unsent | free |
|
// | acked(free) | sent | unsent | free |
|
||||||
// 0 freeEnd=first.off last.end==unsent.off freeStart=unsent.end Size()
|
// 0 freeEnd=first.off last.end==unsent.off freeStart=unsent.end Size()
|
||||||
func (tx *ringTx) lims() (freeStart, freeEnd, sentEndorUnsentStart int) {
|
func (tx *ringTx) lims() (unsentStart, unsentEnd, sentStart, sentEnd int) {
|
||||||
freeStart = tx.unsentend
|
return tx.unsentoff, tx.unsentend, tx.sentoff, tx.sentend
|
||||||
if freeStart == 0 {
|
|
||||||
freeStart = tx.unsentoff
|
|
||||||
}
|
|
||||||
first := tx.pkt(tx.firstPkt())
|
|
||||||
if first.sent() {
|
|
||||||
freeEnd = first.off
|
|
||||||
sentEndorUnsentStart = tx.unsentoff
|
|
||||||
} else if tx.unsentend != 0 {
|
|
||||||
// sent section empty and unsent not empty.
|
|
||||||
freeEnd = tx.unsentoff
|
|
||||||
sentEndorUnsentStart = tx.unsentoff
|
|
||||||
} else {
|
|
||||||
freeEnd = tx.unsentoff
|
|
||||||
sentEndorUnsentStart = tx.unsentoff
|
|
||||||
}
|
|
||||||
return freeStart, freeEnd, sentEndorUnsentStart
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pkt *ringidx) sent() bool {
|
func (pkt *ringidx) sent() bool {
|
||||||
|
|||||||
+35
-10
@@ -12,6 +12,9 @@ func TestTxQueue(t *testing.T) {
|
|||||||
rng := rand.New(rand.NewSource(1))
|
rng := rand.New(rand.NewSource(1))
|
||||||
|
|
||||||
var rtx ringTx
|
var rtx ringTx
|
||||||
|
defer func() {
|
||||||
|
testQueueSanity(t, &rtx)
|
||||||
|
}()
|
||||||
increasingComplexityTests := []struct {
|
increasingComplexityTests := []struct {
|
||||||
name string
|
name string
|
||||||
test func(*testing.T)
|
test func(*testing.T)
|
||||||
@@ -169,16 +172,38 @@ func testQueueSanity(t *testing.T, rtx *ringTx) {
|
|||||||
t.Fatal("\n" + rtx.string())
|
t.Fatal("\n" + rtx.string())
|
||||||
t.Fatalf("want size=%d, got size=%d (free+sent+unsent=%d+%d+%d)", sz, gotSz, free, sent, unsent)
|
t.Fatalf("want size=%d, got size=%d (free+sent+unsent=%d+%d+%d)", sz, gotSz, free, sent, unsent)
|
||||||
}
|
}
|
||||||
freeStart, freeEnd, sentEnd := rtx.lims()
|
rsent, _ := rtx.sentRing()
|
||||||
gotFreeEnd := rtx.addOff(freeStart, free)
|
sentEmpty := rsent.Buffered() == 0
|
||||||
gotSentEnd := rtx.addOff(freeEnd, sent)
|
runsent, _ := rtx.unsentRing()
|
||||||
gotUnsentEnd := rtx.addOff(sentEnd, unsent)
|
unsentEmpty := runsent.Buffered() == 0
|
||||||
if free != 0 && gotFreeEnd != freeEnd {
|
all := rtx.sentAndUnsentBuffer()
|
||||||
t.Fatalf("want freeEnd=%d, got %d", freeEnd, gotFreeEnd)
|
allEmpty := all.Buffered() == 0
|
||||||
} else if sent != 0 && gotSentEnd != sentEnd {
|
if !sentEmpty {
|
||||||
t.Fatalf("want sentEnd=%d, got %d", sentEnd, gotSentEnd)
|
if all.Off != rsent.Off {
|
||||||
} else if unsent != 0 && gotUnsentEnd != freeStart {
|
t.Fatalf("want entire buffer start %d to equal sent start %d", all.Off, rsent.Off)
|
||||||
t.Fatalf("want unsentEnd=%d, got %d (freeStart)", freeStart, gotUnsentEnd)
|
} else if rsent.End == 0 {
|
||||||
|
t.Fatalf("expected not empty sent buffer End to be !=0, got %d", rsent.End)
|
||||||
|
}
|
||||||
|
gotSentEnd := rtx.addOff(rsent.Off, sent)
|
||||||
|
if gotSentEnd != rsent.End {
|
||||||
|
t.Fatalf("calculated sent end mismatches lim sent end %d != %d", gotSentEnd, rsent.End)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !unsentEmpty {
|
||||||
|
if all.End != runsent.End {
|
||||||
|
t.Fatalf("want entire buffer end %d to equal unsent end %d", all.End, runsent.End)
|
||||||
|
} else if runsent.End == 0 {
|
||||||
|
t.Fatalf("expected not empty unsent buffer End to be !=0, got %d", runsent.End)
|
||||||
|
}
|
||||||
|
gotUnsentEnd := rtx.addOff(runsent.Off, unsent)
|
||||||
|
if gotUnsentEnd != runsent.End {
|
||||||
|
t.Fatalf("calculated unsent end mismatches lim unsent end %d != %d", gotUnsentEnd, runsent.End)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if allEmpty && (!sentEmpty || !unsentEmpty) {
|
||||||
|
t.Fatalf("all buffer empty but sent|unsent(%v/%v) not empty", sentEmpty, unsentEmpty)
|
||||||
|
} else if !allEmpty && sentEmpty && unsentEmpty {
|
||||||
|
t.Fatal("all buffer not empty but sent&unsentempty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user