Skip to content

Commit

Permalink
add more LinkedClient tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jborbely committed May 13, 2023
1 parent 53d0959 commit efef348
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
3 changes: 2 additions & 1 deletion msl/network/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,8 @@ def identities(self, *, as_string=False, indent=2, timeout=None):

def is_connected(self):
"""See :obj:`.Client.is_connected` for more details."""
self._check_client()
if self._client is None:
return False
return self._client.is_connected()

def notification_handler(self, *args, **kwargs):
Expand Down
34 changes: 33 additions & 1 deletion tests/test_linked_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import platform

import pytest

import conftest
from msl.examples.network import Echo
from msl.network import LinkedClient
from msl.network.constants import HOSTNAME


def test_linked_echo():
Expand Down Expand Up @@ -38,8 +41,37 @@ def test_linked_echo():
assert 'echo' in link.service_attributes
assert 'set_logging_level' in link.service_attributes
assert link.name == 'foobar'
assert link.address_manager.startswith('localhost:')
assert isinstance(link.port, int)
assert link.service_address.startswith(f'{HOSTNAME}:')
assert link.is_connected() is True
assert link.service_name == 'Echo'
assert link.service_language == f'Python {platform.python_version()}'
assert link.service_os == f'{platform.system()} {platform.release()} {platform.machine()}'
assert link.service_max_clients == -1

ids = link.identities()
assert 'Echo' in ids['services']
assert str(link.client) in ids['clients']
assert str(link.client).startswith('foobar')

with pytest.raises(RuntimeError):
with pytest.raises(RuntimeError, match=r"'Echo' object has no attribute"):
link.does_not_exist()

assert str(link).startswith('<Link[name=foobar] with Echo[')
link.unlink()
assert str(link).startswith('<Un-Linked[name=foobar] from Echo[')

with pytest.raises(AttributeError, match=r"Cannot access 'echo'"):
link.echo(0)

link2 = link.spawn()
assert str(link2).startswith('<Link[name=LinkedClient] with Echo[')
assert str(link2.client) == f'LinkedClient[{HOSTNAME}:{link2.port}]'
assert link2.echo('echo', cold='fusion') == [['echo'], {'cold': 'fusion'}]
link2.disconnect()
assert str(link2).startswith('<Un-Linked[name=LinkedClient] from Echo[')
assert link2.client is None
assert link2.is_connected() is False

manager.shutdown(connection=link.client)

0 comments on commit efef348

Please sign in to comment.