Skip to content

Commit

Permalink
Replaced python sdk usage with docker cli (#800)
Browse files Browse the repository at this point in the history
* Replaced python sdk usage with docker cli

* Removed docker requirement and updated get ids function
  • Loading branch information
hpohekar authored Aug 30, 2022
1 parent ccafff7 commit 71a4b9e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
3 changes: 1 addition & 2 deletions requirements/requirements_tests.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pytest
pytest-mock
pytest-cov
psutil>=5.9.1
docker>=5.0.3
psutil>=5.9.1
26 changes: 16 additions & 10 deletions tests/test_fluent_session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import subprocess
import time

import psutil
Expand All @@ -10,7 +11,6 @@
import ansys.fluent.core as pyfluent
from ansys.fluent.core.examples import download_file
from ansys.fluent.core.session import _FluentConnection
import docker


def _read_case(session):
Expand Down Expand Up @@ -54,18 +54,25 @@ def print_transcript(transcript):
assert not print_transcript.called


def get_container_ids_set():
proc = subprocess.Popen(["docker", "ps", "-q"], stdout=subprocess.PIPE)
output_bytes = proc.stdout.read()
output_str = output_bytes.decode()
ids = output_str.strip().split()
return set(ids)


def test_server_exits_when_session_goes_out_of_scope(with_launching_container) -> None:
def f():
session = pyfluent.launch_fluent(mode="solver")
f.server_pid = session.scheme_eval.scheme_eval("(%cx-process-id)")

if os.getenv("PYFLUENT_START_INSTANCE") == "0":
client = docker.from_env()
containers_before = client.containers.list()
containers_before = get_container_ids_set()
f()
time.sleep(10)
containers_after = client.containers.list()
new_containers = set(containers_after) - set(containers_before)
containers_after = get_container_ids_set()
new_containers = containers_after - containers_before
assert not new_containers
else:
f()
Expand All @@ -81,15 +88,14 @@ def f():
f.server_pid = session.scheme_eval.scheme_eval("(%cx-process-id)")

if os.getenv("PYFLUENT_START_INSTANCE") == "0":
client = docker.from_env()
containers_before = client.containers.list()
containers_before = get_container_ids_set()
f()
time.sleep(10)
containers_after = client.containers.list()
new_containers = set(containers_after) - set(containers_before)
containers_after = get_container_ids_set()
new_containers = containers_after - containers_before
assert new_containers
for container in new_containers:
container.stop()
subprocess.Popen(["docker", "stop", container])
else:
f()
time.sleep(10)
Expand Down

0 comments on commit 71a4b9e

Please sign in to comment.