Skip to content

Commit

Permalink
[Minor] Try improve test stability
Browse files Browse the repository at this point in the history
  • Loading branch information
fatalbanana committed Nov 9, 2023
1 parent 1e62c2b commit b891de9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions test/functional/util/dummy_http.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import asyncio
import dummy_killer
import tornado.ioloop
import tornado.web
import tornado.httpserver
Expand Down Expand Up @@ -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)
Expand All @@ -141,4 +141,4 @@ async def main():
await asyncio.Event().wait()

if __name__ == "__main__":
asyncio.run(main())
asyncio.run(main())
4 changes: 3 additions & 1 deletion test/functional/util/dummy_killer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import signal
import os
import atexit
import tempfile

def setup_killer(server, method = None):
def default_method():
Expand All @@ -18,9 +19,10 @@ def alarm_handler(signum, frame):


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)
Expand Down

0 comments on commit b891de9

Please sign in to comment.