|
9 | 9 | using Cleipnir.ResilientFunctions.Domain.Exceptions; |
10 | 10 | using Cleipnir.ResilientFunctions.Messaging; |
11 | 11 | using Cleipnir.ResilientFunctions.Storage; |
| 12 | +using Cleipnir.ResilientFunctions.Tests.Utils; |
12 | 13 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
13 | 14 | using Shouldly; |
14 | 15 |
|
@@ -111,6 +112,32 @@ public async Task ClearRemovesPositionsFromIgnoreSetOnceDeleted() |
111 | 112 | clearer.NonClearedPositions().OrderBy(p => p).ShouldBe(new long[] { 1, 3 }); |
112 | 113 | } |
113 | 114 |
|
| 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 | + |
114 | 141 | private static MessageClearer CreateClearer( |
115 | 142 | IMessageStore messageStore, |
116 | 143 | Action<FrameworkException>? onUnhandledException = null, |
|
0 commit comments