Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions infinistore/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ def start_loop(loop):
loop.run_forever()


loop = asyncio.new_event_loop()
t = threading.Thread(target=start_loop, args=(loop,))
t.start()


def run(args):
config = infinistore.ClientConfig(
host_addr=args.server,
Expand All @@ -138,6 +133,12 @@ def run(args):
config.connection_type = infinistore.TYPE_TCP

conn = infinistore.InfinityConnection(config)
loop = None
t = None
if args.rdma:
loop = asyncio.new_event_loop()
t = threading.Thread(target=start_loop, args=(loop,))
t.start()
try:
conn.connect()

Expand Down Expand Up @@ -271,8 +272,9 @@ def run(args):
assert torch.equal(src_tensor.cpu(), dst_tensor.cpu())
finally:
conn.close()
loop.call_soon_threadsafe(loop.stop)
t.join()
if loop is not None:
loop.call_soon_threadsafe(loop.stop)
t.join()


if __name__ == "__main__":
Expand Down
28 changes: 28 additions & 0 deletions tests/test_benchmark_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import subprocess
import sys
from pathlib import Path


def test_help_exits():
benchmark = Path(__file__).parents[1] / "infinistore" / "benchmark.py"
runner = """
import runpy
import sys
import types

sys.modules["infinistore"] = types.ModuleType("infinistore")
sys.modules["torch"] = types.ModuleType("torch")
benchmark = sys.argv[1]
sys.argv = [benchmark, "--help"]
runpy.run_path(benchmark, run_name="__main__")
"""

result = subprocess.run(
[sys.executable, "-c", runner, str(benchmark)],
capture_output=True,
text=True,
timeout=5,
)

assert result.returncode == 0
assert "--rdma" in result.stdout