Skip to content

Commit

Permalink
tests.test_daemon: shutdown server after the fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
skshetry committed Aug 14, 2024
1 parent cb811d5 commit 2b4fc51
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tests/func/test_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def server():
thread = Thread(target=httpd.serve_forever)
thread.daemon = True
thread.start()
yield httpd
try:
yield httpd
finally:
httpd.shutdown()


def test_analytics(tmp_path, server):
Expand Down Expand Up @@ -109,10 +112,14 @@ def test_analytics(tmp_path, server):
assert match, "no match for the pid"
pid = int(match.group(1).strip())

with suppress(psutil.NoSuchProcess):
psutil.Process(pid).wait(timeout=10)
with suppress(psutil.NoSuchProcess, psutil.TimeoutExpired):
psutil.Process(pid).wait(timeout=30)

log_contents = logfile.read_text(encoding="utf8")
expected_line = (f"Process {pid} " if os.name != "nt" else "") + "exiting with 0"
assert expected_line in log_contents

assert not os.path.exists(report_file)
assert f"Process {pid} exiting with 0" in logfile.read_text(encoding="utf8")
assert server.RequestHandlerClass.hits == {"POST": 1}


Expand Down Expand Up @@ -142,7 +149,11 @@ def test_updater(tmp_dir, dvc, server):

with suppress(psutil.NoSuchProcess):
psutil.Process(pid).wait(timeout=10)
assert f"Process {pid} exiting with 0" in logfile.read_text(encoding="utf8")

log_contents = logfile.read_text(encoding="utf8")
expected_line = (f"Process {pid} " if os.name != "nt" else "") + "exiting with 0"
assert expected_line in log_contents

assert server.RequestHandlerClass.hits == {"GET": 1}
# check that the file is saved correctly
updater_file = Path(dvc.tmp_dir) / Updater.UPDATER_FILE
Expand Down

0 comments on commit 2b4fc51

Please sign in to comment.