Tests: nimoyd unbatcher repro

This commit is contained in:
vis2k 2021-07-07 11:20:40 +08:00
parent fb608d685a
commit fe7ed2ace1

View File

@ -21,6 +21,29 @@ public void GetNextMessage_NoBatches()
Assert.That(result, Is.False);
}
// test for nimoyd bug, where calling getnextmessage after the previous
// call already returned false would cause an InvalidOperationException.
[Test]
public void GetNextMessage_NoBatches_AfterWeHadBatches()
{
// add batch
byte[] batch = BatcherTests.ConcatTimestamp(TimeStamp, new byte[2]);
unbatcher.AddBatch(new ArraySegment<byte>(batch));
// get next message, pretend we read the whole thing
bool result = unbatcher.GetNextMessage(out NetworkReader reader, out _);
Assert.That(result, Is.True);
reader.Position = reader.Length;
// shouldn't get another one
result = unbatcher.GetNextMessage(out reader, out _);
Assert.That(result, Is.False);
// calling it again was causing "InvalidOperationException: Queue empty"
result = unbatcher.GetNextMessage(out reader, out _);
Assert.That(result, Is.False);
}
[Test]
public void GetNextMessage_OneBatch()
{