Properly shutdown test mock S3 server

This commit is contained in:
Kirill Bulatov
2022-05-24 17:56:37 +03:00
committed by Kliment Serafimov
parent a3238cd69d
commit fedcc71c01
2 changed files with 6 additions and 3 deletions

View File

@@ -393,7 +393,10 @@ class MockS3Server:
):
self.port = port
self.subprocess = subprocess.Popen([f'poetry run moto_server s3 -p{port}'], shell=True)
# XXX: do not use `shell=True` or add `exec ` to the command here otherwise.
# We use `self.subprocess.kill()` to shut down the server, which would not "just" work in Linux
# if a process is started from the shell process.
self.subprocess = subprocess.Popen(['poetry', 'run', 'moto_server', 's3', f'-p{port}'])
error = None
try:
return_code = self.subprocess.poll()
@@ -403,7 +406,7 @@ class MockS3Server:
error = f"expected mock s3 server to start but it failed with exception: {e}. stdout: '{self.subprocess.stdout}', stderr: '{self.subprocess.stderr}'"
if error is not None:
log.error(error)
self.subprocess.kill()
self.kill()
raise RuntimeError("failed to start s3 mock server")
def endpoint(self) -> str: