From 0a7e9388ad71f79b192fc8dd781856004e05e238 Mon Sep 17 00:00:00 2001 From: Gene Walters Date: Thu, 9 Dec 2021 19:23:48 -0800 Subject: [PATCH] Cleanup: Adding wait_for_critical_expected_line as a public method to utils.py and updated the RPC test to use it. Signed-off-by: Gene Walters --- .../editor_python_test_tools/utils.py | 54 +++++++++++-------- .../tests/Multiplayer_AutoComponent_RPC.py | 30 +++-------- 2 files changed, 39 insertions(+), 45 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py index 7b526033dd..92ac279627 100644 --- a/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py +++ b/AutomatedTesting/Gem/PythonTests/EditorPythonTestTools/editor_python_test_tools/utils.py @@ -100,6 +100,31 @@ class TestHelper: TestHelper.wait_for_condition(lambda : general.is_in_game_mode(), 1.0) Report.critical_result(msgtuple_success_fail, general.is_in_game_mode()) + @staticmethod + def find_expected_line(window, expected_message, print_infos): + """ + Looks for an expected line in a list of tracer log lines + :param window: The log's window name. For example, logs printed via script-canvas use the "Script" window. + :param expected_message: The log message to search. + :param print_infos: A list of PrintInfos collected by Tracer to search. Example options: your_tracer.warnings, your_tracer.errors, your_tracer.asserts, or your_tracer.prints + + :return: True if the message is found, otherwise false. + """ + for printInfo in print_infos: + if printInfo.window == window.strip() and printInfo.message.strip() == expected_message: + return True + return False + + @staticmethod + def wait_for_critical_expected_line(window, expected_message, print_infos, time_out): + TestHelper.wait_for_condition(lambda : TestHelper.find_expected_line(window, expected_message, print_infos), time_out) + Report.critical_result(("Found expected line: " + expected_message, "Failed to find expected line: " + expected_message), TestHelper.find_expected_line(window, expected_message, print_infos)) + + @staticmethod + def wait_for_critical_unexpected_line(window, unexpected_line, print_infos, time_out): + TestHelper.wait_for_condition(lambda : TestHelper.find_expected_line(window, unexpected_line, print_infos), time_out) + Report.critical_result(("Unexpected line not found: " + unexpected_line, "Unexpected line found: " + unexpected_line), not TestHelper.find_expected_line(window, unexpected_line, print_infos)) + @staticmethod def multiplayer_enter_game_mode(msgtuple_success_fail: Tuple[str, str], sv_default_player_spawn_asset: str) -> None: """ @@ -108,23 +133,6 @@ class TestHelper: :return: None """ - - # looks for an expected line in a list of tracers lines - # lines: the tracer list of lines to search. options are section_tracer.warnings, section_tracer.errors, section_tracer.asserts, section_tracer.prints - # return: true if the line is found, otherwise false - def find_expected_line(expected_line, lines): - found_lines = [printInfo.message.strip() for printInfo in lines] - return expected_line in found_lines - - def wait_for_critical_expected_line(expected_line, lines, time_out): - TestHelper.wait_for_condition(lambda : find_expected_line(expected_line, lines), time_out) - Report.critical_result(("Found expected line: " + expected_line, "Failed to find expected line: " + expected_line), find_expected_line(expected_line, lines)) - - def wait_for_critical_unexpected_line(unexpected_line, lines, time_out): - TestHelper.wait_for_condition(lambda : find_expected_line(unexpected_line, lines), time_out) - Report.critical_result(("Unexpected line not found: " + unexpected_line, "Unexpected line found: " + unexpected_line), not find_expected_line(unexpected_line, lines)) - - Report.info("Entering game mode") if sv_default_player_spawn_asset : general.set_cvar("sv_defaultPlayerSpawnAsset", sv_default_player_spawn_asset) @@ -135,20 +143,20 @@ class TestHelper: multiplayer.PythonEditorFuncs_enter_game_mode() # make sure the server launcher binary exists - wait_for_critical_unexpected_line("LaunchEditorServer failed! The ServerLauncher binary is missing!", section_tracer.errors, 0.5) + TestHelper.wait_for_critical_unexpected_line("MultiplayerEditor", "LaunchEditorServer failed! The ServerLauncher binary is missing!", section_tracer.errors, 0.5) # make sure the server launcher is running waiter.wait_for(lambda: process_utils.process_exists("AutomatedTesting.ServerLauncher", ignore_extensions=True), timeout=5.0, exc=AssertionError("AutomatedTesting.ServerLauncher has NOT launched!"), interval=1.0) - wait_for_critical_expected_line("MultiplayerEditorConnection: Editor-server activation has found and connected to the editor.", section_tracer.prints, 15.0) + TestHelper.wait_for_critical_expected_line("EditorServer", "MultiplayerEditorConnection: Editor-server activation has found and connected to the editor.", section_tracer.prints, 15.0) - wait_for_critical_expected_line("Editor is sending the editor-server the level data packet.", section_tracer.prints, 5.0) + TestHelper.wait_for_critical_expected_line("MultiplayerEditor", "Editor is sending the editor-server the level data packet.", section_tracer.prints, 5.0) - wait_for_critical_expected_line("Logger: Editor Server completed receiving the editor's level assets, responding to Editor...", section_tracer.prints, 5.0) + TestHelper.wait_for_critical_expected_line("EditorServer", "Logger: Editor Server completed receiving the editor's level assets, responding to Editor...", section_tracer.prints, 5.0) - wait_for_critical_expected_line("Editor-server ready. Editor has successfully connected to the editor-server's network simulation.", section_tracer.prints, 5.0) + TestHelper.wait_for_critical_expected_line("MultiplayerEditorConnection", "Editor-server ready. Editor has successfully connected to the editor-server's network simulation.", section_tracer.prints, 5.0) - wait_for_critical_unexpected_line(f"MultiplayerSystemComponent: SpawnDefaultPlayerPrefab failed. Missing sv_defaultPlayerSpawnAsset at path '{sv_default_player_spawn_asset.lower()}'.", section_tracer.prints, 0.5) + TestHelper.wait_for_critical_unexpected_line("EditorServer", f"MultiplayerSystemComponent: SpawnDefaultPlayerPrefab failed. Missing sv_defaultPlayerSpawnAsset at path '{sv_default_player_spawn_asset.lower()}'.", section_tracer.prints, 0.5) TestHelper.wait_for_condition(lambda : multiplayer.PythonEditorFuncs_is_in_game_mode(), 5.0) Report.critical_result(msgtuple_success_fail, multiplayer.PythonEditorFuncs_is_in_game_mode()) diff --git a/AutomatedTesting/Gem/PythonTests/Multiplayer/tests/Multiplayer_AutoComponent_RPC.py b/AutomatedTesting/Gem/PythonTests/Multiplayer/tests/Multiplayer_AutoComponent_RPC.py index 3f971e4abf..387de66acd 100644 --- a/AutomatedTesting/Gem/PythonTests/Multiplayer/tests/Multiplayer_AutoComponent_RPC.py +++ b/AutomatedTesting/Gem/PythonTests/Multiplayer/tests/Multiplayer_AutoComponent_RPC.py @@ -14,27 +14,25 @@ class Tests(): enter_game_mode = ("Entered game mode", "Failed to enter game mode") exit_game_mode = ("Exited game mode", "Couldn't exit game mode") find_network_player = ("Found network player", "Couldn't find network player") - found_lines = ("Expected log lines were found", "Expected log lines were not found") - found_unexpected_lines = ("Unexpected log lines were not found", "Unexpected log lines were found") # fmt: on def Multiplayer_AutoComponent_RPC(): r""" Summary: - Runs a test to make sure that network input can be sent from the autonomous player, received by the authority, and processed + Runs a test to make sure that RPCs can be sent and received via script canvas Level Description: - Dynamic - 1. Although the level is empty, when the server and editor connect the server will spawn and replicate the player network prefab. - a. The player network prefab has a NetworkTestPlayerComponent.AutoComponent and a script canvas attached which will listen for the CreateInput and ProcessInput events. - Print logs occur upon triggering the CreateInput and ProcessInput events along with their values; we are testing to make sure the expected events are values are recieved. + 1. Although the level is nearly empty, when the server and editor connect the server will spawn and replicate the player network prefab. + a. The player network prefab has a NetworkTestPlayerComponent.AutoComponent and a script canvas attached which sends and receives various RPCs. + Print logs occur upon sending and receiving the RPCs; we are testing to make sure the expected events and values are received. - Static - 1. This is an empty level. All the logic occurs on the Player.network.spawnable (see the above Dynamic description) + 1. NetLevelEntity. This is a networked entity which has a script attached. Used for cross-entity communication. The net-player prefab will send this level entity Server->Authority RPCs Expected Outcome: - We should see editor logs stating that network input has been created and processed. + We should see editor logs stating that RPCs have been sent and received. However, if the script receives unexpected values for the Process event we will see print logs for bad data as well. :return: @@ -46,18 +44,6 @@ def Multiplayer_AutoComponent_RPC(): from editor_python_test_tools.utils import TestHelper as helper from ly_remote_console.remote_console_commands import RemoteConsole as RemoteConsole - - # looks for an expected line in a list of tracers lines - # lines: the tracer list of lines to search. options are section_tracer.warnings, section_tracer.errors, section_tracer.asserts, section_tracer.prints - # return: true if the line is found, otherwise false - def find_expected_line(expected_line, lines): - found_lines = [printInfo.message.strip() for printInfo in lines] - return expected_line in found_lines - - def wait_for_critical_expected_line(expected_line, lines, time_out): - helper.wait_for_condition(lambda : find_expected_line(expected_line, lines), time_out) - Report.critical_result(("Found expected line: " + expected_line, "Failed to find expected line: " + expected_line), find_expected_line(expected_line, lines)) - level_name = "AutoComponent_RPC" player_prefab_name = "Player" player_prefab_path = f"levels/multiplayer/{level_name}/{player_prefab_name}.network.spawnable" @@ -77,8 +63,8 @@ def Multiplayer_AutoComponent_RPC(): # 4) Check the editor logs for expected and unexpected log output EXPECTEDLINE_WAIT_TIME_SECONDS = 1.0 - wait_for_critical_expected_line('Script: AutoComponent_RPC: Sending client PlayerNumber 1', section_tracer.prints, EXPECTEDLINE_WAIT_TIME_SECONDS) - wait_for_critical_expected_line("AutoComponent_RPC: I'm Player #1", section_tracer.prints, EXPECTEDLINE_WAIT_TIME_SECONDS) + helper.wait_for_critical_expected_line('EditorServer', 'Script: AutoComponent_RPC: Sending client PlayerNumber 1', section_tracer.prints, EXPECTEDLINE_WAIT_TIME_SECONDS) + helper.wait_for_critical_expected_line('Script', "AutoComponent_RPC: I'm Player #1", section_tracer.prints, EXPECTEDLINE_WAIT_TIME_SECONDS) # Exit game mode