Improve the stability of metrics gem tests by removing local file operations (#4761)

Signed-off-by: Junbo Liang <junbo@amazon.com>
monroegm-disable-blank-issue-2
Junbo Liang 4 years ago committed by GitHub
parent 1c409e0a23
commit 77ec88f86e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,7 +31,7 @@ namespace AWSMetrics
static const unsigned int DesiredMaxWorkers = 2; static const unsigned int DesiredMaxWorkers = 2;
MetricsManager(); MetricsManager();
~MetricsManager(); virtual ~MetricsManager();
//! Initializing the metrics manager //! Initializing the metrics manager
//! @return Whether the operation is successful. //! @return Whether the operation is successful.
@ -93,6 +93,12 @@ namespace AWSMetrics
//! @return Total number of requests for sending metrics events. //! @return Total number of requests for sending metrics events.
int GetNumTotalRequests() const; int GetNumTotalRequests() const;
protected:
//! Send metrics to a local file.
//! @param metricsQueue metricsQueue Metrics queue that stores the metrics.
//! @return Outcome of the operation.
virtual AZ::Outcome<void, AZStd::string> SendMetricsToFile(AZStd::shared_ptr<MetricsQueue> metricsQueue);
private: private:
//! Job management //! Job management
void SetupJobContext(); void SetupJobContext();
@ -112,11 +118,6 @@ namespace AWSMetrics
//! @param metricsQueue Metrics events to send. //! @param metricsQueue Metrics events to send.
void SendMetricsToServiceApiAsync(const MetricsQueue& metricsQueue); void SendMetricsToServiceApiAsync(const MetricsQueue& metricsQueue);
//! Send metrics to a local file.
//! @param metricsQueue metricsQueue Metrics queue that stores the metrics.
//! @return Outcome of the operation.
AZ::Outcome<void, AZStd::string> SendMetricsToFile(AZStd::shared_ptr<MetricsQueue> metricsQueue);
//! Push metrics events to the front of the queue for retry. //! Push metrics events to the front of the queue for retry.
//! @param metricsEventsForRetry Metrics events for retry. //! @param metricsEventsForRetry Metrics events for retry.
void PushMetricsForRetry(MetricsQueue& metricsEventsForRetry); void PushMetricsForRetry(MetricsQueue& metricsEventsForRetry);

@ -139,11 +139,6 @@ namespace AWSMetrics
return true; return true;
} }
bool RemoveDirectory(const AZStd::string& directory)
{
return AZ::IO::SystemFile::DeleteDir(directory.c_str());
}
AZ::IO::FileIOBase* m_priorFileIO = nullptr; AZ::IO::FileIOBase* m_priorFileIO = nullptr;
AZ::IO::FileIOBase* m_localFileIO = nullptr; AZ::IO::FileIOBase* m_localFileIO = nullptr;

@ -75,6 +75,23 @@ namespace AZ
namespace AWSMetrics namespace AWSMetrics
{ {
class MetricsManagerMock
: public MetricsManager
{
private:
AZ::Outcome<void, AZStd::string> SendMetricsToFile(AZStd::shared_ptr<MetricsQueue> metricsQueue) override
{
if (AZ::IO::FileIOBase::GetInstance())
{
return AZ::Success();
}
else
{
return AZ::Failure(AZStd::string{ "Invalid File IO" });
}
}
};
class AWSMetricsNotificationBusMock class AWSMetricsNotificationBusMock
: protected AWSMetricsNotificationBus::Handler : protected AWSMetricsNotificationBus::Handler
{ {
@ -134,13 +151,11 @@ namespace AWSMetrics
AWSMetricsGemAllocatorFixture::SetUp(); AWSMetricsGemAllocatorFixture::SetUp();
AWSMetricsRequestBus::Handler::BusConnect(); AWSMetricsRequestBus::Handler::BusConnect();
m_metricsManager = AZStd::make_unique<MetricsManager>(); m_metricsManager = AZStd::make_unique<MetricsManagerMock>();
AZStd::string configFilePath = CreateClientConfigFile(true, (double) TestMetricsEventSizeInBytes / MbToBytes * 2, DefaultFlushPeriodInSeconds, 0); AZStd::string configFilePath = CreateClientConfigFile(true, (double) TestMetricsEventSizeInBytes / MbToBytes * 2, DefaultFlushPeriodInSeconds, 0);
m_settingsRegistry->MergeSettingsFile(configFilePath, AZ::SettingsRegistryInterface::Format::JsonMergePatch, {}); m_settingsRegistry->MergeSettingsFile(configFilePath, AZ::SettingsRegistryInterface::Format::JsonMergePatch, {});
m_metricsManager->Init(); m_metricsManager->Init();
RemoveFile(m_metricsManager->GetMetricsFilePath());
ReplaceLocalFileIOWithMockIO(); ReplaceLocalFileIOWithMockIO();
} }
@ -149,8 +164,6 @@ namespace AWSMetrics
RevertMockIOToLocalFileIO(); RevertMockIOToLocalFileIO();
RemoveFile(GetDefaultTestFilePath()); RemoveFile(GetDefaultTestFilePath());
RemoveFile(m_metricsManager->GetMetricsFilePath());
RemoveDirectory(m_metricsManager->GetMetricsFileDirectory());
m_metricsManager.reset(); m_metricsManager.reset();
@ -233,7 +246,7 @@ namespace AWSMetrics
} }
} }
AZStd::unique_ptr<MetricsManager> m_metricsManager; AZStd::unique_ptr<MetricsManagerMock> m_metricsManager;
AWSMetricsNotificationBusMock m_notifications; AWSMetricsNotificationBusMock m_notifications;
AZ::IO::FileIOBase* m_fileIOMock; AZ::IO::FileIOBase* m_fileIOMock;

Loading…
Cancel
Save