Skip to content

Commit 81fc6e4

Browse files
committed
Add failing test coverage of exception handling
1 parent 5280840 commit 81fc6e4

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

osu.Server.QueueProcessor.Tests/BatchProcessorTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,40 @@ public void SendThenErrorDoesRetry()
195195
Assert.Equal(obj, receivedObject);
196196
}
197197

198+
[Fact]
199+
public void MultipleErrorsAttachedToCorrectItems()
200+
{
201+
var cts = new CancellationTokenSource(10000);
202+
203+
var obj1 = FakeData.New();
204+
var obj2 = FakeData.New();
205+
206+
bool gotCorrectExceptionForItem1 = false;
207+
bool gotCorrectExceptionForItem2 = false;
208+
209+
processor.Error += (exception, item) =>
210+
{
211+
Assert.NotNull(exception);
212+
213+
gotCorrectExceptionForItem1 |= Equals(item.Data, obj1.Data) && exception.Message == "1";
214+
gotCorrectExceptionForItem2 |= Equals(item.Data, obj2.Data) && exception.Message == "2";
215+
};
216+
217+
processor.PushToQueue(new[] { obj1, obj2 });
218+
219+
processor.Received += o =>
220+
{
221+
if (Equals(o.Data, obj1.Data)) throw new Exception("1");
222+
if (Equals(o.Data, obj2.Data)) throw new Exception("2");
223+
};
224+
225+
processor.Run(cts.Token);
226+
227+
Assert.Equal(0, processor.GetQueueSize());
228+
Assert.True(gotCorrectExceptionForItem1);
229+
Assert.True(gotCorrectExceptionForItem2);
230+
}
231+
198232
[Fact]
199233
public void SendThenErrorForeverDoesDrop()
200234
{

0 commit comments

Comments
 (0)