Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions Gem/Code/Source/NetSoakTestSystemComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#include "NetSoakTestSystemComponent.h"

#include <AzFramework/API/ApplicationAPI.h>
#include <AzFramework/Windowing/WindowBus.h>

namespace AzNetworking
{
enum class SoakMode
Expand Down Expand Up @@ -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_runtime, AZ::Time::ZeroTimeMs, nullptr, AZ::ConsoleFunctorFlags::DontReplicate, "How long to run the soak test for before dumping stats");

void NetSoakTestSystemComponent::Reflect(AZ::ReflectContext* context)
{
Expand Down Expand Up @@ -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_runtime != AZ::Time::ZeroTimeMs)
{
if (m_soakEndTimepoint == AZ::Time::ZeroTimeMs)
{
m_soakEndTimepoint = AZ::GetRealElapsedTimeMs() + soak_runtime;
}
else if (AZ::GetRealElapsedTimeMs() >= m_soakEndTimepoint)
{
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_runtime));
AZ::Interface<AZ::IConsole>::Get()->PerformCommand("DumpSoakStats");

AzFramework::ApplicationRequests::Bus::Broadcast(&AzFramework::ApplicationRequests::ExitMainLoop);
return;
}

NetSoakTestPackets::Small packet;

Expand All @@ -199,7 +228,6 @@ namespace NetSoakTest
unreliable.SetSmallDatum(2);
connection.SendUnreliablePacket(unreliable);
}

};

m_networkInterface->GetConnectionSet().VisitConnections(visitor);
Expand Down
3 changes: 3 additions & 0 deletions Gem/Code/Source/NetSoakTestSystemComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ namespace NetSoakTest
////////////////////////////////////////////////////////////////////////

private:
bool CheckforTimedTermination();

AzNetworking::INetworkInterface* m_networkInterface = nullptr;
AzNetworking::INetworkInterface* m_loopbackInterface = nullptr;
AZ::TimeMs m_soakEndTimepoint = AZ::Time::ZeroTimeMs;
};
}
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 format 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.

Expand All @@ -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_runtime | How long to run the test for. 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:

Expand Down