Skip to content

Commit

Permalink
test: Fixed test compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoTenPvP committed Sep 4, 2019
1 parent 1c542bf commit e6abf8a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
16 changes: 8 additions & 8 deletions Ruffles.Tests/Channels/ReliableSequencedChannelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public void TestSimpleMessage()

byte[] message = BufferHelper.GetRandomBuffer(1024, 0);

HeapMemory messageMemory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message, 0, 1024), out bool dealloc)[0];
ArraySegment<byte>? payload = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(messageMemory.Buffer, (int)messageMemory.VirtualOffset + 2, (int)messageMemory.VirtualCount - 2), out bool hasMore);
HeapMemory messageMemory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message, 0, 1024), out _, out bool dealloc)[0];
ArraySegment<byte>? payload = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(messageMemory.Buffer, (int)messageMemory.VirtualOffset + 2, (int)messageMemory.VirtualCount - 2), out _, out bool hasMore);

Assert.NotNull(payload);
Assert.False(hasMore);
Expand All @@ -53,16 +53,16 @@ public void TestOutOfOrder()
byte[] message3 = BufferHelper.GetRandomBuffer(1024, 2);

// Sequence all payloads as outgoing
HeapMemory message1Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message1, 0, 1024), out bool dealloc)[0];
HeapMemory message2Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message2, 0, 1024), out dealloc)[0];
HeapMemory message3Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message3, 0, 1024), out dealloc)[0];
HeapMemory message1Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message1, 0, 1024), out _, out bool dealloc)[0];
HeapMemory message2Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message2, 0, 1024), out _, out dealloc)[0];
HeapMemory message3Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message3, 0, 1024), out _, out dealloc)[0];

// Consume 1st payload
ArraySegment<byte>? payload1 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message1Memory.Buffer, (int)message1Memory.VirtualOffset + 2, (int)message1Memory.VirtualCount - 2), out bool hasMore1);
ArraySegment<byte>? payload1 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message1Memory.Buffer, (int)message1Memory.VirtualOffset + 2, (int)message1Memory.VirtualCount - 2), out _, out bool hasMore1);
// Consume 3rd payload
ArraySegment<byte>? payload3 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message3Memory.Buffer, (int)message3Memory.VirtualOffset + 2, (int)message3Memory.VirtualCount - 2), out bool hasMore3);
ArraySegment<byte>? payload3 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message3Memory.Buffer, (int)message3Memory.VirtualOffset + 2, (int)message3Memory.VirtualCount - 2), out _, out bool hasMore3);
// Consume 2nd payload
ArraySegment<byte>? payload2 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message2Memory.Buffer, (int)message2Memory.VirtualOffset + 2, (int)message2Memory.VirtualCount - 2), out bool hasMore2);
ArraySegment<byte>? payload2 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message2Memory.Buffer, (int)message2Memory.VirtualOffset + 2, (int)message2Memory.VirtualCount - 2), out _, out bool hasMore2);

HeapMemory pollMemory = serverChannel.HandlePoll();

Expand Down
45 changes: 23 additions & 22 deletions Ruffles.Tests/Channels/ReliableSequencedFragmentedChannelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Ruffles.Tests.Helpers;
using Ruffles.Tests.Stubs;
using System;
using System.Collections.Generic;

namespace Ruffles.Tests.Channels
{
Expand All @@ -25,8 +26,8 @@ public void TestSimpleMessageSingleFragment()

byte[] message = BufferHelper.GetRandomBuffer(1024, 0);

HeapMemory messageMemory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message, 0, 1024), out bool dealloc)[0];
ArraySegment<byte>? payload = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(messageMemory.Buffer, (int)messageMemory.VirtualOffset + 2, (int)messageMemory.VirtualCount - 2), out bool hasMore);
HeapMemory messageMemory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message, 0, 1024), out _, out bool dealloc)[0];
ArraySegment<byte>? payload = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(messageMemory.Buffer, (int)messageMemory.VirtualOffset + 2, (int)messageMemory.VirtualCount - 2), out _, out bool hasMore);

Assert.Null(payload);
Assert.True(hasMore);
Expand Down Expand Up @@ -57,16 +58,16 @@ public void TestOutOfOrderSingleFragment()
byte[] message3 = BufferHelper.GetRandomBuffer(1024, 2);

// Sequence all payloads as outgoing
HeapMemory message1Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message1, 0, 1024), out bool dealloc)[0];
HeapMemory message2Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message2, 0, 1024), out dealloc)[0];
HeapMemory message3Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message3, 0, 1024), out dealloc)[0];
HeapMemory message1Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message1, 0, 1024), out _, out bool dealloc)[0];
HeapMemory message2Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message2, 0, 1024), out _, out dealloc)[0];
HeapMemory message3Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message3, 0, 1024), out _, out dealloc)[0];

// Consume 1st payload
ArraySegment<byte>? payload1 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message1Memory.Buffer, (int)message1Memory.VirtualOffset + 2, (int)message1Memory.VirtualCount - 2), out bool hasMore1);
ArraySegment<byte>? payload1 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message1Memory.Buffer, (int)message1Memory.VirtualOffset + 2, (int)message1Memory.VirtualCount - 2), out _, out bool hasMore1);
// Consume 3rd payload
ArraySegment<byte>? payload3 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message3Memory.Buffer, (int)message3Memory.VirtualOffset + 2, (int)message3Memory.VirtualCount - 2), out bool hasMore3);
ArraySegment<byte>? payload3 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message3Memory.Buffer, (int)message3Memory.VirtualOffset + 2, (int)message3Memory.VirtualCount - 2), out _, out bool hasMore3);
// Consume 2nd payload
ArraySegment<byte>? payload2 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message2Memory.Buffer, (int)message2Memory.VirtualOffset + 2, (int)message2Memory.VirtualCount - 2), out bool hasMore2);
ArraySegment<byte>? payload2 = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message2Memory.Buffer, (int)message2Memory.VirtualOffset + 2, (int)message2Memory.VirtualCount - 2), out _, out bool hasMore2);

Assert.Null(payload1);
Assert.Null(payload2);
Expand Down Expand Up @@ -116,24 +117,24 @@ public void TestOutOfFragmentOrderMultiFragment()
byte[] message3 = BufferHelper.GetRandomBuffer(1024 * 6, 2);

// Sequence all payloads as outgoing
HeapMemory[] message1Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message1, 0, 1024 * 5), out bool dealloc);
HeapMemory[] message2Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message2, 0, 1024 * 8), out dealloc);
HeapMemory[] message3Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message3, 0, 1024 * 6), out dealloc);
HeapMemory[] message1Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message1, 0, 1024 * 5), out _, out bool dealloc);
HeapMemory[] message2Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message2, 0, 1024 * 8), out _, out dealloc);
HeapMemory[] message3Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message3, 0, 1024 * 6), out _, out dealloc);

// Consume 1st payload all except first fragment
bool[] hasMore1s = new bool[message1Memory.Length];
ArraySegment<byte>?[] payload1s = new ArraySegment<byte>?[message1Memory.Length];
for (int i = 1; i < message1Memory.Length; i++)
{
payload1s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message1Memory[i].Buffer, (int)message1Memory[i].VirtualOffset + 2, (int)message1Memory[i].VirtualCount - 2), out bool hasMore1);
payload1s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message1Memory[i].Buffer, (int)message1Memory[i].VirtualOffset + 2, (int)message1Memory[i].VirtualCount - 2), out _, out bool hasMore1);
hasMore1s[i] = hasMore1;
}
// Consume 3rd payload only last fragment
bool[] hasMore3s = new bool[message3Memory.Length];
ArraySegment<byte>?[] payload3s = new ArraySegment<byte>?[message3Memory.Length];

{
payload3s[payload3s.Length - 1] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message3Memory[payload3s.Length - 1].Buffer, (int)message3Memory[payload3s.Length - 1].VirtualOffset + 2, (int)message3Memory[payload3s.Length - 1].VirtualCount - 2), out bool hasMore3);
payload3s[payload3s.Length - 1] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message3Memory[payload3s.Length - 1].Buffer, (int)message3Memory[payload3s.Length - 1].VirtualOffset + 2, (int)message3Memory[payload3s.Length - 1].VirtualCount - 2), out _, out bool hasMore3);
hasMore3s[payload3s.Length - 1] = hasMore3;
}

Expand All @@ -142,22 +143,22 @@ public void TestOutOfFragmentOrderMultiFragment()
ArraySegment<byte>?[] payload2s = new ArraySegment<byte>?[message2Memory.Length];
for (int i = 0; i < message2Memory.Length; i++)
{
payload2s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message2Memory[i].Buffer, (int)message2Memory[i].VirtualOffset + 2, (int)message2Memory[i].VirtualCount - 2), out bool hasMore2);
payload2s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message2Memory[i].Buffer, (int)message2Memory[i].VirtualOffset + 2, (int)message2Memory[i].VirtualCount - 2), out _, out bool hasMore2);
hasMore2s[i] = hasMore2;
}

{
// Consume 3rd payload all except last fragment (completes the last payload)
for (int i = 0; i < message3Memory.Length - 1; i++)
{
payload3s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message3Memory[i].Buffer, (int)message3Memory[i].VirtualOffset + 2, (int)message3Memory[i].VirtualCount - 2), out bool hasMore3);
payload3s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message3Memory[i].Buffer, (int)message3Memory[i].VirtualOffset + 2, (int)message3Memory[i].VirtualCount - 2), out _, out bool hasMore3);
hasMore3s[i] = hasMore3;
}
}

{
// Consume 1st payload first fragment (completes first payload)
payload1s[0] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message1Memory[0].Buffer, (int)message1Memory[0].VirtualOffset + 2, (int)message1Memory[0].VirtualCount - 2), out bool hasMore1);
payload1s[0] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message1Memory[0].Buffer, (int)message1Memory[0].VirtualOffset + 2, (int)message1Memory[0].VirtualCount - 2), out _, out bool hasMore1);
hasMore1s[0] = hasMore1;
}

Expand Down Expand Up @@ -218,32 +219,32 @@ public void TestOutOfPacketOrderMultiFragment()
byte[] message3 = BufferHelper.GetRandomBuffer(1024 * 6, 2);

// Sequence all payloads as outgoing
HeapMemory[] message1Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message1, 0, 1024 * 5), out bool dealloc);
HeapMemory[] message2Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message2, 0, 1024 * 8), out dealloc);
HeapMemory[] message3Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message3, 0, 1024 * 6), out dealloc);
HeapMemory[] message1Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message1, 0, 1024 * 5), out _, out bool dealloc);
HeapMemory[] message2Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message2, 0, 1024 * 8), out _, out dealloc);
HeapMemory[] message3Memory = clientChannel.CreateOutgoingMessage(new ArraySegment<byte>(message3, 0, 1024 * 6), out _, out dealloc);

// Consume 1st payload
bool[] hasMore1s = new bool[message1Memory.Length];
ArraySegment<byte>?[] payload1s = new ArraySegment<byte>?[message1Memory.Length];
for (int i = 0; i < message1Memory.Length; i++)
{
payload1s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message1Memory[i].Buffer, (int)message1Memory[i].VirtualOffset + 2, (int)message1Memory[i].VirtualCount - 2), out bool hasMore1);
payload1s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message1Memory[i].Buffer, (int)message1Memory[i].VirtualOffset + 2, (int)message1Memory[i].VirtualCount - 2), out _, out bool hasMore1);
hasMore1s[i] = hasMore1;
}
// Consume 3rd payload
bool[] hasMore3s = new bool[message3Memory.Length];
ArraySegment<byte>?[] payload3s = new ArraySegment<byte>?[message3Memory.Length];
for (int i = 0; i < message3Memory.Length; i++)
{
payload3s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message3Memory[i].Buffer, (int)message3Memory[i].VirtualOffset + 2, (int)message3Memory[i].VirtualCount - 2), out bool hasMore3);
payload3s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message3Memory[i].Buffer, (int)message3Memory[i].VirtualOffset + 2, (int)message3Memory[i].VirtualCount - 2), out _, out bool hasMore3);
hasMore3s[i] = hasMore3;
}
// Consume 2nd payload
bool[] hasMore2s = new bool[message2Memory.Length];
ArraySegment<byte>?[] payload2s = new ArraySegment<byte>?[message2Memory.Length];
for (int i = 0; i < message2Memory.Length; i++)
{
payload2s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message2Memory[i].Buffer, (int)message2Memory[i].VirtualOffset + 2, (int)message2Memory[i].VirtualCount - 2), out bool hasMore2);
payload2s[i] = serverChannel.HandleIncomingMessagePoll(new ArraySegment<byte>(message2Memory[i].Buffer, (int)message2Memory[i].VirtualOffset + 2, (int)message2Memory[i].VirtualCount - 2), out _, out bool hasMore2);
hasMore2s[i] = hasMore2;
}

Expand Down
2 changes: 1 addition & 1 deletion Ruffles.Tests/Stubs/ConnectionStub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal override void Disconnect(bool sendMessage)
}
}

internal override void SendRaw(ArraySegment<byte> payload, bool noMerge)
internal override void SendRaw(ArraySegment<byte> payload, bool noMerge, ushort headerSize)
{
if (OnSendData != null)
{
Expand Down

0 comments on commit e6abf8a

Please sign in to comment.