test_process_utils.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. import os
  7. import subprocess
  8. import pytest
  9. import ly_test_tools.environment.process_utils as process_utils
  10. import ly_test_tools.environment.waiter as waiter
  11. from ly_test_tools import WINDOWS
  12. if WINDOWS:
  13. pytestmark = pytest.mark.SUITE_smoke
  14. else:
  15. pytestmark = pytest.mark.skipif(not WINDOWS, reason="Only runs on Windows")
  16. class TestSubprocessCheckOutputWrapper(object):
  17. def test_KillWindowsProgram_WindowsProgramStarted_KilledSuccessfully(self):
  18. windows_program = 'timeout.exe'
  19. windows_directory = os.environ.get('windir')
  20. command = [
  21. os.path.join(f'{windows_directory}', 'System32', f'{windows_program}'),
  22. '/T', # Timeout flag
  23. '4', # 4 seconds
  24. ]
  25. def process_killed():
  26. return not process_utils.process_exists(windows_program, ignore_extensions=True)
  27. assert os.path.exists(command[0]), (
  28. f'The {windows_program} executable does not exist at: {command[0]}'
  29. )
  30. with subprocess.Popen(command, creationflags=subprocess.CREATE_NEW_CONSOLE) as process:
  31. if process_utils.process_exists(windows_program, ignore_extensions=True):
  32. process_utils.kill_process_with_pid(process.pid)
  33. waiter.wait_for(process_killed, timeout=2) # Raises exception if the process is alive.