Skip to content

Commit

Permalink
Improve the process cleanup logic when running tests (#616)
Browse files Browse the repository at this point in the history
* Improve the process cleanup logic when running tests

* Add graceful shutdown in test_dht_experts

* Add graceful shutdown in test_fault_tolerance
  • Loading branch information
mryab authored Jun 9, 2024
1 parent 91fa494 commit 51e5942
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import gc
from contextlib import suppress

import psutil
import pytest
Expand Down Expand Up @@ -40,13 +39,12 @@ def cleanup_children():

children = psutil.Process().children(recursive=True)
if children:
logger.info(f"Cleaning up {len(children)} leftover child processes")
for child in children:
with suppress(psutil.NoSuchProcess):
child.terminate()
psutil.wait_procs(children, timeout=1)
for child in children:
with suppress(psutil.NoSuchProcess):
child.kill()
gone, alive = psutil.wait_procs(children, timeout=0.1)
logger.debug(f"Cleaning up {len(alive)} leftover child processes")
for child in alive:
child.terminate()
gone, alive = psutil.wait_procs(alive, timeout=1)
for child in alive:
child.kill()

MPFuture.reset_backend()
1 change: 1 addition & 0 deletions tests/test_allreduce_fault_tolerance.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,4 @@ def _make_tensors():

for averager in averagers:
averager.shutdown()
dht.shutdown()
6 changes: 6 additions & 0 deletions tests/test_dht_experts.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def test_beam_search(
assert all(isinstance(e, hivemind.RemoteExpert) for experts in batch_experts for e in experts)
assert all(len(experts) == beam_size for experts in batch_experts)

you.shutdown()
for dht_instance in dht_instances:
dht_instance.shutdown()


@pytest.mark.forked
def test_dht_single_node():
Expand Down Expand Up @@ -119,6 +123,8 @@ def test_dht_single_node():
with pytest.raises(AssertionError):
beam_search.get_active_successors(["e.1.2.", "e.2", "e.4.5."])

node.shutdown()


def test_uid_patterns():
valid_experts = [
Expand Down

0 comments on commit 51e5942

Please sign in to comment.