Skip to content

Commit

Permalink
make the soak test much more aggressive
Browse files Browse the repository at this point in the history
  • Loading branch information
gafferongames committed Dec 26, 2023
1 parent a48579e commit 98aa26f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 46 deletions.
93 changes: 47 additions & 46 deletions soak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

const int MaxPacketSize = 16 * 1024;
const int MaxSnapshotSize = 8 * 1024;
const int MaxBlockSize = 64 * 1024;
const int MaxBlockSize = 10 * 1024;

static volatile int quit = 0;

Expand All @@ -45,9 +45,9 @@ int SoakMain()

ClientServerConfig config;
config.maxPacketSize = MaxPacketSize;
config.clientMemory = 10 * 1024 * 1024;
config.clientMemory = 100 * 1024 * 1024;
config.serverGlobalMemory = 10 * 1024 * 1024;
config.serverPerClientMemory = 10 * 1024 * 1024;
config.serverPerClientMemory = 100 * 1024 * 1024;
config.numChannels = 2;
config.channel[UNRELIABLE_UNORDERED_CHANNEL].type = CHANNEL_TYPE_UNRELIABLE_UNORDERED;
config.channel[UNRELIABLE_UNORDERED_CHANNEL].maxBlockSize = MaxSnapshotSize;
Expand Down Expand Up @@ -108,7 +108,7 @@ int SoakMain()

if ( timeForNextClientMessage < time && ( rand() % 1000 ) == 0 )
{
timeForNextClientMessage = time + yojimbo_random_int( 1, 5 );
timeForNextClientMessage = time + yojimbo_random_int( 1, 1000 );
}

if ( timeForNextClientMessage <= time )
Expand All @@ -120,7 +120,7 @@ int SoakMain()
if ( !client.CanSendMessage( RELIABLE_ORDERED_CHANNEL ) )
break;

if ( rand() % 25 )
if ( rand() % 100 )
{
TestMessage * message = (TestMessage*) client.CreateMessage( TEST_MESSAGE );
if ( message )
Expand All @@ -130,10 +130,9 @@ int SoakMain()
numMessagesSentToServer++;
}
}
/*
else
{
int numBlocks = yojimbo_random_int( 1, 10 );
int numBlocks = yojimbo_random_int( 1, 3 );

for ( int k = 0; k < numBlocks; k++ )
{
Expand Down Expand Up @@ -161,70 +160,72 @@ int SoakMain()
}
}
}
*/
}
}

const int clientIndex = client.GetClientIndex();

if ( timeForNextServerMessage < time && ( rand() % 1000 ) == 0 )
{
timeForNextServerMessage = time + yojimbo_random_int( 1, 5 );
int delay = yojimbo_random_int( 1, 1000 );

timeForNextServerMessage = time + delay;
}

if ( server.IsClientConnected( clientIndex ) && timeForNextServerMessage <= time )
if ( server.IsClientConnected( clientIndex ) )
{
serverConnected = true;

const int messagesToSend = yojimbo_random_int( 0, 64 );

for ( int i = 0; i < messagesToSend; ++i )
if ( timeForNextServerMessage <= time )
{
if ( !server.CanSendMessage( clientIndex, RELIABLE_ORDERED_CHANNEL ) )
break;
const int messagesToSend = yojimbo_random_int( 0, 64 );

if ( rand() % 25 )
for ( int i = 0; i < messagesToSend; ++i )
{
TestMessage * message = (TestMessage*) server.CreateMessage( clientIndex, TEST_MESSAGE );
if ( message )
if ( !server.CanSendMessage( clientIndex, RELIABLE_ORDERED_CHANNEL ) )
break;

if ( rand() % 100 )
{
message->sequence = (uint16_t) numMessagesSentToClient;
server.SendMessage( clientIndex, RELIABLE_ORDERED_CHANNEL, message );
numMessagesSentToClient++;
TestMessage * message = (TestMessage*) server.CreateMessage( clientIndex, TEST_MESSAGE );
if ( message )
{
message->sequence = (uint16_t) numMessagesSentToClient;
server.SendMessage( clientIndex, RELIABLE_ORDERED_CHANNEL, message );
numMessagesSentToClient++;
}
}
}
/*
else
{
int numBlocks = yojimbo_random_int( 1, 10 );
for ( int k = 0; k < numBlocks; k++ )
else
{
if ( !server.CanSendMessage( clientIndex, RELIABLE_ORDERED_CHANNEL ) )
break;
int numBlocks = yojimbo_random_int( 1, 3 );

TestBlockMessage * blockMessage = (TestBlockMessage*) server.CreateMessage( clientIndex, TEST_BLOCK_MESSAGE );
if ( blockMessage )
for ( int k = 0; k < numBlocks; k++ )
{
blockMessage->sequence = (uint16_t) numMessagesSentToClient;
const int blockSize = 1 + ( int( numMessagesSentToClient ) * 33 ) % MaxBlockSize;
uint8_t * blockData = server.AllocateBlock( clientIndex, blockSize );
if ( blockData )
{
for ( int j = 0; j < blockSize; ++j )
blockData[j] = uint8_t( numMessagesSentToClient + j );
server.AttachBlockToMessage( clientIndex, blockMessage, blockData, blockSize );
server.SendMessage( clientIndex, RELIABLE_ORDERED_CHANNEL, blockMessage );
numMessagesSentToClient++;
}
else
if ( !server.CanSendMessage( clientIndex, RELIABLE_ORDERED_CHANNEL ) )
break;

TestBlockMessage * blockMessage = (TestBlockMessage*) server.CreateMessage( clientIndex, TEST_BLOCK_MESSAGE );
if ( blockMessage )
{
server.ReleaseMessage( clientIndex, blockMessage );
blockMessage->sequence = (uint16_t) numMessagesSentToClient;
const int blockSize = 1 + ( int( numMessagesSentToClient ) * 33 ) % MaxBlockSize;
uint8_t * blockData = server.AllocateBlock( clientIndex, blockSize );
if ( blockData )
{
for ( int j = 0; j < blockSize; ++j )
blockData[j] = uint8_t( numMessagesSentToClient + j );
server.AttachBlockToMessage( clientIndex, blockMessage, blockData, blockSize );
server.SendMessage( clientIndex, RELIABLE_ORDERED_CHANNEL, blockMessage );
numMessagesSentToClient++;
}
else
{
server.ReleaseMessage( clientIndex, blockMessage );
}
}
}
}
}
*/
}

while ( true )
Expand Down
2 changes: 2 additions & 0 deletions source/yojimbo_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ static void default_assert_handler( const char * condition, const char * functio
}

static int log_level = 0;

static int (*printf_function)( const char *, ... ) = printf;

void (*yojimbo_assert_function)( const char *, const char *, const char * file, int line ) = default_assert_handler;

void yojimbo_log_level( int level )
Expand Down
3 changes: 3 additions & 0 deletions source/yojimbo_reliable_ordered_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ namespace yojimbo
uint16_t previousMessageId = 0;
int usedBits = ConservativeMessageHeaderBits;
int giveUpCounter = 0;
#if YOJIMBO_DEBUG
const int maxBits = availableBits;
#endif // YOJIMBO_DEBUG

for ( int i = 0; i < messageLimit; ++i )
{
Expand Down Expand Up @@ -382,6 +384,7 @@ namespace yojimbo
if ( yojimbo_sequence_greater_than( messageId, maxMessageId ) )
{
// Did you forget to dequeue messages on the receiver?
yojimbo_printf( YOJIMBO_LOG_LEVEL_ERROR, "sequence overflow: %d vs. [%d,%d]\n", messageId, minMessageId, maxMessageId );
SetErrorLevel( CHANNEL_ERROR_DESYNC );
return;
}
Expand Down

0 comments on commit 98aa26f

Please sign in to comment.