Skip to content

Commit

Permalink
Tests: MultipleClientServerTests use the same test config for faster …
Browse files Browse the repository at this point in the history
…runs
  • Loading branch information
vis2k committed Dec 14, 2022
1 parent 7ac3f31 commit 4e43d57
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions kcp2k/Assets/Tests/Editor/MultiClientServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class MultipleClientServerTests
Interval: 1, // 1ms so at interval code at least runs.
Timeout: 2000,

// windows can be configured separately to test differently sized windows
// use 2x defaults so we can test larger max message than defaults too.
// IMPORTANT: default max message needs 127 fragments.
// default x2 needs 255 fragments.
// kcp sends 'frg' as 1 byte, so 255 still fits.
// need to try x3 to find possible bugs.
SendWindowSize: Kcp.WND_SND * 3,
ReceiveWindowSize: Kcp.WND_RCV * 3,
// large window sizes so large messages are flushed with very few
// update calls. otherwise tests take too long.
SendWindowSize: Kcp.WND_SND * 1000,
ReceiveWindowSize: Kcp.WND_RCV * 1000,

// congestion window _heavily_ restricts send/recv window sizes
// sending a max sized message would require thousands of updates.
CongestionWindow: false,

// maximum retransmit attempts until dead_link detected
// default * 2 to check if configuration works
Expand Down Expand Up @@ -147,13 +147,13 @@ int ServerLastConnectionId()
return server.connections.Last().Key;
}

void UpdateSeveralTimes()
void UpdateSeveralTimes(int amount)
{
// update serveral times to avoid flaky tests.
// => need to update at 120 times for default maxed sized messages
// where it requires 120+ fragments.
// => need to update even more often for 2x default max sized
for (int i = 0; i < 500; ++i)
for (int i = 0; i < amount; ++i)
{
clientA.Tick();
clientB.Tick();
Expand All @@ -168,37 +168,37 @@ void UpdateSeveralTimes()
void ConnectClientsBlocking(string hostname = "127.0.0.1")
{
clientA.Connect(hostname, Port, config);
UpdateSeveralTimes();
UpdateSeveralTimes(5);

clientB.Connect(hostname, Port, config);
UpdateSeveralTimes();
UpdateSeveralTimes(5);
}

// disconnect and give it enough time to handle
void DisconnectClientsBlocking()
{
clientA.Disconnect();
clientB.Disconnect();
UpdateSeveralTimes();
UpdateSeveralTimes(5);
}

// kick and give it enough time to handle
void KickClientBlocking(int connectionId)
{
server.Disconnect(connectionId);
UpdateSeveralTimes();
UpdateSeveralTimes(5);
}

void SendClientToServerBlocking(KcpClient client, ArraySegment<byte> message, KcpChannel channel)
{
client.Send(message, channel);
UpdateSeveralTimes();
UpdateSeveralTimes(10);
}

void SendServerToClientBlocking(int connectionId, ArraySegment<byte> message, KcpChannel channel)
{
server.Send(connectionId, message, channel);
UpdateSeveralTimes();
UpdateSeveralTimes(10);
}

// tests ///////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 4e43d57

Please sign in to comment.