]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Try improve test stability 4695/head
authorAndrew Lewis <nerf@judo.za.org>
Thu, 9 Nov 2023 15:49:12 +0000 (17:49 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Thu, 9 Nov 2023 15:49:12 +0000 (17:49 +0200)
test/functional/util/dummy_http.py
test/functional/util/dummy_killer.py

index a88b64801d954ca129aa5d7b1969b1228f349049..832dbdc7975f414af369cc9ab15ce661bcaa06d1 100755 (executable)
@@ -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())
index 6b31816087d76670f38adccb09a35ba451390d31..0a052fb3ee071722008811b4cdcf0fb826db94b4 100644 (file)
@@ -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)