diff --git a/Assets/Mirror/Tests/Editor/Batching/UnbatcherTests.cs b/Assets/Mirror/Tests/Editor/Batching/UnbatcherTests.cs index 2ec500e32..a1e243600 100644 --- a/Assets/Mirror/Tests/Editor/Batching/UnbatcherTests.cs +++ b/Assets/Mirror/Tests/Editor/Batching/UnbatcherTests.cs @@ -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(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() {