From e2ccfdb21337992bf15043494e52b1498c83df89 Mon Sep 17 00:00:00 2001 From: Martin Vrachev Date: Thu, 24 Sep 2020 13:19:27 +0300 Subject: [PATCH] Reorder the tearDownClass cleanup Fixes an issue where rmtree tries to access and consequently remove a temp folder where the server has opened a file already. This results in error: "PermissionError: [WinError 32] The process cannot access the file because it is being used by another process" For reference read: https://github.com/theupdateframework/tuf/issues/1119 Signed-off-by: Martin Vrachev --- tests/test_arbitrary_package_attack.py | 5 +++-- tests/test_endless_data_attack.py | 5 +++-- tests/test_extraneous_dependencies_attack.py | 5 +++-- tests/test_indefinite_freeze_attack.py | 5 +++-- tests/test_key_revocation_integration.py | 5 +++-- tests/test_mix_and_match_attack.py | 5 +++-- tests/test_replay_attack.py | 5 +++-- tests/test_updater.py | 5 +++-- tests/test_updater_root_rotation_integration.py | 5 +++-- 9 files changed, 27 insertions(+), 18 deletions(-) diff --git a/tests/test_arbitrary_package_attack.py b/tests/test_arbitrary_package_attack.py index d858d83aee..a4127c6462 100755 --- a/tests/test_arbitrary_package_attack.py +++ b/tests/test_arbitrary_package_attack.py @@ -82,12 +82,13 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + # Kills the server subprocess and closes the temp file used for logging. + cls.server_process_handler.clean() + # Remove the temporary repository directory, which should contain all the # metadata, targets, and key files generated of all the test cases. shutil.rmtree(cls.temporary_directory) - # Kills the server subprocess and closes the temp file used for logging. - cls.server_process_handler.clean() diff --git a/tests/test_endless_data_attack.py b/tests/test_endless_data_attack.py index d64ffdcf3b..dd5b901635 100755 --- a/tests/test_endless_data_attack.py +++ b/tests/test_endless_data_attack.py @@ -84,12 +84,13 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + # Kills the server subprocess and closes the temp file used for logging. + cls.server_process_handler.clean() + # Remove the temporary repository directory, which should contain all the # metadata, targets, and key files generated of all the test cases. shutil.rmtree(cls.temporary_directory) - # Kills the server subprocess and closes the temp file used for logging. - cls.server_process_handler.clean() diff --git a/tests/test_extraneous_dependencies_attack.py b/tests/test_extraneous_dependencies_attack.py index c9700d1244..c5f92c9e9d 100755 --- a/tests/test_extraneous_dependencies_attack.py +++ b/tests/test_extraneous_dependencies_attack.py @@ -88,12 +88,13 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + # Kills the server subprocess and closes the temp file used for logging. + cls.server_process_handler.clean() + # Remove the temporary repository directory, which should contain all the # metadata, targets, and key files generated of all the test cases. shutil.rmtree(cls.temporary_directory) - # Kills the server subprocess and closes the temp file used for logging. - cls.server_process_handler.clean() diff --git a/tests/test_indefinite_freeze_attack.py b/tests/test_indefinite_freeze_attack.py index 1e20cce97a..55cc664b3e 100755 --- a/tests/test_indefinite_freeze_attack.py +++ b/tests/test_indefinite_freeze_attack.py @@ -96,12 +96,13 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + # Kills the server subprocess and closes the temp file used for logging. + cls.server_process_handler.clean() + # Remove the temporary repository directory, which should contain all the # metadata, targets, and key files generated of all the test cases. shutil.rmtree(cls.temporary_directory) - # Kills the server subprocess and closes the temp file used for logging. - cls.server_process_handler.clean() diff --git a/tests/test_key_revocation_integration.py b/tests/test_key_revocation_integration.py index 4a7ca179f4..bf13cfe530 100755 --- a/tests/test_key_revocation_integration.py +++ b/tests/test_key_revocation_integration.py @@ -83,12 +83,13 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + # Kills the server subprocess and closes the temp file used for logging. + cls.server_process_handler.clean() + # Remove the temporary repository directory, which should contain all the # metadata, targets, and key files generated for the test cases. shutil.rmtree(cls.temporary_directory) - # Kills the server subprocess and closes the temp file used for logging. - cls.server_process_handler.clean() diff --git a/tests/test_mix_and_match_attack.py b/tests/test_mix_and_match_attack.py index bec55dca4c..9be6c54fe5 100755 --- a/tests/test_mix_and_match_attack.py +++ b/tests/test_mix_and_match_attack.py @@ -87,12 +87,13 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + # Kills the server subprocess and closes the temp file used for logging. + cls.server_process_handler.clean() + # Remove the temporary repository directory, which should contain all the # metadata, targets, and key files generated of all the test cases. shutil.rmtree(cls.temporary_directory) - # Kills the server subprocess and closes the temp file used for logging. - cls.server_process_handler.clean() diff --git a/tests/test_replay_attack.py b/tests/test_replay_attack.py index ac0bc31836..58fdc13ffd 100755 --- a/tests/test_replay_attack.py +++ b/tests/test_replay_attack.py @@ -87,12 +87,13 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + # Kills the server subprocess and closes the temp file used for logging. + cls.server_process_handler.clean() + # Remove the temporary repository directory, which should contain all the # metadata, targets, and key files generated of all the test cases. shutil.rmtree(cls.temporary_directory) - # Kills the server subprocess and closes the temp file used for logging. - cls.server_process_handler.clean() diff --git a/tests/test_updater.py b/tests/test_updater.py index 477ef96c4a..8c76a96c52 100644 --- a/tests/test_updater.py +++ b/tests/test_updater.py @@ -107,12 +107,13 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + # Kills the server subprocess and closes the temp file used for logging. + cls.server_process_handler.clean() + # Remove the temporary repository directory, which should contain all the # metadata, targets, and key files generated for the test cases shutil.rmtree(cls.temporary_directory) - # Kills the server subprocess and closes the temp file used for logging. - cls.server_process_handler.clean() def setUp(self): diff --git a/tests/test_updater_root_rotation_integration.py b/tests/test_updater_root_rotation_integration.py index 721fe32eb6..c101b496b5 100755 --- a/tests/test_updater_root_rotation_integration.py +++ b/tests/test_updater_root_rotation_integration.py @@ -91,12 +91,13 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): + # Kills the server subprocess and closes the temp file used for logging. + cls.server_process_handler.clean() + # Remove the temporary repository directory, which should contain all the # metadata, targets, and key files generated for the test cases. shutil.rmtree(cls.temporary_directory) - # Kills the server subprocess and closes the temp file used for logging. - cls.server_process_handler.clean()