Browse Source

Add a new console variable to control length of test (#26)

Signed-off-by: Pip Potter <[email protected]>
Pip Potter 3 years ago
parent
commit
9e768201f6

+ 31 - 3
Gem/Code/Source/NetSoakTestSystemComponent.cpp

@@ -14,6 +14,9 @@
 
 #include "NetSoakTestSystemComponent.h"
 
+#include <AzFramework/API/ApplicationAPI.h>
+#include <AzFramework/Windowing/WindowBus.h>
+
 namespace AzNetworking
 {
     enum class SoakMode
@@ -100,6 +103,7 @@ namespace NetSoakTest
     AZ_CVAR(uint16_t, soak_port, 33450, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "The port that this soak test will bind to for game traffic");
     AZ_CVAR(ProtocolType, soak_protocol, ProtocolType::Udp, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Soak test protocol");
     AZ_CVAR(SoakMode, soak_mode, SoakMode::Loopback, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "Soak test mode");
+    AZ_CVAR(AZ::TimeMs, soak_runtimems, AZ::Time::ZeroTimeMs, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "How long to run (milliseconds) the soak test for before dumping stats. Defaults to running forever.");
 
     void NetSoakTestSystemComponent::Reflect(AZ::ReflectContext* context)
     {
@@ -174,9 +178,34 @@ namespace NetSoakTest
         AZ::Interface<INetworking>::Get()->DestroyNetworkInterface(AZ::Name(s_networkInterfaceName));
     }
 
-    void NetSoakTestSystemComponent::OnTick(float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
+    bool NetSoakTestSystemComponent::CheckforTimedTermination()
     {
-        [[maybe_unused]] auto elapsedMs = aznumeric_cast<AZ::TimeMs>(aznumeric_cast<int64_t>(deltaTime / 1000.0f));
+        // Check to see if test should terminate early if running in timed mode
+        if (soak_runtimems != AZ::Time::ZeroTimeMs)
+        {
+            if (m_soakEndTimepointMs == AZ::Time::ZeroTimeMs)
+            {
+                m_soakEndTimepointMs = AZ::GetRealElapsedTimeMs() + soak_runtimems;
+            }
+            else if (AZ::GetRealElapsedTimeMs() >= m_soakEndTimepointMs)
+            {
+                return true;
+            }
+
+        }
+        return false;
+    }
+
+    void NetSoakTestSystemComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
+    {
+        if (CheckforTimedTermination())
+        {
+            AZLOG_INFO("Completed timed run for %.2f seconds", AZ::TimeMsToSeconds(soak_runtimems));
+            AZ::Interface<AZ::IConsole>::Get()->PerformCommand("DumpSoakStats");
+
+            AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::ExitMainLoop);
+            return;
+        }
 
         NetSoakTestPackets::Small packet;
 
@@ -199,7 +228,6 @@ namespace NetSoakTest
                 unreliable.SetSmallDatum(2);
                 connection.SendUnreliablePacket(unreliable);
             }
-
         };
 
         m_networkInterface->GetConnectionSet().VisitConnections(visitor);

+ 3 - 0
Gem/Code/Source/NetSoakTestSystemComponent.h

@@ -72,7 +72,10 @@ namespace NetSoakTest
         ////////////////////////////////////////////////////////////////////////
 
     private:
+        bool CheckforTimedTermination();
+
         AzNetworking::INetworkInterface* m_networkInterface = nullptr;
         AzNetworking::INetworkInterface* m_loopbackInterface = nullptr;
+        AZ::TimeMs m_soakEndTimepointMs = AZ::Time::ZeroTimeMs;
     };
 }

+ 6 - 4
README.md

@@ -96,13 +96,14 @@ If you have a Git credential helper configured, you should not be prompted for y
 
 ## Running the Project
 
-Run the netsoak ServerLauncher with the relevant comand line values (see full options below), using the format is ```--<command>=<value>```
+Run the netsoak ServerLauncher with the relevant comand line values, using the nformat is ```--<command>=<value>```. See the full list of options below.
 
+For example, the following params will run the loopback test for 2 minutes before dumping stats and exiting:
 ``` 
-NetSoakTest.ServerLauncher --soak_mode=loopback 
+NetSoakTest.ServerLauncher --soak_mode=loopback --soak_runtime=2000
 ```
 
-When running tests, you can use the [debug console](https://www.o3de.org/docs/user-guide/appendix/cvars/debugging/#using-console-debug-views) and the `DumpSoakStats` command to see point-in-time stats from the test. The test will run indefinitely until such point it is terminated.
+When running tests, you can use the [debug console](https://www.o3de.org/docs/user-guide/appendix/cvars/debugging/#using-console-debug-views) and the `DumpSoakStats` command to see point-in-time stats from the test. The test will run indefinitely unless `soak_runtime` is set.
 
 Note: All O3DE projects generate a GameLauncher and a ServerLauncher. NetSoakTest does not utilize its GameLauncher by design.
 
@@ -118,7 +119,8 @@ Note: All O3DE projects generate a GameLauncher and a ServerLauncher. NetSoakTes
 | soak_port | The port that this soak test will bind to for game traffic | 33450 |
 | soak_protocol | Soak test protocol (TCP or UDP) | udp | 
 | soak_mode | The operating mode for the soak test, options are loopback, client or host. `Loopback` has two connection within the application feed traffic to each other in a loop. `Client` expects to connect to a server hosted at soak_serveraddr. `Host` hosts a server for clients to connect to | Loopback | 
-| DumpSoakStats | Dump snapshot of soak test networking stats to console | N/A|
+| soak_runtimems | How long to run the test for in milliseconds. Will automatically dump stats at the end of the test period. | 0 (run indefinitely) |
+| DumpSoakStats | Dump snapshot of soak test networking stats to console and log. | N/A |
 
 Other networking features such as Compression or DTLS/TLS can be enabled/disabled in the same way they would be in a production environment. For example: