fix: correct MaxBytes enforcement and consumer start sequence after purge
StreamManager.Capture now accounts for full message size (subject + payload + 16-byte overhead) when checking MaxBytes, matching Go's memStoreMsgSize. PullConsumerEngine uses stream FirstSeq instead of hardcoded 1 for DeliverAll after purge. Fix 6 tests with Go parity assertions and updated MaxBytes values.
This commit is contained in:
@@ -49,11 +49,13 @@ public class StorageRetentionTests
|
||||
[Fact]
|
||||
public async Task Max_bytes_limit_enforced()
|
||||
{
|
||||
// Each payload is 100 bytes. Set MaxBytes to hold exactly 5 messages.
|
||||
// Go: memStoreMsgSize = subject.Length + headers.Length + data.Length + 16
|
||||
// Each message = "byteslimit.foo"(14) + payload(100) + overhead(16) = 130 bytes.
|
||||
var payload = new byte[100];
|
||||
const int payloadSize = 100;
|
||||
const string subject = "byteslimit.foo";
|
||||
const int msgSize = 14 + 100 + 16; // 130
|
||||
const int maxCapacity = 5;
|
||||
var maxBytes = (long)(payloadSize * maxCapacity);
|
||||
var maxBytes = (long)(msgSize * maxCapacity); // 650
|
||||
|
||||
var manager = new StreamManager();
|
||||
manager.CreateOrUpdate(new StreamConfig
|
||||
@@ -66,16 +68,16 @@ public class StorageRetentionTests
|
||||
|
||||
// Store exactly maxCapacity messages — should all fit.
|
||||
for (var i = 0; i < maxCapacity; i++)
|
||||
manager.Capture("byteslimit.foo", payload);
|
||||
manager.Capture(subject, payload);
|
||||
|
||||
manager.TryGet("BYTESLIMIT", out var handle).ShouldBeTrue();
|
||||
var stateAtCapacity = await handle.Store.GetStateAsync(default);
|
||||
stateAtCapacity.Messages.ShouldBe((ulong)maxCapacity);
|
||||
stateAtCapacity.Bytes.ShouldBe((ulong)(payloadSize * maxCapacity));
|
||||
stateAtCapacity.Bytes.ShouldBe((ulong)(msgSize * maxCapacity));
|
||||
|
||||
// Store 5 more — each one should displace an old message.
|
||||
for (var i = 0; i < maxCapacity; i++)
|
||||
manager.Capture("byteslimit.foo", payload);
|
||||
manager.Capture(subject, payload);
|
||||
|
||||
var stateFinal = await handle.Store.GetStateAsync(default);
|
||||
stateFinal.Messages.ShouldBe((ulong)maxCapacity);
|
||||
|
||||
Reference in New Issue
Block a user