Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tracker/inflights.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func (in *Inflights) Count() int { return in.count }

// reset frees all inflights.
func (in *Inflights) reset() {
in.count = 0
in.start = 0
in.count = 0
in.bytes = 0
}
22 changes: 22 additions & 0 deletions tracker/inflights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,28 @@ func TestInflightsFull(t *testing.T) {
}
}

func TestInflightsReset(t *testing.T) {
in := NewInflights(10, 1000)
// Imitate a semi-realistic flow during which the inflight tracker is
// periodically reset to empty. Byte usage must not "leak" across resets.
index := uint64(0)
for epoch := 0; epoch < 100; epoch++ {
in.reset()
// Add 5 messages. They should not max out the limit yet.
for i := 0; i < 5; i++ {
require.False(t, in.Full())
index++
in.Add(index, 16)
}
// Ack all but last 2 indices.
in.FreeLE(index - 2)
require.False(t, in.Full())
require.Equal(t, 2, in.Count())
}
in.FreeLE(index)
require.Equal(t, 0, in.Count())
}

func inflightsBuffer(indices []uint64, sizes []uint64) []inflight {
if len(indices) != len(sizes) {
panic("len(indices) != len(sizes)")
Expand Down