Skip to content

Commit

Permalink
Add failing test coverage of exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Oct 31, 2024
1 parent 5280840 commit 81fc6e4
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions osu.Server.QueueProcessor.Tests/BatchProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,40 @@ public void SendThenErrorDoesRetry()
Assert.Equal(obj, receivedObject);
}

[Fact]
public void MultipleErrorsAttachedToCorrectItems()
{
var cts = new CancellationTokenSource(10000);

var obj1 = FakeData.New();
var obj2 = FakeData.New();

bool gotCorrectExceptionForItem1 = false;
bool gotCorrectExceptionForItem2 = false;

processor.Error += (exception, item) =>
{
Assert.NotNull(exception);

gotCorrectExceptionForItem1 |= Equals(item.Data, obj1.Data) && exception.Message == "1";
gotCorrectExceptionForItem2 |= Equals(item.Data, obj2.Data) && exception.Message == "2";
};

processor.PushToQueue(new[] { obj1, obj2 });

processor.Received += o =>
{
if (Equals(o.Data, obj1.Data)) throw new Exception("1");
if (Equals(o.Data, obj2.Data)) throw new Exception("2");
};

processor.Run(cts.Token);

Assert.Equal(0, processor.GetQueueSize());
Assert.True(gotCorrectExceptionForItem1);
Assert.True(gotCorrectExceptionForItem2);
}

[Fact]
public void SendThenErrorForeverDoesDrop()
{
Expand Down

0 comments on commit 81fc6e4

Please sign in to comment.