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
9 changes: 5 additions & 4 deletions mcp/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,11 @@ func (s *MemoryEventStore) purge() {
for _, dl := range sm {
if dl.size > 0 {
r := dl.removeFirst()
if r > 0 {
changed = true
s.nBytes -= r
}
// Even if we remove an empty chunk, that's
// still progress. There may be non-empty
// chunks after it.
changed = true
s.nBytes -= r
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions mcp/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,29 @@ func TestMemoryEventStoreAfter(t *testing.T) {
}
}

func TestMemoryEventStorePurgeEmpty(t *testing.T) {
ctx := context.Background()
s := NewMemoryEventStore(nil)
s.SetMaxBytes(100)

// Append an empty chunk first.
if err := s.Append(ctx, "S1", "1", []byte("")); err != nil {
t.Fatal(err)
}
// Append a non-empty chunk.
if err := s.Append(ctx, "S1", "1", []byte("1234567890")); err != nil {
t.Fatal(err)
}
// Now nBytes = 10, but the first chunk is empty.

// This should not panic.
s.SetMaxBytes(5)

if s.nBytes > 5 {
t.Errorf("got nBytes %d, want <= 5", s.nBytes)
}
}

func BenchmarkMemoryEventStore(b *testing.B) {
// Benchmark with various settings for event store size, number of session,
// and payload size.
Expand Down
Loading