From: Andrew Lewis Date: Thu, 9 Nov 2023 15:49:12 +0000 (+0200) Subject: [Minor] Try improve test stability X-Git-Tag: 3.8.0~81^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b891de934a9fa6fed21161bf9545f9357d229b27;p=rspamd.git [Minor] Try improve test stability --- diff --git a/test/functional/util/dummy_http.py b/test/functional/util/dummy_http.py index a88b64801..832dbdc79 100755 --- a/test/functional/util/dummy_http.py +++ b/test/functional/util/dummy_http.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import asyncio +import dummy_killer import tornado.ioloop import tornado.web import tornado.httpserver @@ -131,8 +132,7 @@ async def main(): # Write the PID to the specified PID file, if provided if args.pidfile: - with open(args.pidfile, "w") as f: - f.write(str(os.getpid())) + dummy_killer.write_pid(args.pidfile) # Start the server server.bind(args.port, args.bind) @@ -141,4 +141,4 @@ async def main(): await asyncio.Event().wait() if __name__ == "__main__": - asyncio.run(main()) \ No newline at end of file + asyncio.run(main()) diff --git a/test/functional/util/dummy_killer.py b/test/functional/util/dummy_killer.py index 6b3181608..0a052fb3e 100644 --- a/test/functional/util/dummy_killer.py +++ b/test/functional/util/dummy_killer.py @@ -1,6 +1,7 @@ import signal import os import atexit +import tempfile def setup_killer(server, method = None): def default_method(): @@ -18,9 +19,10 @@ def setup_killer(server, method = None): def write_pid(path): - with open(path, 'w+') as f: + with tempfile.NamedTemporaryFile(mode='w', delete=False) as f: f.write(str(os.getpid())) f.close() + os.rename(f.name, path) def cleanup(): os.remove(path)