Skip to content

Commit bbdf598

Browse files
committed
Verify Clear's completion implies the positions are gone from the store
Add an end-to-end test against the real InMemoryFunctionStore: append messages, await Clear for a subset, then assert GetMessages no longer returns them the instant the task completes. Also gives the new positions-only DeleteMessages its first real-store coverage.
1 parent 090d2c0 commit bbdf598

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Core/Cleipnir.ResilientFunctions.Tests/Messaging/InMemoryTests/MessageClearerTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Cleipnir.ResilientFunctions.Domain.Exceptions;
1010
using Cleipnir.ResilientFunctions.Messaging;
1111
using Cleipnir.ResilientFunctions.Storage;
12+
using Cleipnir.ResilientFunctions.Tests.Utils;
1213
using Microsoft.VisualStudio.TestTools.UnitTesting;
1314
using Shouldly;
1415

@@ -111,6 +112,32 @@ public async Task ClearRemovesPositionsFromIgnoreSetOnceDeleted()
111112
clearer.NonClearedPositions().OrderBy(p => p).ShouldBe(new long[] { 1, 3 });
112113
}
113114

115+
[TestMethod]
116+
public async Task ClearedPositionsAreGoneFromTheStoreWhenTheReturnedTaskCompletes()
117+
{
118+
var functionStore = new InMemoryFunctionStore();
119+
var messageStore = functionStore.MessageStore;
120+
var storedId = TestStoredId.Create();
121+
122+
await messageStore.AppendMessages([
123+
new StoredIdAndMessage(storedId, Message()),
124+
new StoredIdAndMessage(storedId, Message()),
125+
new StoredIdAndMessage(storedId, Message())
126+
]);
127+
var positions = (await messageStore.GetMessages(storedId)).Select(m => m.Position).ToList();
128+
positions.Count.ShouldBe(3);
129+
130+
var clearer = CreateClearer(messageStore);
131+
await clearer.Clear(positions.Take(2).ToList()).WaitAsync(MaxWait);
132+
133+
// The instant Clear's task completes, the cleared messages must already be gone from the store.
134+
var remaining = (await messageStore.GetMessages(storedId)).Select(m => m.Position).ToList();
135+
remaining.ShouldBe(new[] { positions[2] });
136+
}
137+
138+
private static StoredMessage Message()
139+
=> new(MessageContent: new byte[] { 1 }, MessageType: new byte[] { 2 }, Position: 0, Replica: ReplicaId.Empty);
140+
114141
private static MessageClearer CreateClearer(
115142
IMessageStore messageStore,
116143
Action<FrameworkException>? onUnhandledException = null,

0 commit comments

Comments
 (0)