Fixing crash log name bugs in test tools
Signed-off-by: evanchia <evanchia@amazon.com>
This commit is contained in:
@@ -413,7 +413,7 @@ def crash_log_watchdog(request, workspace):
|
||||
|
||||
def _crash_log_watchdog(request, workspace, raise_on_crash):
|
||||
"""Separate implementation to call directly during unit tests"""
|
||||
error_log = os.path.join(workspace.paths.project_log(), 'error.log')
|
||||
error_log = workspace.paths.crash_log()
|
||||
crash_log_watchdog = ly_test_tools.environment.watchdog.CrashLogWatchdog(
|
||||
error_log, raise_on_condition=raise_on_crash)
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from __future__ import annotations
|
||||
import os
|
||||
import time
|
||||
import logging
|
||||
import re
|
||||
|
||||
import ly_test_tools.environment.process_utils as process_utils
|
||||
import ly_test_tools.environment.waiter as waiter
|
||||
@@ -71,7 +72,15 @@ def retrieve_crash_output(run_id: int, workspace: AbstractWorkspaceManager, time
|
||||
:return str: The contents of the editor crash file (error.log)
|
||||
"""
|
||||
crash_info = "-- No crash log available --"
|
||||
crash_log = os.path.join(retrieve_log_path(run_id, workspace), 'error.log')
|
||||
error_log_regex = ""
|
||||
log_path = retrieve_log_path(run_id, workspace)
|
||||
# Gather all of the files in the log directory
|
||||
dir_files = [f for f in os.listdir(log_path) if os.path.isfile(os.path.join(log_path, f))]
|
||||
for file_name in dir_files:
|
||||
# Search for all .log files with either "crash" or "error" because they could be renamed
|
||||
if ("error" in file_name.lower() or "crash" in file_name.lower()) and (file_name.endswith(".log")):
|
||||
crash_log = os.path.join(log_path, file_name)
|
||||
break
|
||||
try:
|
||||
waiter.wait_for(lambda: os.path.exists(crash_log), timeout=timeout)
|
||||
except AssertionError:
|
||||
|
||||
@@ -59,22 +59,28 @@ class TestEditorTestUtils(unittest.TestCase):
|
||||
|
||||
assert expected == editor_test_utils.retrieve_log_path(0, mock_workspace)
|
||||
|
||||
@mock.patch('os.listdir')
|
||||
@mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_log_path')
|
||||
@mock.patch('os.path.isfile', mock.MagicMock())
|
||||
@mock.patch('ly_test_tools.environment.waiter.wait_for', mock.MagicMock())
|
||||
def test_RetrieveCrashOutput_CrashLogExists_ReturnsLogInfo(self, mock_retrieve_log_path):
|
||||
mock_retrieve_log_path.return_value = 'mock_log_path'
|
||||
def test_RetrieveCrashOutput_CrashLogExists_ReturnsLogInfo(self, mock_retrieve_log_path, mock_listdir):
|
||||
mock_retrieve_log_path.return_value = 'mock_path'
|
||||
mock_workspace = mock.MagicMock()
|
||||
mock_log = 'mock crash info'
|
||||
mock_listdir.return_value = ['mock_error_log.log']
|
||||
|
||||
with mock.patch('builtins.open', mock.mock_open(read_data=mock_log)) as mock_file:
|
||||
assert mock_log == editor_test_utils.retrieve_crash_output(0, mock_workspace, 0)
|
||||
|
||||
@mock.patch('os.listdir')
|
||||
@mock.patch('ly_test_tools.o3de.editor_test_utils.retrieve_log_path')
|
||||
@mock.patch('os.path.isfile', mock.MagicMock())
|
||||
@mock.patch('ly_test_tools.environment.waiter.wait_for', mock.MagicMock())
|
||||
def test_RetrieveCrashOutput_CrashLogNotExists_ReturnsError(self, mock_retrieve_log_path):
|
||||
def test_RetrieveCrashOutput_CrashLogNotExists_ReturnsError(self, mock_retrieve_log_path, mock_listdir):
|
||||
mock_retrieve_log_path.return_value = 'mock_log_path'
|
||||
mock_workspace = mock.MagicMock()
|
||||
error_message = "No crash log available"
|
||||
mock_listdir.return_value = ['mock_file.log']
|
||||
|
||||
assert error_message in editor_test_utils.retrieve_crash_output(0, mock_workspace, 0)
|
||||
|
||||
|
||||
@@ -323,20 +323,19 @@ class TestFixtures(object):
|
||||
@mock.patch('ly_test_tools.environment.watchdog.CrashLogWatchdog')
|
||||
def test_CrashLogWatchdog_Instantiates_CreatesWatchdog(self, under_test):
|
||||
mock_workspace = mock.MagicMock()
|
||||
mock_path = 'C:/foo'
|
||||
mock_workspace.paths.project_log.return_value = mock_path
|
||||
mock_workspace.paths.crash_log.return_value = mock.MagicMock()
|
||||
mock_request = mock.MagicMock()
|
||||
mock_request.addfinalizer = mock.MagicMock()
|
||||
mock_raise_on_crash = mock.MagicMock()
|
||||
mock_watchdog = test_tools_fixtures._crash_log_watchdog(mock_request, mock_workspace, mock_raise_on_crash)
|
||||
|
||||
under_test.assert_called_once_with(os.path.join(mock_path, 'error.log'), raise_on_condition=mock_raise_on_crash)
|
||||
under_test.assert_called_once_with(mock_workspace.paths.crash_log.return_value, raise_on_condition=mock_raise_on_crash)
|
||||
|
||||
@mock.patch('ly_test_tools.environment.watchdog.CrashLogWatchdog.start')
|
||||
def test_CrashLogWatchdog_Instantiates_StartsThread(self, under_test):
|
||||
mock_workspace = mock.MagicMock()
|
||||
mock_path = 'C:/foo'
|
||||
mock_workspace.paths.project_log.return_value = mock_path
|
||||
mock_workspace.paths.crash_log.return_value = mock_path
|
||||
mock_request = mock.MagicMock()
|
||||
mock_request.addfinalizer = mock.MagicMock()
|
||||
mock_raise_on_crash = mock.MagicMock()
|
||||
@@ -348,7 +347,7 @@ class TestFixtures(object):
|
||||
def test_CrashLogWatchdog_Instantiates_AddsTeardown(self):
|
||||
mock_workspace = mock.MagicMock()
|
||||
mock_path = 'C:/foo'
|
||||
mock_workspace.paths.project_log.return_value = mock_path
|
||||
mock_workspace.paths.crash_log.return_value = mock_path
|
||||
mock_request = mock.MagicMock()
|
||||
mock_request.addfinalizer = mock.MagicMock()
|
||||
mock_raise_on_crash = mock.MagicMock()
|
||||
@@ -361,7 +360,7 @@ class TestFixtures(object):
|
||||
def test_CrashLogWatchdog_Teardown_CallsStop(self, mock_stop):
|
||||
mock_workspace = mock.MagicMock()
|
||||
mock_path = 'C:/foo'
|
||||
mock_workspace.paths.project_log.return_value = mock_path
|
||||
mock_workspace.paths.crash_log.return_value = mock_path
|
||||
mock_request = mock.MagicMock()
|
||||
mock_request.addfinalizer = mock.MagicMock()
|
||||
mock_raise_condition = mock.MagicMock()
|
||||
|
||||
Reference in New Issue
Block a user