AWSGameLiftServerManagerTest.cpp 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AWSGameLiftServerFixture.h>
  9. #include <AWSGameLiftServerMocks.h>
  10. #include <AzCore/Interface/Interface.h>
  11. #include <AzFramework/IO/LocalFileIO.h>
  12. #include <AzTest/Utils.h>
  13. #include <Multiplayer/Session/SessionConfig.h>
  14. #include <Multiplayer/Session/SessionNotifications.h>
  15. namespace UnitTest
  16. {
  17. static constexpr const char TEST_SERVER_MATCHMAKING_DATA[] =
  18. R"({
  19. "matchId":"testmatchid",
  20. "matchmakingConfigurationArn":"testmatchconfig",
  21. "teams":[
  22. {"name":"testteam",
  23. "players":[
  24. {"playerId":"testplayer",
  25. "attributes":{
  26. "skills":{
  27. "attributeType":"STRING_DOUBLE_MAP",
  28. "valueAttribute":{"test1":10.0,"test2":20.0,"test3":30.0,"test4":40.0}
  29. },
  30. "mode":{
  31. "attributeType":"STRING",
  32. "valueAttribute":"testmode"
  33. },
  34. "level":{
  35. "attributeType":"DOUBLE",
  36. "valueAttribute":10.0
  37. },
  38. "items":{
  39. "attributeType":"STRING_LIST",
  40. "valueAttribute":["test1","test2","test3"]
  41. }
  42. }},
  43. {"playerId":"secondplayer",
  44. "attributes":{
  45. "mode":{
  46. "attributeType":"STRING",
  47. "valueAttribute":"testmode"
  48. }
  49. }}
  50. ]}
  51. ]
  52. })";
  53. Aws::GameLift::Server::Model::StartMatchBackfillRequest GetTestStartMatchBackfillRequest()
  54. {
  55. Aws::GameLift::Server::Model::StartMatchBackfillRequest request;
  56. request.SetMatchmakingConfigurationArn("testmatchconfig");
  57. Aws::GameLift::Server::Model::Player player;
  58. player.SetPlayerId("testplayer");
  59. player.SetTeam("testteam");
  60. player.AddPlayerAttribute("mode", Aws::GameLift::Server::Model::AttributeValue("testmode"));
  61. player.AddPlayerAttribute("level", Aws::GameLift::Server::Model::AttributeValue(10.0));
  62. auto sdmValue = Aws::GameLift::Server::Model::AttributeValue::ConstructStringDoubleMap();
  63. sdmValue.AddStringAndDouble("test1", 10.0);
  64. player.AddPlayerAttribute("skills", sdmValue);
  65. auto slValue = Aws::GameLift::Server::Model::AttributeValue::ConstructStringList();
  66. slValue.AddString("test1");
  67. player.AddPlayerAttribute("items", slValue);
  68. player.AddLatencyInMs("testregion", 10);
  69. request.AddPlayer(player);
  70. request.SetTicketId("testticket");
  71. return request;
  72. }
  73. AWSGameLiftPlayer GetTestGameLiftPlayer()
  74. {
  75. AWSGameLiftPlayer player;
  76. player.m_team = "testteam";
  77. player.m_playerId = "testplayer";
  78. player.m_playerAttributes.emplace("mode", "{\"S\": \"testmode\"}");
  79. player.m_playerAttributes.emplace("level", "{\"N\": 10.0}");
  80. player.m_playerAttributes.emplace("skills", "{\"SDM\": {\"test1\":10.0}}");
  81. player.m_playerAttributes.emplace("items", "{\"SL\": [\"test1\"]}");
  82. player.m_latencyInMs.emplace("testregion", 10);
  83. return player;
  84. }
  85. MATCHER_P(StartMatchBackfillRequestMatcher, expectedRequest, "")
  86. {
  87. // Custome matcher for checking the SearchSessionsResponse type argument.
  88. AZ_UNUSED(result_listener);
  89. if (strcmp(arg.GetGameSessionArn().c_str(), expectedRequest.GetGameSessionArn().c_str()) != 0)
  90. {
  91. return false;
  92. }
  93. if (strcmp(arg.GetMatchmakingConfigurationArn().c_str(), expectedRequest.GetMatchmakingConfigurationArn().c_str()) != 0)
  94. {
  95. return false;
  96. }
  97. if (strcmp(arg.GetTicketId().c_str(), expectedRequest.GetTicketId().c_str()) != 0)
  98. {
  99. return false;
  100. }
  101. if (arg.GetPlayers().size() != expectedRequest.GetPlayers().size())
  102. {
  103. return false;
  104. }
  105. for (int playerIndex = 0; playerIndex < expectedRequest.GetPlayers().size(); playerIndex++)
  106. {
  107. auto actualPlayerAttributes = arg.GetPlayers()[playerIndex].GetPlayerAttributes();
  108. auto expectedPlayerAttributes = expectedRequest.GetPlayers()[playerIndex].GetPlayerAttributes();
  109. if (actualPlayerAttributes.size() != expectedPlayerAttributes.size())
  110. {
  111. return false;
  112. }
  113. for (auto attributePair : expectedPlayerAttributes)
  114. {
  115. if (actualPlayerAttributes.find(attributePair.first) == actualPlayerAttributes.end())
  116. {
  117. return false;
  118. }
  119. if (!(attributePair.second.GetType() == actualPlayerAttributes[attributePair.first].GetType() &&
  120. (attributePair.second.GetS() == actualPlayerAttributes[attributePair.first].GetS() ||
  121. attributePair.second.GetN() == actualPlayerAttributes[attributePair.first].GetN() ||
  122. attributePair.second.GetSL() == actualPlayerAttributes[attributePair.first].GetSL() ||
  123. attributePair.second.GetSDM() == actualPlayerAttributes[attributePair.first].GetSDM())))
  124. {
  125. return false;
  126. }
  127. }
  128. auto actualLatencies = arg.GetPlayers()[playerIndex].GetLatencyInMs();
  129. auto expectedLatencies = expectedRequest.GetPlayers()[playerIndex].GetLatencyInMs();
  130. if (actualLatencies.size() != expectedLatencies.size())
  131. {
  132. return false;
  133. }
  134. for (auto latencyPair : expectedLatencies)
  135. {
  136. if (actualLatencies.find(latencyPair.first) == actualLatencies.end())
  137. {
  138. return false;
  139. }
  140. if (latencyPair.second != actualLatencies[latencyPair.first])
  141. {
  142. return false;
  143. }
  144. }
  145. }
  146. return true;
  147. }
  148. class SessionNotificationsHandlerMock
  149. : public Multiplayer::SessionNotificationBus::Handler
  150. {
  151. public:
  152. SessionNotificationsHandlerMock()
  153. {
  154. Multiplayer::SessionNotificationBus::Handler::BusConnect();
  155. }
  156. ~SessionNotificationsHandlerMock()
  157. {
  158. Multiplayer::SessionNotificationBus::Handler::BusDisconnect();
  159. }
  160. MOCK_METHOD0(OnSessionHealthCheck, bool());
  161. MOCK_METHOD1(OnCreateSessionBegin, bool(const Multiplayer::SessionConfig&));
  162. MOCK_METHOD0(OnCreateSessionEnd, void());
  163. MOCK_METHOD0(OnDestroySessionBegin, bool());
  164. MOCK_METHOD0(OnDestroySessionEnd, void());
  165. MOCK_METHOD2(OnUpdateSessionBegin, void(const Multiplayer::SessionConfig&, const AZStd::string&));
  166. MOCK_METHOD0(OnUpdateSessionEnd, void());
  167. };
  168. class GameLiftServerManagerTest
  169. : public AWSGameLiftServerFixture
  170. {
  171. public:
  172. void SetUp() override
  173. {
  174. AWSGameLiftServerFixture::SetUp();
  175. GameLiftServerProcessDesc serverDesc;
  176. m_serverManager = AZStd::make_unique<NiceMock<AWSGameLiftServerManagerMock>>();
  177. // Set up the file IO and alias
  178. m_localFileIO = aznew AZ::IO::LocalFileIO();
  179. m_priorFileIO = AZ::IO::FileIOBase::GetInstance();
  180. AZ::IO::FileIOBase::SetInstance(nullptr);
  181. AZ::IO::FileIOBase::SetInstance(m_localFileIO);
  182. m_localFileIO->SetAlias("@log@", m_tempDirectory.GetDirectory());
  183. }
  184. void TearDown() override
  185. {
  186. AZ::IO::FileIOBase::SetInstance(nullptr);
  187. delete m_localFileIO;
  188. AZ::IO::FileIOBase::SetInstance(m_priorFileIO);
  189. m_serverManager.reset();
  190. AWSGameLiftServerFixture::TearDown();
  191. }
  192. AZStd::unique_ptr<NiceMock<AWSGameLiftServerManagerMock>> m_serverManager;
  193. AZ::IO::FileIOBase* m_priorFileIO;
  194. AZ::IO::FileIOBase* m_localFileIO;
  195. private:
  196. AZ::Test::ScopedAutoTempDirectory m_tempDirectory;
  197. };
  198. TEST_F(GameLiftServerManagerTest, InitializeGameLiftServerSDK_InitializeTwice_InitSDKCalledOnce)
  199. {
  200. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), InitSDK(_)).Times(1);
  201. m_serverManager->InitializeGameLiftServerSDK();
  202. AZ_TEST_START_TRACE_SUPPRESSION;
  203. m_serverManager->InitializeGameLiftServerSDK();
  204. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  205. }
  206. TEST_F(GameLiftServerManagerTest, NotifyGameLiftProcessReady_SDKNotInitialized_FailToNotifyGameLift)
  207. {
  208. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ProcessReady(testing::_)).Times(0);
  209. AZ_TEST_START_TRACE_SUPPRESSION;
  210. EXPECT_FALSE(m_serverManager->NotifyGameLiftProcessReady());
  211. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  212. }
  213. TEST_F(GameLiftServerManagerTest, NotifyGameLiftProcessReady_SDKInitialized_ProcessReadyNotificationSent)
  214. {
  215. m_serverManager->InitializeGameLiftServerSDK();
  216. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ProcessReady(testing::_)).Times(1);
  217. EXPECT_TRUE(m_serverManager->NotifyGameLiftProcessReady());
  218. }
  219. TEST_F(GameLiftServerManagerTest, NotifyGameLiftProcessReady_ProcessReadyFails_TerminationNotificationSent)
  220. {
  221. m_serverManager->InitializeGameLiftServerSDK();
  222. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ProcessReady(testing::_))
  223. .Times(1)
  224. .WillOnce(testing::Return(Aws::GameLift::GenericOutcome()));
  225. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ProcessEnding()).Times(1);
  226. AZ_TEST_START_TRACE_SUPPRESSION;
  227. EXPECT_TRUE(m_serverManager->NotifyGameLiftProcessReady());
  228. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  229. }
  230. TEST_F(GameLiftServerManagerTest, OnProcessTerminate_OnDestroySessionBeginReturnsFalse_FailToNotifyGameLift)
  231. {
  232. m_serverManager->InitializeGameLiftServerSDK();
  233. m_serverManager->NotifyGameLiftProcessReady();
  234. if (!AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Get())
  235. {
  236. AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Register(m_serverManager.get());
  237. }
  238. SessionNotificationsHandlerMock handlerMock;
  239. EXPECT_CALL(handlerMock, OnDestroySessionBegin()).Times(1).WillOnce(testing::Return(false));
  240. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), GetTerminationTime()).Times(1);
  241. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ProcessEnding()).Times(0);
  242. EXPECT_CALL(handlerMock, OnDestroySessionEnd()).Times(0);
  243. AZ_TEST_START_TRACE_SUPPRESSION;
  244. m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_onProcessTerminateFunc();
  245. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  246. EXPECT_FALSE(AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Get());
  247. }
  248. TEST_F(GameLiftServerManagerTest, OnProcessTerminate_OnDestroySessionBeginReturnsTrue_TerminationNotificationSent)
  249. {
  250. m_serverManager->InitializeGameLiftServerSDK();
  251. m_serverManager->NotifyGameLiftProcessReady();
  252. if (!AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Get())
  253. {
  254. AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Register(m_serverManager.get());
  255. }
  256. SessionNotificationsHandlerMock handlerMock;
  257. EXPECT_CALL(handlerMock, OnDestroySessionBegin()).Times(1).WillOnce(testing::Return(true));
  258. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), GetTerminationTime()).Times(1);
  259. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ProcessEnding())
  260. .Times(1)
  261. .WillOnce(testing::Return(Aws::GameLift::GenericOutcome(nullptr)));
  262. EXPECT_CALL(handlerMock, OnDestroySessionEnd()).Times(1);
  263. m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_onProcessTerminateFunc();
  264. EXPECT_FALSE(AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Get());
  265. }
  266. TEST_F(GameLiftServerManagerTest, OnProcessTerminate_OnDestroySessionBeginReturnsTrue_TerminationNotificationSentButFail)
  267. {
  268. m_serverManager->InitializeGameLiftServerSDK();
  269. m_serverManager->NotifyGameLiftProcessReady();
  270. if (!AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Get())
  271. {
  272. AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Register(m_serverManager.get());
  273. }
  274. SessionNotificationsHandlerMock handlerMock;
  275. EXPECT_CALL(handlerMock, OnDestroySessionBegin()).Times(1).WillOnce(testing::Return(true));
  276. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), GetTerminationTime()).Times(1);
  277. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ProcessEnding())
  278. .Times(1)
  279. .WillOnce(testing::Return(Aws::GameLift::GenericOutcome()));
  280. EXPECT_CALL(handlerMock, OnDestroySessionEnd()).Times(0);
  281. AZ_TEST_START_TRACE_SUPPRESSION;
  282. m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_onProcessTerminateFunc();
  283. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  284. EXPECT_FALSE(AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Get());
  285. }
  286. TEST_F(GameLiftServerManagerTest, OnHealthCheck_OnSessionHealthCheckReturnsTrue_CallbackFunctionReturnsTrue)
  287. {
  288. m_serverManager->InitializeGameLiftServerSDK();
  289. m_serverManager->NotifyGameLiftProcessReady();
  290. SessionNotificationsHandlerMock handlerMock;
  291. EXPECT_CALL(handlerMock, OnSessionHealthCheck()).Times(1).WillOnce(testing::Return(true));
  292. EXPECT_TRUE(m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_healthCheckFunc());
  293. }
  294. TEST_F(GameLiftServerManagerTest, OnHealthCheck_OnSessionHealthCheckReturnsFalseAndTrue_CallbackFunctionReturnsFalse)
  295. {
  296. m_serverManager->InitializeGameLiftServerSDK();
  297. m_serverManager->NotifyGameLiftProcessReady();
  298. SessionNotificationsHandlerMock handlerMock1;
  299. EXPECT_CALL(handlerMock1, OnSessionHealthCheck()).Times(1).WillOnce(testing::Return(false));
  300. SessionNotificationsHandlerMock handlerMock2;
  301. EXPECT_CALL(handlerMock2, OnSessionHealthCheck()).Times(1).WillOnce(testing::Return(true));
  302. EXPECT_FALSE(m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_healthCheckFunc());
  303. }
  304. TEST_F(GameLiftServerManagerTest, OnHealthCheck_OnSessionHealthCheckReturnsFalse_CallbackFunctionReturnsFalse)
  305. {
  306. m_serverManager->InitializeGameLiftServerSDK();
  307. m_serverManager->NotifyGameLiftProcessReady();
  308. SessionNotificationsHandlerMock handlerMock;
  309. EXPECT_CALL(handlerMock, OnSessionHealthCheck()).Times(1).WillOnce(testing::Return(false));
  310. EXPECT_FALSE(m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_healthCheckFunc());
  311. }
  312. TEST_F(GameLiftServerManagerTest, OnStartGameSession_OnCreateSessionBeginReturnsFalse_TerminationNotificationSent)
  313. {
  314. m_serverManager->InitializeGameLiftServerSDK();
  315. m_serverManager->NotifyGameLiftProcessReady();
  316. SessionNotificationsHandlerMock handlerMock;
  317. EXPECT_CALL(handlerMock, OnCreateSessionBegin(testing::_)).Times(1).WillOnce(testing::Return(false));
  318. EXPECT_CALL(handlerMock, OnCreateSessionEnd()).Times(0);
  319. EXPECT_CALL(handlerMock, OnDestroySessionBegin()).Times(1).WillOnce(testing::Return(true));
  320. EXPECT_CALL(handlerMock, OnDestroySessionEnd()).Times(1);
  321. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ProcessEnding()).Times(1);
  322. AZ_TEST_START_TRACE_SUPPRESSION;
  323. m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_onStartGameSessionFunc(Aws::GameLift::Server::Model::GameSession());
  324. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  325. EXPECT_FALSE(AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Get());
  326. }
  327. TEST_F(GameLiftServerManagerTest, OnStartGameSession_ActivateGameSessionSucceeds_RegisterAsHandler)
  328. {
  329. m_serverManager->InitializeGameLiftServerSDK();
  330. m_serverManager->NotifyGameLiftProcessReady();
  331. SessionNotificationsHandlerMock handlerMock;
  332. EXPECT_CALL(handlerMock, OnCreateSessionBegin(testing::_)).Times(1).WillOnce(testing::Return(true));
  333. EXPECT_CALL(handlerMock, OnCreateSessionEnd()).Times(1);
  334. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ActivateGameSession())
  335. .Times(1)
  336. .WillOnce(testing::Return(Aws::GameLift::GenericOutcome(nullptr)));
  337. Aws::GameLift::Server::Model::GameSession testSession;
  338. Aws::GameLift::Server::Model::GameProperty testProperty;
  339. testProperty.SetKey("testKey");
  340. testProperty.SetValue("testValue");
  341. testSession.AddGameProperty(testProperty);
  342. m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_onStartGameSessionFunc(testSession);
  343. EXPECT_TRUE(AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Get());
  344. // clean up
  345. EXPECT_CALL(handlerMock, OnDestroySessionBegin()).Times(1).WillOnce(testing::Return(true));
  346. EXPECT_CALL(handlerMock, OnDestroySessionEnd()).Times(1);
  347. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ProcessEnding()).Times(1);
  348. m_serverManager->HandleDestroySession();
  349. EXPECT_FALSE(AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Get());
  350. }
  351. TEST_F(GameLiftServerManagerTest, OnStartGameSession_ActivateGameSessionFails_TerminationNotificationSent)
  352. {
  353. m_serverManager->InitializeGameLiftServerSDK();
  354. m_serverManager->NotifyGameLiftProcessReady();
  355. SessionNotificationsHandlerMock handlerMock;
  356. EXPECT_CALL(handlerMock, OnCreateSessionBegin(testing::_)).Times(1).WillOnce(testing::Return(true));
  357. EXPECT_CALL(handlerMock, OnCreateSessionEnd()).Times(0);
  358. EXPECT_CALL(handlerMock, OnDestroySessionBegin()).Times(1).WillOnce(testing::Return(true));
  359. EXPECT_CALL(handlerMock, OnDestroySessionEnd()).Times(1);
  360. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ActivateGameSession())
  361. .Times(1)
  362. .WillOnce(testing::Return(Aws::GameLift::GenericOutcome()));
  363. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), ProcessEnding()).Times(1);
  364. AZ_TEST_START_TRACE_SUPPRESSION;
  365. m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_onStartGameSessionFunc(Aws::GameLift::Server::Model::GameSession());
  366. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  367. EXPECT_FALSE(AZ::Interface<Multiplayer::ISessionHandlingProviderRequests>::Get());
  368. }
  369. TEST_F(GameLiftServerManagerTest, OnUpdateGameSession_TriggerWithUnknownReason_OnUpdateSessionGetCalledOnce)
  370. {
  371. m_serverManager->InitializeGameLiftServerSDK();
  372. m_serverManager->NotifyGameLiftProcessReady();
  373. SessionNotificationsHandlerMock handlerMock;
  374. EXPECT_CALL(handlerMock, OnUpdateSessionBegin(testing::_, testing::_)).Times(1);
  375. EXPECT_CALL(handlerMock, OnUpdateSessionEnd()).Times(1);
  376. m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_onUpdateGameSessionFunc(
  377. Aws::GameLift::Server::Model::UpdateGameSession(
  378. Aws::GameLift::Server::Model::GameSession(),
  379. Aws::GameLift::Server::Model::UpdateReason::UNKNOWN,
  380. "testticket"));
  381. }
  382. TEST_F(GameLiftServerManagerTest, OnUpdateGameSession_TriggerWithEmptyMatchmakingData_OnUpdateSessionGetCalledOnce)
  383. {
  384. m_serverManager->InitializeGameLiftServerSDK();
  385. m_serverManager->NotifyGameLiftProcessReady();
  386. SessionNotificationsHandlerMock handlerMock;
  387. EXPECT_CALL(handlerMock, OnUpdateSessionBegin(testing::_, testing::_)).Times(1);
  388. EXPECT_CALL(handlerMock, OnUpdateSessionEnd()).Times(1);
  389. m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_onUpdateGameSessionFunc(
  390. Aws::GameLift::Server::Model::UpdateGameSession(
  391. Aws::GameLift::Server::Model::GameSession(),
  392. Aws::GameLift::Server::Model::UpdateReason::MATCHMAKING_DATA_UPDATED,
  393. "testticket"));
  394. }
  395. TEST_F(GameLiftServerManagerTest, OnUpdateGameSession_TriggerWithValidMatchmakingData_OnUpdateSessionGetCalledOnce)
  396. {
  397. m_serverManager->InitializeGameLiftServerSDK();
  398. m_serverManager->NotifyGameLiftProcessReady();
  399. SessionNotificationsHandlerMock handlerMock;
  400. EXPECT_CALL(handlerMock, OnUpdateSessionBegin(testing::_, testing::_)).Times(1);
  401. EXPECT_CALL(handlerMock, OnUpdateSessionEnd()).Times(1);
  402. Aws::GameLift::Server::Model::GameSession gameSession;
  403. gameSession.SetMatchmakerData(TEST_SERVER_MATCHMAKING_DATA);
  404. m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_onUpdateGameSessionFunc(
  405. Aws::GameLift::Server::Model::UpdateGameSession(
  406. gameSession, Aws::GameLift::Server::Model::UpdateReason::MATCHMAKING_DATA_UPDATED, "testticket"));
  407. }
  408. TEST_F(GameLiftServerManagerTest, OnUpdateGameSession_TriggerWithInvalidMatchmakingData_OnUpdateSessionGetCalledOnce)
  409. {
  410. m_serverManager->InitializeGameLiftServerSDK();
  411. m_serverManager->NotifyGameLiftProcessReady();
  412. SessionNotificationsHandlerMock handlerMock;
  413. EXPECT_CALL(handlerMock, OnUpdateSessionBegin(testing::_, testing::_)).Times(1);
  414. EXPECT_CALL(handlerMock, OnUpdateSessionEnd()).Times(1);
  415. Aws::GameLift::Server::Model::GameSession gameSession;
  416. gameSession.SetMatchmakerData("{invalid}");
  417. AZ_TEST_START_TRACE_SUPPRESSION;
  418. m_serverManager->m_gameLiftServerSDKWrapperMockPtr->m_onUpdateGameSessionFunc(
  419. Aws::GameLift::Server::Model::UpdateGameSession(
  420. gameSession, Aws::GameLift::Server::Model::UpdateReason::MATCHMAKING_DATA_UPDATED, "testticket"));
  421. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  422. }
  423. TEST_F(GameLiftServerManagerTest, ValidatePlayerJoinSession_CallWithInvalidConnectionConfig_GetFalseResultAndExpectedErrorLog)
  424. {
  425. AZ_TEST_START_TRACE_SUPPRESSION;
  426. auto result = m_serverManager->ValidatePlayerJoinSession(Multiplayer::PlayerConnectionConfig());
  427. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  428. EXPECT_FALSE(result);
  429. }
  430. TEST_F(GameLiftServerManagerTest, ValidatePlayerJoinSession_CallWithDuplicatedConnectionId_GetFalseResultAndExpectedErrorLog)
  431. {
  432. Multiplayer::PlayerConnectionConfig connectionConfig1;
  433. connectionConfig1.m_playerConnectionId = 123;
  434. connectionConfig1.m_playerSessionId = "dummyPlayerSessionId1";
  435. GenericOutcome successOutcome(nullptr);
  436. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), AcceptPlayerSession(testing::_))
  437. .Times(1)
  438. .WillOnce(Return(successOutcome));
  439. m_serverManager->ValidatePlayerJoinSession(connectionConfig1);
  440. Multiplayer::PlayerConnectionConfig connectionConfig2;
  441. connectionConfig2.m_playerConnectionId = 123;
  442. connectionConfig2.m_playerSessionId = "dummyPlayerSessionId2";
  443. AZ_TEST_START_TRACE_SUPPRESSION;
  444. auto result = m_serverManager->ValidatePlayerJoinSession(connectionConfig2);
  445. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  446. EXPECT_FALSE(result);
  447. }
  448. TEST_F(GameLiftServerManagerTest, ValidatePlayerJoinSession_CallWithValidConnectionConfigButErrorOutcome_GetFalseResultAndExpectedErrorLog)
  449. {
  450. Multiplayer::PlayerConnectionConfig connectionConfig;
  451. connectionConfig.m_playerConnectionId = 123;
  452. connectionConfig.m_playerSessionId = "dummyPlayerSessionId1";
  453. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), AcceptPlayerSession(testing::_)).Times(1);
  454. AZ_TEST_START_TRACE_SUPPRESSION;
  455. auto result = m_serverManager->ValidatePlayerJoinSession(connectionConfig);
  456. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  457. EXPECT_FALSE(result);
  458. }
  459. TEST_F(GameLiftServerManagerTest, ValidatePlayerJoinSession_CallWithValidConnectionConfigAndSuccessOutcome_GetTrueResult)
  460. {
  461. Multiplayer::PlayerConnectionConfig connectionConfig;
  462. connectionConfig.m_playerConnectionId = 123;
  463. connectionConfig.m_playerSessionId = "dummyPlayerSessionId1";
  464. GenericOutcome successOutcome(nullptr);
  465. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), AcceptPlayerSession(testing::_))
  466. .Times(1)
  467. .WillOnce(Return(successOutcome));
  468. auto result = m_serverManager->ValidatePlayerJoinSession(connectionConfig);
  469. EXPECT_TRUE(result);
  470. }
  471. TEST_F(GameLiftServerManagerTest, ValidatePlayerJoinSession_CallWithFirstErrorSecondSuccess_GetFirstFalseSecondTrueResult)
  472. {
  473. Multiplayer::PlayerConnectionConfig connectionConfig1;
  474. connectionConfig1.m_playerConnectionId = 123;
  475. connectionConfig1.m_playerSessionId = "dummyPlayerSessionId1";
  476. GenericOutcome successOutcome(nullptr);
  477. Aws::GameLift::GameLiftError error;
  478. GenericOutcome errorOutcome(error);
  479. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), AcceptPlayerSession(testing::_))
  480. .Times(2)
  481. .WillOnce(Return(errorOutcome))
  482. .WillOnce(Return(successOutcome));
  483. AZ_TEST_START_TRACE_SUPPRESSION;
  484. auto result = m_serverManager->ValidatePlayerJoinSession(connectionConfig1);
  485. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  486. EXPECT_FALSE(result);
  487. Multiplayer::PlayerConnectionConfig connectionConfig2;
  488. connectionConfig2.m_playerConnectionId = 123;
  489. connectionConfig2.m_playerSessionId = "dummyPlayerSessionId2";
  490. result = m_serverManager->ValidatePlayerJoinSession(connectionConfig2);
  491. EXPECT_TRUE(result);
  492. }
  493. TEST_F(GameLiftServerManagerTest, ValidatePlayerJoinSession_CallWithMultithread_GetFirstTrueAndRestFalse)
  494. {
  495. int testThreadNumber = 5;
  496. GenericOutcome successOutcome(nullptr);
  497. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), AcceptPlayerSession(testing::_))
  498. .Times(1)
  499. .WillOnce(Return(successOutcome));
  500. AZStd::vector<AZStd::thread> testThreadPool;
  501. AZStd::atomic<int> trueCount = 0;
  502. for (int index = 0; index < testThreadNumber; index++)
  503. {
  504. testThreadPool.emplace_back(AZStd::thread([&]() {
  505. Multiplayer::PlayerConnectionConfig connectionConfig;
  506. connectionConfig.m_playerConnectionId = 123;
  507. connectionConfig.m_playerSessionId = "dummyPlayerSessionId";
  508. auto result = m_serverManager->ValidatePlayerJoinSession(connectionConfig);
  509. if (result)
  510. {
  511. trueCount++;
  512. }
  513. }));
  514. }
  515. for (auto& testThread : testThreadPool)
  516. {
  517. testThread.join();
  518. }
  519. EXPECT_TRUE(trueCount == 1);
  520. }
  521. TEST_F(GameLiftServerManagerTest, HandlePlayerLeaveSession_CallWithInvalidConnectionConfig_GetExpectedErrorLog)
  522. {
  523. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), RemovePlayerSession(testing::_)).Times(0);
  524. AZ_TEST_START_TRACE_SUPPRESSION;
  525. m_serverManager->HandlePlayerLeaveSession(Multiplayer::PlayerConnectionConfig());
  526. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  527. }
  528. TEST_F(GameLiftServerManagerTest, HandlePlayerLeaveSession_CallWithNonExistentPlayerConnectionId_GetExpectedErrorLog)
  529. {
  530. Multiplayer::PlayerConnectionConfig connectionConfig;
  531. connectionConfig.m_playerConnectionId = 123;
  532. connectionConfig.m_playerSessionId = "dummyPlayerSessionId";
  533. auto result = m_serverManager->AddConnectedTestPlayer(connectionConfig);
  534. EXPECT_TRUE(result);
  535. Multiplayer::PlayerConnectionConfig connectionConfig1;
  536. connectionConfig1.m_playerConnectionId = 456;
  537. connectionConfig1.m_playerSessionId = "dummyPlayerSessionId";
  538. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), RemovePlayerSession(testing::_)).Times(0);
  539. AZ_TEST_START_TRACE_SUPPRESSION;
  540. m_serverManager->HandlePlayerLeaveSession(connectionConfig1);
  541. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  542. }
  543. TEST_F(GameLiftServerManagerTest, HandlePlayerLeaveSession_CallWithValidConnectionConfigButErrorOutcome_GetExpectedErrorLog)
  544. {
  545. Multiplayer::PlayerConnectionConfig connectionConfig;
  546. connectionConfig.m_playerConnectionId = 123;
  547. connectionConfig.m_playerSessionId = "dummyPlayerSessionId";
  548. auto result = m_serverManager->AddConnectedTestPlayer(connectionConfig);
  549. EXPECT_TRUE(result);
  550. Aws::GameLift::GameLiftError error;
  551. GenericOutcome errorOutcome(error);
  552. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), RemovePlayerSession(testing::_))
  553. .Times(1)
  554. .WillOnce(Return(errorOutcome));
  555. AZ_TEST_START_TRACE_SUPPRESSION;
  556. m_serverManager->HandlePlayerLeaveSession(connectionConfig);
  557. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  558. }
  559. TEST_F(GameLiftServerManagerTest, HandlePlayerLeaveSession_CallWithValidConnectionConfigAndSuccessOutcome_RemovePlayerSessionNotificationSent)
  560. {
  561. Multiplayer::PlayerConnectionConfig connectionConfig;
  562. connectionConfig.m_playerConnectionId = 123;
  563. connectionConfig.m_playerSessionId = "dummyPlayerSessionId";
  564. auto result = m_serverManager->AddConnectedTestPlayer(connectionConfig);
  565. EXPECT_TRUE(result);
  566. GenericOutcome successOutcome(nullptr);
  567. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), RemovePlayerSession(testing::_))
  568. .Times(1)
  569. .WillOnce(Return(successOutcome));
  570. m_serverManager->HandlePlayerLeaveSession(connectionConfig);
  571. }
  572. TEST_F(GameLiftServerManagerTest, HandlePlayerLeaveSession_CallWithMultithread_OnlyOneNotificationIsSent)
  573. {
  574. Multiplayer::PlayerConnectionConfig connectionConfig;
  575. connectionConfig.m_playerConnectionId = 123;
  576. connectionConfig.m_playerSessionId = "dummyPlayerSessionId";
  577. auto result = m_serverManager->AddConnectedTestPlayer(connectionConfig);
  578. EXPECT_TRUE(result);
  579. int testThreadNumber = 5;
  580. GenericOutcome successOutcome(nullptr);
  581. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), RemovePlayerSession(testing::_))
  582. .Times(1)
  583. .WillOnce(Return(successOutcome));
  584. AZStd::vector<AZStd::thread> testThreadPool;
  585. AZ_TEST_START_TRACE_SUPPRESSION;
  586. for (int index = 0; index < testThreadNumber; index++)
  587. {
  588. testThreadPool.emplace_back(AZStd::thread(
  589. [&]()
  590. {
  591. m_serverManager->HandlePlayerLeaveSession(connectionConfig);
  592. }));
  593. }
  594. for (auto& testThread : testThreadPool)
  595. {
  596. testThread.join();
  597. }
  598. AZ_TEST_STOP_TRACE_SUPPRESSION(testThreadNumber - 1); // The player is only disconnected once.
  599. }
  600. TEST_F(GameLiftServerManagerTest, UpdateGameSessionData_CallWithInvalidMatchmakingData_GetExpectedError)
  601. {
  602. AZ_TEST_START_TRACE_SUPPRESSION;
  603. m_serverManager->SetupTestMatchmakingData("{invalid}");
  604. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  605. }
  606. TEST_F(GameLiftServerManagerTest, GetActiveServerMatchBackfillPlayers_CallWithInvalidMatchmakingData_GetEmptyResult)
  607. {
  608. AZ_TEST_START_TRACE_SUPPRESSION;
  609. m_serverManager->SetupTestMatchmakingData("{invalid}");
  610. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  611. auto actualResult = m_serverManager->GetTestServerMatchBackfillPlayers();
  612. EXPECT_TRUE(actualResult.empty());
  613. }
  614. TEST_F(GameLiftServerManagerTest, GetActiveServerMatchBackfillPlayers_CallWithEmptyMatchmakingData_GetEmptyResult)
  615. {
  616. m_serverManager->SetupTestMatchmakingData("");
  617. auto actualResult = m_serverManager->GetTestServerMatchBackfillPlayers();
  618. EXPECT_TRUE(actualResult.empty());
  619. }
  620. TEST_F(GameLiftServerManagerTest, GetActiveServerMatchBackfillPlayers_CallButDescribePlayerError_GetEmptyResult)
  621. {
  622. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  623. Aws::GameLift::GameLiftError error;
  624. Aws::GameLift::DescribePlayerSessionsOutcome errorOutcome(error);
  625. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), DescribePlayerSessions(testing::_))
  626. .Times(1)
  627. .WillOnce(Return(errorOutcome));
  628. AZ_TEST_START_TRACE_SUPPRESSION;
  629. auto actualResult = m_serverManager->GetTestServerMatchBackfillPlayers();
  630. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  631. EXPECT_TRUE(actualResult.empty());
  632. }
  633. TEST_F(GameLiftServerManagerTest, GetActiveServerMatchBackfillPlayers_CallButNoActivePlayer_GetEmptyResult)
  634. {
  635. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  636. Aws::GameLift::Server::Model::DescribePlayerSessionsResult result;
  637. Aws::GameLift::DescribePlayerSessionsOutcome successOutcome(result);
  638. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), DescribePlayerSessions(testing::_))
  639. .Times(1)
  640. .WillOnce(Return(successOutcome));
  641. auto actualResult = m_serverManager->GetTestServerMatchBackfillPlayers();
  642. EXPECT_TRUE(actualResult.empty());
  643. }
  644. TEST_F(GameLiftServerManagerTest, GetActiveServerMatchBackfillPlayers_CallWithValidMatchmakingData_GetExpectedResult)
  645. {
  646. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  647. Aws::GameLift::Server::Model::PlayerSession playerSession;
  648. playerSession.SetPlayerId("testplayer");
  649. Aws::GameLift::Server::Model::DescribePlayerSessionsResult result;
  650. result.AddPlayerSession(playerSession);
  651. Aws::GameLift::DescribePlayerSessionsOutcome successOutcome(result);
  652. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), DescribePlayerSessions(testing::_))
  653. .Times(1)
  654. .WillOnce(Return(successOutcome));
  655. auto actualResult = m_serverManager->GetTestServerMatchBackfillPlayers();
  656. EXPECT_TRUE(actualResult.size() == 1);
  657. EXPECT_TRUE(actualResult[0].m_team == "testteam");
  658. EXPECT_TRUE(actualResult[0].m_playerId == "testplayer");
  659. EXPECT_TRUE(actualResult[0].m_playerAttributes.size() == 4);
  660. }
  661. TEST_F(GameLiftServerManagerTest, GetExternalSessionCertificate_CallWithTLSDisabled_GetEmptyResult)
  662. {
  663. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), GetComputeCertificate())
  664. .Times(1)
  665. .WillOnce(Return(Aws::GameLift::GetComputeCertificateOutcome()));
  666. AZ_TEST_START_TRACE_SUPPRESSION;
  667. auto actualResult = m_serverManager->GetExternalSessionCertificate();
  668. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  669. EXPECT_STREQ(actualResult.c_str(), "");
  670. }
  671. TEST_F(GameLiftServerManagerTest, GetExternalSessionCertificate_CallWithTLSEnabled_GetExpectedResult)
  672. {
  673. AZStd::string expectedResult = "gameliftunittestcertificate.pem";
  674. Aws::GameLift::Server::Model::GetComputeCertificateResult certificateResult;
  675. certificateResult.SetCertificatePath(expectedResult.c_str());
  676. Aws::GameLift::GetComputeCertificateOutcome certificateOutcome(certificateResult);
  677. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), GetComputeCertificate())
  678. .Times(1)
  679. .WillOnce(Return(certificateOutcome));
  680. auto actualResult = m_serverManager->GetExternalSessionCertificate();
  681. EXPECT_STREQ(actualResult.c_str(), expectedResult.c_str());
  682. }
  683. TEST_F(GameLiftServerManagerTest, GetInternalSessionCertificate_Call_GetEmptyResult)
  684. {
  685. auto actualResult = m_serverManager->GetInternalSessionCertificate();
  686. EXPECT_STREQ(actualResult.c_str(), "");
  687. }
  688. TEST_F(GameLiftServerManagerTest, GetActiveServerMatchBackfillPlayers_CallWithMultiDescribePlayerButError_GetEmptyResult)
  689. {
  690. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA, 50);
  691. Aws::GameLift::GameLiftError error;
  692. Aws::GameLift::DescribePlayerSessionsOutcome errorOutcome(error);
  693. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), DescribePlayerSessions(testing::_))
  694. .Times(1)
  695. .WillOnce(Return(errorOutcome));
  696. AZ_TEST_START_TRACE_SUPPRESSION;
  697. auto actualResult = m_serverManager->GetTestServerMatchBackfillPlayers();
  698. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  699. EXPECT_TRUE(actualResult.empty());
  700. }
  701. TEST_F(GameLiftServerManagerTest, GetActiveServerMatchBackfillPlayers_CallWithMultiDescribePlayer_GetExpectedResult)
  702. {
  703. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA, 50);
  704. Aws::GameLift::Server::Model::PlayerSession playerSession1;
  705. playerSession1.SetPlayerId("testplayer");
  706. Aws::GameLift::Server::Model::DescribePlayerSessionsResult result1;
  707. result1.AddPlayerSession(playerSession1);
  708. result1.SetNextToken("testtoken");
  709. Aws::GameLift::DescribePlayerSessionsOutcome successOutcome1(result1);
  710. Aws::GameLift::Server::Model::PlayerSession playerSession2;
  711. playerSession2.SetPlayerId("playernotinmatch");
  712. Aws::GameLift::Server::Model::DescribePlayerSessionsResult result2;
  713. result2.AddPlayerSession(playerSession2);
  714. Aws::GameLift::DescribePlayerSessionsOutcome successOutcome2(result2);
  715. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), DescribePlayerSessions(testing::_))
  716. .WillOnce(Return(successOutcome1))
  717. .WillOnce(Return(successOutcome2));
  718. auto actualResult = m_serverManager->GetTestServerMatchBackfillPlayers();
  719. EXPECT_TRUE(actualResult.size() == 1);
  720. EXPECT_TRUE(actualResult[0].m_team == "testteam");
  721. EXPECT_TRUE(actualResult[0].m_playerId == "testplayer");
  722. EXPECT_TRUE(actualResult[0].m_playerAttributes.size() == 4);
  723. }
  724. TEST_F(GameLiftServerManagerTest, StartMatchBackfill_SDKNotInitialized_GetExpectedError)
  725. {
  726. AZ_TEST_START_TRACE_SUPPRESSION;
  727. auto actualResult = m_serverManager->StartMatchBackfill("testticket", {});
  728. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  729. EXPECT_FALSE(actualResult);
  730. }
  731. TEST_F(GameLiftServerManagerTest, StartMatchBackfill_CallWithEmptyMatchmakingData_GetExpectedError)
  732. {
  733. m_serverManager->InitializeGameLiftServerSDK();
  734. m_serverManager->SetupTestMatchmakingData("");
  735. AZ_TEST_START_TRACE_SUPPRESSION;
  736. auto actualResult = m_serverManager->StartMatchBackfill("testticket", {});
  737. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  738. EXPECT_FALSE(actualResult);
  739. }
  740. TEST_F(GameLiftServerManagerTest, StartMatchBackfill_CallWithInvalidPlayerAttribute_GetExpectedError)
  741. {
  742. m_serverManager->InitializeGameLiftServerSDK();
  743. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  744. AWSGameLiftPlayer testPlayer = GetTestGameLiftPlayer();
  745. testPlayer.m_playerAttributes.clear();
  746. testPlayer.m_playerAttributes.emplace("invalidattribute", "{invalid}");
  747. AZ_TEST_START_TRACE_SUPPRESSION;
  748. auto actualResult = m_serverManager->StartMatchBackfill("testticket", { testPlayer });
  749. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  750. EXPECT_FALSE(actualResult);
  751. }
  752. TEST_F(GameLiftServerManagerTest, StartMatchBackfill_CallWithWrongPlayerAttributeType_GetExpectedError)
  753. {
  754. m_serverManager->InitializeGameLiftServerSDK();
  755. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  756. AWSGameLiftPlayer testPlayer = GetTestGameLiftPlayer();
  757. testPlayer.m_playerAttributes.clear();
  758. testPlayer.m_playerAttributes.emplace("invalidattribute", "{\"SDM\": [\"test1\"]}");
  759. AZ_TEST_START_TRACE_SUPPRESSION;
  760. auto actualResult = m_serverManager->StartMatchBackfill("testticket", { testPlayer });
  761. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  762. EXPECT_FALSE(actualResult);
  763. }
  764. TEST_F(GameLiftServerManagerTest, StartMatchBackfill_CallWithUnexpectedPlayerAttributeType_GetExpectedError)
  765. {
  766. m_serverManager->InitializeGameLiftServerSDK();
  767. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  768. AWSGameLiftPlayer testPlayer = GetTestGameLiftPlayer();
  769. testPlayer.m_playerAttributes.clear();
  770. testPlayer.m_playerAttributes.emplace("invalidattribute", "{\"UNEXPECTED\": [\"test1\"]}");
  771. AZ_TEST_START_TRACE_SUPPRESSION;
  772. auto actualResult = m_serverManager->StartMatchBackfill("testticket", { testPlayer });
  773. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  774. EXPECT_FALSE(actualResult);
  775. }
  776. TEST_F(GameLiftServerManagerTest, StartMatchBackfill_CallWithWrongSLPlayerAttributeValue_GetExpectedError)
  777. {
  778. m_serverManager->InitializeGameLiftServerSDK();
  779. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  780. AWSGameLiftPlayer testPlayer = GetTestGameLiftPlayer();
  781. testPlayer.m_playerAttributes.clear();
  782. testPlayer.m_playerAttributes.emplace("invalidattribute", "{\"SL\": [10.0]}");
  783. AZ_TEST_START_TRACE_SUPPRESSION;
  784. auto actualResult = m_serverManager->StartMatchBackfill("testticket", { testPlayer });
  785. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  786. EXPECT_FALSE(actualResult);
  787. }
  788. TEST_F(GameLiftServerManagerTest, StartMatchBackfill_CallWithWrongSDMPlayerAttributeValue_GetExpectedError)
  789. {
  790. m_serverManager->InitializeGameLiftServerSDK();
  791. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  792. AWSGameLiftPlayer testPlayer = GetTestGameLiftPlayer();
  793. testPlayer.m_playerAttributes.clear();
  794. testPlayer.m_playerAttributes.emplace("invalidattribute", "{\"SDM\": {10.0: \"test1\"}}");
  795. AZ_TEST_START_TRACE_SUPPRESSION;
  796. auto actualResult = m_serverManager->StartMatchBackfill("testticket", { testPlayer });
  797. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  798. EXPECT_FALSE(actualResult);
  799. }
  800. TEST_F(GameLiftServerManagerTest, StartMatchBackfill_CallWithValidPlayersData_GetExpectedResult)
  801. {
  802. m_serverManager->InitializeGameLiftServerSDK();
  803. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  804. Aws::GameLift::Server::Model::StartMatchBackfillResult backfillResult;
  805. Aws::GameLift::StartMatchBackfillOutcome backfillSuccessOutcome(backfillResult);
  806. Aws::GameLift::Server::Model::StartMatchBackfillRequest request = GetTestStartMatchBackfillRequest();
  807. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), StartMatchBackfill(StartMatchBackfillRequestMatcher(request)))
  808. .Times(1)
  809. .WillOnce(Return(backfillSuccessOutcome));
  810. AWSGameLiftPlayer testPlayer = GetTestGameLiftPlayer();
  811. auto actualResult = m_serverManager->StartMatchBackfill("testticket", {testPlayer});
  812. EXPECT_TRUE(actualResult);
  813. }
  814. TEST_F(GameLiftServerManagerTest, StartMatchBackfill_CallWithoutGivingPlayersData_GetExpectedResult)
  815. {
  816. m_serverManager->InitializeGameLiftServerSDK();
  817. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  818. Aws::GameLift::Server::Model::PlayerSession playerSession;
  819. playerSession.SetPlayerId("testplayer");
  820. Aws::GameLift::Server::Model::DescribePlayerSessionsResult result;
  821. result.AddPlayerSession(playerSession);
  822. Aws::GameLift::DescribePlayerSessionsOutcome successOutcome(result);
  823. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), DescribePlayerSessions(testing::_))
  824. .Times(1)
  825. .WillOnce(Return(successOutcome));
  826. Aws::GameLift::Server::Model::StartMatchBackfillResult backfillResult;
  827. Aws::GameLift::StartMatchBackfillOutcome backfillSuccessOutcome(backfillResult);
  828. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), StartMatchBackfill(testing::_))
  829. .Times(1)
  830. .WillOnce(Return(backfillSuccessOutcome));
  831. auto actualResult = m_serverManager->StartMatchBackfill("testticket", {});
  832. EXPECT_TRUE(actualResult);
  833. }
  834. TEST_F(GameLiftServerManagerTest, StartMatchBackfill_CallButStartBackfillFail_GetExpectedError)
  835. {
  836. m_serverManager->InitializeGameLiftServerSDK();
  837. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  838. Aws::GameLift::Server::Model::PlayerSession playerSession;
  839. playerSession.SetPlayerId("testplayer");
  840. Aws::GameLift::Server::Model::DescribePlayerSessionsResult result;
  841. result.AddPlayerSession(playerSession);
  842. Aws::GameLift::DescribePlayerSessionsOutcome successOutcome(result);
  843. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), DescribePlayerSessions(testing::_))
  844. .Times(1)
  845. .WillOnce(Return(successOutcome));
  846. Aws::GameLift::GameLiftError error;
  847. Aws::GameLift::StartMatchBackfillOutcome errorOutcome(error);
  848. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), StartMatchBackfill(testing::_))
  849. .Times(1)
  850. .WillOnce(Return(errorOutcome));
  851. AZ_TEST_START_TRACE_SUPPRESSION;
  852. auto actualResult = m_serverManager->StartMatchBackfill("testticket", {});
  853. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  854. EXPECT_FALSE(actualResult);
  855. }
  856. TEST_F(GameLiftServerManagerTest, StopMatchBackfill_SDKNotInitialized_GetExpectedError)
  857. {
  858. AZ_TEST_START_TRACE_SUPPRESSION;
  859. auto actualResult = m_serverManager->StopMatchBackfill("testticket");
  860. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  861. EXPECT_FALSE(actualResult);
  862. }
  863. TEST_F(GameLiftServerManagerTest, StopMatchBackfill_CallWithEmptyMatchmakingData_GetExpectedError)
  864. {
  865. m_serverManager->InitializeGameLiftServerSDK();
  866. m_serverManager->SetupTestMatchmakingData("");
  867. AZ_TEST_START_TRACE_SUPPRESSION;
  868. auto actualResult = m_serverManager->StopMatchBackfill("testticket");
  869. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  870. EXPECT_FALSE(actualResult);
  871. }
  872. TEST_F(GameLiftServerManagerTest, StopMatchBackfill_CallAndSuccessOutcome_GetExpectedResult)
  873. {
  874. m_serverManager->InitializeGameLiftServerSDK();
  875. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  876. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), StopMatchBackfill(testing::_))
  877. .Times(1)
  878. .WillOnce(Return(Aws::GameLift::GenericOutcome(nullptr)));
  879. auto actualResult = m_serverManager->StopMatchBackfill("testticket");
  880. EXPECT_TRUE(actualResult);
  881. }
  882. TEST_F(GameLiftServerManagerTest, StopMatchBackfill_CallButErrorOutcome_GetExpectedError)
  883. {
  884. m_serverManager->InitializeGameLiftServerSDK();
  885. m_serverManager->SetupTestMatchmakingData(TEST_SERVER_MATCHMAKING_DATA);
  886. EXPECT_CALL(*(m_serverManager->m_gameLiftServerSDKWrapperMockPtr), StopMatchBackfill(testing::_))
  887. .Times(1)
  888. .WillOnce(Return(Aws::GameLift::GenericOutcome()));
  889. AZ_TEST_START_TRACE_SUPPRESSION;
  890. auto actualResult = m_serverManager->StopMatchBackfill("testticket");
  891. AZ_TEST_STOP_TRACE_SUPPRESSION(1);
  892. EXPECT_FALSE(actualResult);
  893. }
  894. } // namespace UnitTest