Skip to content

Commit 0385e10

Browse files
committed
Fix flaky test_Network
When the (random) map size happens to be equal to the chunksize the test fails as the first mock-send finishes the transmission. Use named constants and ensure sizes.
1 parent d78eb3a commit 0385e10

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

tests/s25Main/network/testGameClient.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,22 @@ BOOST_AUTO_TEST_CASE(ClientDetectsMapBufferOverflow)
208208
clientMsgInterface.OnGameMessage(GameMessage_Server_TypeOK(GameMessage_Server_TypeOK::StatusCode::Ok, ""));
209209
clientMsgInterface.OnGameMessage(GameMessage_Server_Password("true"));
210210

211-
const auto mapDataSize = rttr::test::randomValue(10u, 100u);
211+
constexpr auto chunkSize = 10u;
212+
const auto mapDataSize = rttr::test::randomValue(2 * chunkSize, 10 * chunkSize); // At least 2 chunks
213+
const auto uncompressedSize = rttr::test::randomValue(mapDataSize, 10 * mapDataSize); // Doesn't really matter
212214
std::vector<char> mapData(mapDataSize);
213-
clientMsgInterface.OnGameMessage(GameMessage_Map_Info("testMap.swd", MapType::OldMap, 500u, mapDataSize, 0, 0));
215+
clientMsgInterface.OnGameMessage(
216+
GameMessage_Map_Info("testMap.swd", MapType::OldMap, uncompressedSize, mapDataSize, 0, 0));
214217
// First part of map
215-
MOCK_EXPECT(callbacks.CI_MapPartReceived).in(s).with(10u, mapDataSize).once();
216-
clientMsgInterface.OnGameMessage(GameMessage_Map_Data(true, 0, mapData.data(), 10));
218+
MOCK_EXPECT(callbacks.CI_MapPartReceived).in(s).with(chunkSize, mapDataSize).once();
219+
clientMsgInterface.OnGameMessage(GameMessage_Map_Data(true, 0, mapData.data(), chunkSize));
217220
BOOST_TEST_REQUIRE(mock::verify());
218221
BOOST_TEST(client.GetState() == ClientState::Connect);
219222

220223
// Remaining part of map but to big/wrong offset
221224
MOCK_EXPECT(callbacks.CI_Error).with(ClientError::MapTransmission).once();
222-
clientMsgInterface.OnGameMessage(GameMessage_Map_Data(true, 10, mapData.data(), mapDataSize - 9));
225+
const auto remainingSize = mapDataSize - chunkSize;
226+
clientMsgInterface.OnGameMessage(GameMessage_Map_Data(true, chunkSize, mapData.data(), remainingSize + 1u));
223227
BOOST_TEST(client.GetState() == ClientState::Stopped);
224228
}
225229

0 commit comments

Comments
 (0)