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 9400698
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Assets/Mirror/Tests/Editor/MultiplexTransportTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ public void OriginalTransportId()
Assert.That(MultiplexTransport.OriginalTransportId(9, transportAmount), Is.EqualTo(0));
}

// test to reproduce https://github.com/vis2k/Mirror/issues/3280
[Test, Ignore("TODO")]
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.
const int largeId = int.MaxValue - 10; // 2147483647 - 10 = 2147483637
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 9400698

Please sign in to comment.