Improve ticket tracker workflow for testing (#4610)
* Improve ticket tracker workflow for testing Signed-off-by: onecent1101 <liug@amazon.com>
This commit is contained in:
+13
-3
@@ -47,6 +47,15 @@ namespace AWSGameLift
|
||||
AZ_TracePrintf(AWSGameLiftClientLocalTicketTrackerName, "Matchmaking ticket tracker is running.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure thread and wait event are both in clean state before starting new one
|
||||
m_waitEvent.release();
|
||||
if (m_trackerThread.joinable())
|
||||
{
|
||||
m_trackerThread.join();
|
||||
}
|
||||
m_waitEvent.acquire();
|
||||
|
||||
m_status = TicketTrackerStatus::Running;
|
||||
m_trackerThread = AZStd::thread(AZStd::bind(
|
||||
&AWSGameLiftClientLocalTicketTracker::ProcessPolling, this, ticketId, playerId));
|
||||
@@ -56,6 +65,7 @@ namespace AWSGameLift
|
||||
{
|
||||
AZStd::lock_guard<AZStd::mutex> lock(m_trackerMutex);
|
||||
m_status = TicketTrackerStatus::Idle;
|
||||
m_waitEvent.release();
|
||||
if (m_trackerThread.joinable())
|
||||
{
|
||||
m_trackerThread.join();
|
||||
@@ -81,19 +91,19 @@ namespace AWSGameLift
|
||||
auto ticket = describeMatchmakingOutcome.GetResult().GetTicketList().front();
|
||||
if (ticket.GetStatus() == Aws::GameLift::Model::MatchmakingConfigurationStatus::COMPLETED)
|
||||
{
|
||||
m_status = TicketTrackerStatus::Idle;
|
||||
AZ_TracePrintf(AWSGameLiftClientLocalTicketTrackerName,
|
||||
"Matchmaking ticket %s is complete.", ticket.GetTicketId().c_str());
|
||||
RequestPlayerJoinMatch(ticket, playerId);
|
||||
m_status = TicketTrackerStatus::Idle;
|
||||
return;
|
||||
}
|
||||
else if (ticket.GetStatus() == Aws::GameLift::Model::MatchmakingConfigurationStatus::TIMED_OUT ||
|
||||
ticket.GetStatus() == Aws::GameLift::Model::MatchmakingConfigurationStatus::FAILED ||
|
||||
ticket.GetStatus() == Aws::GameLift::Model::MatchmakingConfigurationStatus::CANCELLED)
|
||||
{
|
||||
m_status = TicketTrackerStatus::Idle;
|
||||
AZ_Error(AWSGameLiftClientLocalTicketTrackerName, false, "Matchmaking ticket %s is not complete, %s",
|
||||
ticket.GetTicketId().c_str(), ticket.GetStatusReason().c_str());
|
||||
m_status = TicketTrackerStatus::Idle;
|
||||
return;
|
||||
}
|
||||
else if (ticket.GetStatus() == Aws::GameLift::Model::MatchmakingConfigurationStatus::REQUIRES_ACCEPTANCE)
|
||||
@@ -122,7 +132,7 @@ namespace AWSGameLift
|
||||
{
|
||||
AZ_Error(AWSGameLiftClientLocalTicketTrackerName, false, AWSGameLiftClientMissingErrorMessage);
|
||||
}
|
||||
AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(m_pollingPeriodInMS));
|
||||
m_waitEvent.try_acquire_for(AZStd::chrono::milliseconds(m_pollingPeriodInMS));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AzCore/std/parallel/binary_semaphore.h>
|
||||
#include <AzCore/std/parallel/mutex.h>
|
||||
#include <AzCore/std/parallel/thread.h>
|
||||
|
||||
@@ -58,5 +59,6 @@ namespace AWSGameLift
|
||||
|
||||
AZStd::mutex m_trackerMutex;
|
||||
AZStd::thread m_trackerThread;
|
||||
AZStd::binary_semaphore m_waitEvent;
|
||||
};
|
||||
} // namespace AWSGameLift
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
using namespace AWSGameLift;
|
||||
|
||||
static constexpr const uint64_t TEST_RACKER_POLLING_PERIOD_MS = 100;
|
||||
static constexpr const uint64_t TEST_RACKER_POLLING_PERIOD_MS = 1000;
|
||||
static constexpr const uint64_t TEST_WAIT_BUFFER_TIME_MS = 10;
|
||||
static constexpr const uint64_t TEST_WAIT_MAXIMUM_TIME_MS = 10000;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user