Some shutdown crash fixes, reverted a whitespace, and added some basic unit tests for time additions

Signed-off-by: kberg-amzn <karlberg@amazon.com>
This commit is contained in:
kberg-amzn
2021-10-01 15:04:50 -07:00
parent 865ed60007
commit bf136a567b
8 changed files with 85 additions and 2 deletions
-2
View File
@@ -1,4 +1,3 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
@@ -6,7 +5,6 @@
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/base.h>
@@ -0,0 +1,56 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AzCore/Time/TimeSystemComponent.h>
#include <AzCore/UnitTest/TestTypes.h>
namespace UnitTest
{
class TimeTests
: public AllocatorsFixture
{
public:
void SetUp() override
{
SetupAllocator();
m_timeComponent = new AZ::TimeSystemComponent;
}
void TearDown() override
{
delete m_timeComponent;
TeardownAllocator();
}
AZ::TimeSystemComponent* m_timeComponent = nullptr;
};
TEST_F(TimeTests, TestConversionUsToMs)
{
AZ::TimeUs timeUs = AZ::TimeUs{ 1000 };
AZ::TimeMs timeMs = AZ::TimeUsToMs(timeUs);
EXPECT_EQ(timeMs, AZ::TimeMs{ 1 });
}
TEST_F(TimeTests, TestConversionMsToUs)
{
AZ::TimeMs timeMs = AZ::TimeMs{ 1000 };
AZ::TimeUs timeUs = AZ::TimeMsToUs(timeMs);
EXPECT_EQ(timeUs, AZ::TimeUs{ 1000000 });
}
TEST_F(TimeTests, TestClocks)
{
AZ::TimeUs timeUs = AZ::GetElapsedTimeUs();
AZ::TimeMs timeMs = AZ::GetElapsedTimeMs();
AZ::TimeMs timeUsToMs = AZ::TimeUsToMs(timeUs);
int64_t delta = static_cast<int64_t>(timeMs) - static_cast<int64_t>(timeUsToMs);
EXPECT_LT(abs(delta), 1);
}
}
@@ -127,6 +127,7 @@ set(FILES
Serialization/Json/UnorderedSetSerializerTests.cpp
Serialization/Json/UnsupportedTypesSerializerTests.cpp
Serialization/Json/UuidSerializerTests.cpp
Time/TimeTests.cpp
Math/AabbTests.cpp
Math/ColorTests.cpp
Math/CrcTests.cpp
@@ -67,6 +67,9 @@ namespace Multiplayer
//! @return reference to the requested component data, an empty container will be returned if the NetComponentId does not exist
const ComponentData& GetMultiplayerComponentData(NetComponentId netComponentId) const;
//! This releases all owned memory, should only be called during multiplayer shutdown.
void Reset();
private:
NetComponentId m_nextNetComponentId = NetComponentId{ 0 };
AZStd::unordered_map<NetComponentId, ComponentData> m_componentData;
@@ -57,4 +57,9 @@ namespace Multiplayer
}
return nullComponentData;
}
void MultiplayerComponentRegistry::Reset()
{
m_componentData.clear();
}
}
@@ -199,6 +199,8 @@ namespace Multiplayer
AZ::Interface<INetworking>::Get()->DestroyNetworkInterface(AZ::Name(MpNetworkInterfaceName));
AzFramework::SessionNotificationBus::Handler::BusDisconnect();
AZ::TickBus::Handler::BusDisconnect();
m_networkEntityManager.Reset();
}
bool MultiplayerSystemComponent::StartHosting(uint16_t port, bool isDedicated)
@@ -300,6 +300,21 @@ namespace Multiplayer
}
}
void NetworkEntityManager::Reset()
{
m_multiplayerComponentRegistry.Reset();
m_removeList.clear();
m_entityDomain = nullptr;
m_updateEntityDomainEvent.RemoveFromQueue();
m_ownedEntities.clear();
m_entityExitDomainEvent.DisconnectAllHandlers();
m_onEntityMarkedDirty.DisconnectAllHandlers();
m_onEntityNotifyChanges.DisconnectAllHandlers();
m_controllersActivatedEvent.DisconnectAllHandlers();
m_controllersDeactivatedEvent.DisconnectAllHandlers();
m_localDeferredRpcMessages.clear();
}
void NetworkEntityManager::RemoveEntities()
{
AZStd::vector<NetEntityId> removeList;
@@ -92,6 +92,9 @@ namespace Multiplayer
void OnRootSpawnableReleased(uint32_t generation) override;
//! @}
//! Used to release all memory prior to shutdown.
void Reset();
private:
void RemoveEntities();
NetEntityId NextId();