浏览代码

Correct failure to load NetSysComponent for unit tests

Signed-off-by: puvvadar <[email protected]>
puvvadar 3 年之前
父节点
当前提交
c0377f0137

+ 4 - 1
Code/Framework/AzFramework/AzFramework/Application/Application.cpp

@@ -188,7 +188,10 @@ namespace AzFramework
 
 
     void Application::Start(const Descriptor& descriptor, const StartupParameters& startupParameters)
     void Application::Start(const Descriptor& descriptor, const StartupParameters& startupParameters)
     {
     {
-        AZ::Entity* systemEntity = Create(descriptor, startupParameters);
+        Descriptor frameworkDescriptor = descriptor;
+        // Ensure AzNetworking is loaded (required for unit tests)
+        frameworkDescriptor.m_modules.push_back(AZ::DynamicModuleDescriptor{ "AzNetworking" });
+        AZ::Entity* systemEntity = Create(frameworkDescriptor, startupParameters);
 
 
         // Sets FileIOAliases again in case the App root was overridden by the
         // Sets FileIOAliases again in case the App root was overridden by the
         // startupParameters in ComponentApplication::Create
         // startupParameters in ComponentApplication::Create

+ 12 - 2
Code/Framework/AzNetworking/Tests/Main.cpp

@@ -6,8 +6,18 @@
  *
  *
  */
  */
 
 
-#include <AzCore/UnitTest/UnitTest.h>
 #include <AzTest/AzTest.h>
 #include <AzTest/AzTest.h>
+#include <AzTest/GemTestEnvironment.h>
 
 
-AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);
+class AzNetworkingTestEnvironment : public AZ::Test::GemTestEnvironment
+{
+    void AddGemsAndComponents() override;
+};
+
+void AzNetworkingTestEnvironment::AddGemsAndComponents()
+{
+    AddDynamicModulePaths({ "AzNetworking" });
+}
+
+AZ_UNIT_TEST_HOOK(new AzNetworkingTestEnvironment);
 
 

+ 4 - 19
Code/Framework/AzNetworking/Tests/Serialization/DeltaSerializerTests.cpp

@@ -105,21 +105,6 @@ namespace UnitTest
         }
         }
     };
     };
 
 
-    class DeltaSerializerTests
-        : public UnitTest::AllocatorsTestFixture
-    {
-    public:
-        void SetUp() override
-        {
-            UnitTest::AllocatorsTestFixture::SetUp();
-        }
-
-        void TearDown() override
-        {
-            UnitTest::AllocatorsTestFixture::TearDown();
-        }
-    };
-
     static constexpr float BLEND_FACTOR_SCALE = 1.1f;
     static constexpr float BLEND_FACTOR_SCALE = 1.1f;
     static constexpr uint32_t TIME_SCALE = 10;
     static constexpr uint32_t TIME_SCALE = 10;
 
 
@@ -145,7 +130,7 @@ namespace UnitTest
         return testContainer;
         return testContainer;
     }
     }
 
 
-    TEST_F(DeltaSerializerTests, DeltaArray)
+    TEST(DeltaSerializerTests, DeltaArray)
     {
     {
         DeltaDataContainer inContainer = TestDeltaContainer();
         DeltaDataContainer inContainer = TestDeltaContainer();
         AZStd::array<uint8_t, 2048> buffer;
         AZStd::array<uint8_t, 2048> buffer;
@@ -171,7 +156,7 @@ namespace UnitTest
         }
         }
     }
     }
 
 
-    TEST_F(DeltaSerializerTests, DeltaSerializerCreateUnused)
+    TEST(DeltaSerializerTests, DeltaSerializerCreateUnused)
     {
     {
         // Every function here should return a constant value regardless of inputs
         // Every function here should return a constant value regardless of inputs
         AzNetworking::SerializerDelta deltaSerializer;
         AzNetworking::SerializerDelta deltaSerializer;
@@ -188,7 +173,7 @@ namespace UnitTest
         EXPECT_TRUE(createSerializer.EndObject("CreateSerializer", "End"));
         EXPECT_TRUE(createSerializer.EndObject("CreateSerializer", "End"));
     }
     }
 
 
-    TEST_F(DeltaSerializerTests, DeltaArraySize)
+    TEST(DeltaSerializerTests, DeltaArraySize)
     {
     {
         DeltaDataContainer deltaContainer = TestDeltaContainer();
         DeltaDataContainer deltaContainer = TestDeltaContainer();
         DeltaDataContainer noDeltaContainer = TestDeltaContainer();
         DeltaDataContainer noDeltaContainer = TestDeltaContainer();
@@ -204,7 +189,7 @@ namespace UnitTest
         EXPECT_FALSE(noDeltaSerializer.IsValid()); // and that it is no longer valid due to lack of space
         EXPECT_FALSE(noDeltaSerializer.IsValid()); // and that it is no longer valid due to lack of space
     }
     }
 
 
-    TEST_F(DeltaSerializerTests, DeltaSerializerApplyUnused)
+    TEST(DeltaSerializerTests, DeltaSerializerApplyUnused)
     {
     {
         // Every function here should return a constant value regardless of inputs
         // Every function here should return a constant value regardless of inputs
         AzNetworking::SerializerDelta deltaSerializer;
         AzNetworking::SerializerDelta deltaSerializer;

+ 0 - 141
Code/Framework/AzNetworking/Tests/TcpTransport/TcpTransportTests.cpp

@@ -50,145 +50,4 @@ namespace UnitTest
 
 
         }
         }
     };
     };
-
-    class TestTcpClient
-    {
-    public:
-        TestTcpClient()
-        {
-            AZStd::string name = AZStd::string::format("TcpClient%d", ++s_numClients);
-            m_name = name;
-            m_clientNetworkInterface = AZ::Interface<INetworking>::Get()->CreateNetworkInterface(m_name, ProtocolType::Tcp, TrustZone::ExternalClientToServer, m_connectionListener);
-            m_clientNetworkInterface->Connect(IpAddress(127, 0, 0, 1, 12345));
-        }
-
-        ~TestTcpClient()
-        {
-            AZ::Interface<INetworking>::Get()->DestroyNetworkInterface(m_name);
-        }
-
-        AZ::Name m_name;
-        TestTcpConnectionListener m_connectionListener;
-        INetworkInterface* m_clientNetworkInterface;
-        static inline int32_t s_numClients = 0;
-    };
-
-    class TestTcpServer
-    {
-    public:
-        TestTcpServer()
-        {
-            m_serverNetworkInterface = AZ::Interface<INetworking>::Get()->CreateNetworkInterface(m_name, ProtocolType::Tcp, TrustZone::ExternalClientToServer, m_connectionListener);
-            m_serverNetworkInterface->Listen(12345);
-        }
-
-        ~TestTcpServer()
-        {
-            AZ::Interface<INetworking>::Get()->DestroyNetworkInterface(m_name);
-        }
-
-        AZ::Name m_name = AZ::Name(AZStd::string_view("TcpServer"));
-        TestTcpConnectionListener m_connectionListener;
-        INetworkInterface* m_serverNetworkInterface;
-    };
-
-    class TcpTransportTests
-        : public AllocatorsFixture
-    {
-    public:
-
-        void SetUp() override
-        {
-            SetupAllocator();
-            AZ::NameDictionary::Create();
-
-            m_loggerComponent = AZStd::make_unique<AZ::LoggerSystemComponent>();
-            m_timeSystem = AZStd::make_unique<AZ::TimeSystem>();
-            m_networkingSystemComponent = AZStd::make_unique<AzNetworking::NetworkingSystemComponent>();
-        }
-
-        void TearDown() override
-        {
-            m_networkingSystemComponent.reset();
-            m_timeSystem.reset();
-            m_loggerComponent.reset();
-
-            AZ::NameDictionary::Destroy();
-            TeardownAllocator();
-        }
-
-        AZStd::unique_ptr<AZ::LoggerSystemComponent> m_loggerComponent;
-        AZStd::unique_ptr<AZ::TimeSystem> m_timeSystem;
-        AZStd::unique_ptr<AzNetworking::NetworkingSystemComponent> m_networkingSystemComponent;
-    };
-
-    #if AZ_TRAIT_DISABLE_FAILED_NETWORKING_TESTS
-    TEST_F(TcpTransportTests, DISABLED_TestSingleClient)
-    #else
-    TEST_F(TcpTransportTests, SUITE_sandbox_TestSingleClient)
-    #endif // AZ_TRAIT_DISABLE_FAILED_NETWORKING_TESTS
-    {
-        TestTcpServer testServer;
-        TestTcpClient testClient;
-
-        constexpr AZ::TimeMs TotalIterationTimeMs = AZ::TimeMs{ 5000 };
-        const AZ::TimeMs startTimeMs = AZ::GetElapsedTimeMs();
-        for (;;)
-        {
-            AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(25));
-            m_networkingSystemComponent->OnTick(0.0f, AZ::ScriptTimePoint());
-            bool timeExpired = (AZ::GetElapsedTimeMs() - startTimeMs > TotalIterationTimeMs);
-            bool canTerminate = (testServer.m_serverNetworkInterface->GetConnectionSet().GetConnectionCount() == 1)
-                             && (testClient.m_clientNetworkInterface->GetConnectionSet().GetConnectionCount() == 1);
-            if (canTerminate || timeExpired)
-            {
-                break;
-            }
-        }
-
-        EXPECT_EQ(testServer.m_serverNetworkInterface->GetConnectionSet().GetConnectionCount(), 1);
-        EXPECT_EQ(testClient.m_clientNetworkInterface->GetConnectionSet().GetConnectionCount(), 1);
-
-        const AZ::TimeMs timeoutMs = AZ::TimeMs{ 100 };
-        testClient.m_clientNetworkInterface->SetTimeoutMs(timeoutMs);
-        EXPECT_EQ(testClient.m_clientNetworkInterface->GetTimeoutMs(), timeoutMs);
-
-        EXPECT_TRUE(testServer.m_serverNetworkInterface->StopListening());
-    }
-
-    #if AZ_TRAIT_DISABLE_FAILED_NETWORKING_TESTS
-    TEST_F(TcpTransportTests, DISABLED_TestMultipleClients)
-    #else
-    TEST_F(TcpTransportTests, SUITE_sandbox_TestMultipleClients)
-    #endif // AZ_TRAIT_DISABLE_FAILED_NETWORKING_TESTS
-    {
-        constexpr uint32_t NumTestClients = 50;
-
-        TestTcpServer testServer;
-        TestTcpClient testClient[NumTestClients];
-
-        constexpr AZ::TimeMs TotalIterationTimeMs = AZ::TimeMs{ 5000 };
-        const AZ::TimeMs startTimeMs = AZ::GetElapsedTimeMs();
-        for (;;)
-        {
-            AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(25));
-            m_networkingSystemComponent->OnTick(0.0f, AZ::ScriptTimePoint());
-            bool timeExpired = (AZ::GetElapsedTimeMs() - startTimeMs > TotalIterationTimeMs);
-            bool canTerminate = testServer.m_serverNetworkInterface->GetConnectionSet().GetConnectionCount() == NumTestClients;
-            for (uint32_t i = 0; i < NumTestClients; ++i)
-            {
-                canTerminate &= testClient[i].m_clientNetworkInterface->GetConnectionSet().GetConnectionCount() == 1;
-            }
-            if (canTerminate || timeExpired)
-            {
-                break;
-            }
-        }
-
-        EXPECT_EQ(testServer.m_serverNetworkInterface->GetConnectionSet().GetConnectionCount(), NumTestClients);
-        for (uint32_t i = 0; i < NumTestClients; ++i)
-        {
-            EXPECT_EQ(testClient[i].m_clientNetworkInterface->GetConnectionSet().GetConnectionCount(), 1);
-        }
-    }
 }
 }

+ 3 - 140
Code/Framework/AzNetworking/Tests/UdpTransport/UdpTransportTests.cpp

@@ -54,78 +54,7 @@ namespace UnitTest
         }
         }
     };
     };
 
 
-    class TestUdpClient
-    {
-    public:
-        TestUdpClient()
-        {
-            AZStd::string name = AZStd::string::format("UdpClient%d", ++s_numClients);
-            m_name = name;
-            m_clientNetworkInterface = AZ::Interface<INetworking>::Get()->CreateNetworkInterface(m_name, ProtocolType::Udp, TrustZone::ExternalClientToServer, m_connectionListener);
-            m_clientNetworkInterface->Connect(IpAddress(127, 0, 0, 1, 12345));
-        }
-
-        ~TestUdpClient()
-        {
-            AZ::Interface<INetworking>::Get()->DestroyNetworkInterface(m_name);
-        }
-
-        AZ::Name m_name;
-        TestUdpConnectionListener m_connectionListener;
-        INetworkInterface* m_clientNetworkInterface;
-        static inline int32_t s_numClients = 0;
-    };
-
-    class TestUdpServer
-    {
-    public:
-        TestUdpServer()
-        {
-            m_serverNetworkInterface = AZ::Interface<INetworking>::Get()->CreateNetworkInterface(m_name, ProtocolType::Udp, TrustZone::ExternalClientToServer, m_connectionListener);
-            m_serverNetworkInterface->Listen(12345);
-        }
-
-        ~TestUdpServer()
-        {
-            AZ::Interface<INetworking>::Get()->DestroyNetworkInterface(m_name);
-        }
-
-        AZ::Name m_name = AZ::Name(AZStd::string_view("UdpServer"));
-        TestUdpConnectionListener m_connectionListener;
-        INetworkInterface* m_serverNetworkInterface;
-    };
-
-    class UdpTransportTests
-        : public AllocatorsFixture
-    {
-    public:
-
-        void SetUp() override
-        {
-            SetupAllocator();
-            AZ::NameDictionary::Create();
-
-            m_loggerComponent = AZStd::make_unique<AZ::LoggerSystemComponent>();
-            m_timeSystem = AZStd::make_unique<AZ::TimeSystem>();
-            m_networkingSystemComponent = AZStd::make_unique<AzNetworking::NetworkingSystemComponent>();
-        }
-
-        void TearDown() override
-        {
-            m_networkingSystemComponent.reset();
-            m_timeSystem.reset();
-            m_loggerComponent.reset();
-
-            AZ::NameDictionary::Destroy();
-            TeardownAllocator();
-        }
-
-        AZStd::unique_ptr<AZ::LoggerSystemComponent> m_loggerComponent;
-        AZStd::unique_ptr<AZ::TimeSystem> m_timeSystem;
-        AZStd::unique_ptr<AzNetworking::NetworkingSystemComponent> m_networkingSystemComponent;
-    };
-
-    TEST_F(UdpTransportTests, PacketIdWrap)
+    TEST(UdpTransportTests, PacketIdWrap)
     {
     {
         const uint32_t SEQUENCE_BOUNDARY = 0xFFFF;
         const uint32_t SEQUENCE_BOUNDARY = 0xFFFF;
         UdpPacketTracker tracker;
         UdpPacketTracker tracker;
@@ -137,7 +66,7 @@ namespace UnitTest
         EXPECT_EQ(tracker.GetNextPacketId(), PacketId(SEQUENCE_BOUNDARY + 1));
         EXPECT_EQ(tracker.GetNextPacketId(), PacketId(SEQUENCE_BOUNDARY + 1));
     }
     }
 
 
-    TEST_F(UdpTransportTests, AckReplication)
+    TEST(UdpTransportTests, AckReplication)
     {
     {
         static const SequenceId TestReliableSequenceId = InvalidSequenceId;
         static const SequenceId TestReliableSequenceId = InvalidSequenceId;
         static const PacketType TestPacketId = PacketType{ 0 };
         static const PacketType TestPacketId = PacketType{ 0 };
@@ -222,7 +151,7 @@ namespace UnitTest
         }
         }
     }
     }
 
 
-    TEST_F(UdpTransportTests, PacketIdWindow)
+    TEST(UdpTransportTests, PacketIdWindow)
     {
     {
         const PacketType TestPacketType{ 12212 };
         const PacketType TestPacketType{ 12212 };
 
 
@@ -255,70 +184,4 @@ namespace UnitTest
         PacketAckState ackState = packetWindow.GetPacketAckStatus(PacketId(1007));
         PacketAckState ackState = packetWindow.GetPacketAckStatus(PacketId(1007));
         EXPECT_EQ(ackState, PacketAckState::Nacked); // Testing that PacketId is not flagged as acked
         EXPECT_EQ(ackState, PacketAckState::Nacked); // Testing that PacketId is not flagged as acked
     }
     }
-
-    TEST_F(UdpTransportTests, TestSingleClient)
-    {
-        TestUdpServer testServer;
-        TestUdpClient testClient;
-
-        constexpr AZ::TimeMs TotalIterationTimeMs = AZ::TimeMs{ 5000 };
-        const AZ::TimeMs startTimeMs = AZ::GetElapsedTimeMs();
-        for (;;)
-        {
-            AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(25));
-            m_networkingSystemComponent->OnTick(0.0f, AZ::ScriptTimePoint());
-            bool timeExpired = (AZ::GetElapsedTimeMs() - startTimeMs > TotalIterationTimeMs);
-            bool canTerminate = (testServer.m_serverNetworkInterface->GetConnectionSet().GetConnectionCount() == 1)
-                             && (testClient.m_clientNetworkInterface->GetConnectionSet().GetConnectionCount() == 1);
-            if (canTerminate || timeExpired)
-            {
-                break;
-            }
-        }
-
-        EXPECT_EQ(testServer.m_serverNetworkInterface->GetConnectionSet().GetConnectionCount(), 1);
-        EXPECT_EQ(testClient.m_clientNetworkInterface->GetConnectionSet().GetConnectionCount(), 1);
-
-        const AZ::TimeMs timeoutMs = AZ::TimeMs{ 100 };
-        testClient.m_clientNetworkInterface->SetTimeoutMs(timeoutMs);
-        EXPECT_EQ(testClient.m_clientNetworkInterface->GetTimeoutMs(), timeoutMs);
-
-        EXPECT_FALSE(testClient.m_clientNetworkInterface->IsEncrypted());
-
-        EXPECT_TRUE(testServer.m_serverNetworkInterface->StopListening());
-        EXPECT_FALSE(testServer.m_serverNetworkInterface->StopListening());
-        EXPECT_FALSE(testServer.m_serverNetworkInterface->IsOpen());
-    }
-
-    TEST_F(UdpTransportTests, TestMultipleClients)
-    {
-        constexpr uint32_t NumTestClients = 50;
-    
-        TestUdpServer testServer;
-        TestUdpClient testClient[NumTestClients];
-    
-        constexpr AZ::TimeMs TotalIterationTimeMs = AZ::TimeMs{ 5000 };
-        const AZ::TimeMs startTimeMs = AZ::GetElapsedTimeMs();
-        for (;;)
-        {
-            AZStd::this_thread::sleep_for(AZStd::chrono::milliseconds(25));
-            m_networkingSystemComponent->OnTick(0.0f, AZ::ScriptTimePoint());
-            bool timeExpired = (AZ::GetElapsedTimeMs() - startTimeMs > TotalIterationTimeMs);
-            bool canTerminate = testServer.m_serverNetworkInterface->GetConnectionSet().GetConnectionCount() == NumTestClients;
-            for (uint32_t i = 0; i < NumTestClients; ++i)
-            {
-                canTerminate &= testClient[i].m_clientNetworkInterface->GetConnectionSet().GetConnectionCount() == 1;
-            }
-            if (canTerminate || timeExpired)
-            {
-                break;
-            }
-        }
-    
-        EXPECT_EQ(testServer.m_serverNetworkInterface->GetConnectionSet().GetConnectionCount(), NumTestClients);
-        for (uint32_t i = 0; i < NumTestClients; ++i)
-        {
-            EXPECT_EQ(testClient[i].m_clientNetworkInterface->GetConnectionSet().GetConnectionCount(), 1);
-        }
-    }
 }
 }

+ 3 - 0
Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.cpp

@@ -76,6 +76,8 @@
 #include <AzToolsFramework/Script/LuaSymbolsReporterSystemComponent.h>
 #include <AzToolsFramework/Script/LuaSymbolsReporterSystemComponent.h>
 #include <Prefab/ProceduralPrefabSystemComponent.h>
 #include <Prefab/ProceduralPrefabSystemComponent.h>
 
 
+#include <AzNetworking/Framework/NetworkingSystemComponent.h>
+
 #include <QtWidgets/QMessageBox>
 #include <QtWidgets/QMessageBox>
 AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option") // 4251: 'QFileInfo::d_ptr': class 'QSharedDataPointer<QFileInfoPrivate>' needs to have dll-interface to be used by clients of class 'QFileInfo'
 AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option") // 4251: 'QFileInfo::d_ptr': class 'QSharedDataPointer<QFileInfoPrivate>' needs to have dll-interface to be used by clients of class 'QFileInfo'
 #include <QDir>
 #include <QDir>
@@ -281,6 +283,7 @@ namespace AzToolsFramework
                 azrtti_typeid<Components::EditorLevelComponentAPIComponent>(),
                 azrtti_typeid<Components::EditorLevelComponentAPIComponent>(),
                 azrtti_typeid<Components::EditorEntityActionComponent>(),
                 azrtti_typeid<Components::EditorEntityActionComponent>(),
                 azrtti_typeid<Components::PropertyManagerComponent>(),
                 azrtti_typeid<Components::PropertyManagerComponent>(),
+                azrtti_typeid<AzNetworking::NetworkingSystemComponent>(),
                 azrtti_typeid<AzFramework::TargetManagementComponent>(),
                 azrtti_typeid<AzFramework::TargetManagementComponent>(),
                 azrtti_typeid<AssetSystem::AssetSystemComponent>(),
                 azrtti_typeid<AssetSystem::AssetSystemComponent>(),
                 azrtti_typeid<PerforceComponent>(),
                 azrtti_typeid<PerforceComponent>(),

+ 1 - 0
Code/Framework/AzToolsFramework/CMakeLists.txt

@@ -38,6 +38,7 @@ ly_add_target(
             3rdParty::Qt::Widgets
             3rdParty::Qt::Widgets
             AZ::AzFramework
             AZ::AzFramework
             AZ::AzQtComponents
             AZ::AzQtComponents
+            AZ::AzNetworking.API
 )
 )