Skip to content

Commit

Permalink
MultiplexTransport: Test to reproduce #3280
Browse files Browse the repository at this point in the history
  • Loading branch information
vis2k committed Dec 4, 2022
1 parent d77655f commit 2566911
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Assets/Mirror/Tests/Editor/MultiplexTransportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@ public void OriginalTransportId()
Assert.That(MultiplexTransport.OriginalTransportId(9, transportAmount), Is.EqualTo(0));
}

// test to reproduce https://github.com/vis2k/Mirror/issues/3280
[Test]
public void LargeConnectionId()
{
const int transportAmount = 3;

// let's say transport #2 gives us a very large connectionId.
// for example, KCP may use GetHashCode() as connectionId.
// 2147483647 - 10 = 2147483637
const int largeId = int.MaxValue - 10;
const int transportId = 2;

// connectionId * transportAmount + transportId
// = 2147483637 * 3 + 2
// = 6442450913
// which does not fit into int.max
int multiplexedId = MultiplexTransport.MultiplexConnectionId(largeId, transportId, transportAmount);
// Assert.That(multiplexedId, Is.EqualTo(6442450913)); not equal!

// convert it back. multiplexed isn't correct, so neither will this be
int originalId = MultiplexTransport.OriginalConnectionId(multiplexedId, transportAmount);
Assert.That(originalId, Is.EqualTo(largeId));
}

[Test]
public void TestAvailable()
{
Expand Down

0 comments on commit 2566911

Please sign in to comment.