commit b891de9: [Minor] Try improve test stability

Andrew Lewis nerf at judo.za.org
Thu Nov 9 16:28:03 UTC 2023


Author: Andrew Lewis
Date: 2023-11-09 17:49:12 +0200
URL: https://github.com/rspamd/rspamd/commit/b891de934a9fa6fed21161bf9545f9357d229b27 (refs/pull/4695/head)

[Minor] Try improve test stability

---
 test/functional/util/dummy_http.py   | 6 +++---
 test/functional/util/dummy_killer.py | 4 +++-
 2 files changed, 6 insertions(+), 4 deletions(-)

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)


More information about the Commits mailing list