Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: complete pod tests #2164

Merged
merged 4 commits into from
Mar 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
91 changes: 90 additions & 1 deletion tests/unit/peapods/pods/test_pods.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,96 @@
from jina.parsers import set_pod_parser
from jina.peapods import Pod
from jina.peapods.pods import BasePod
from jina.peapods.pods.helper import get_public_ip, get_internal_ip
from jina.peapods.pods.helper import get_internal_ip


@pytest.fixture(scope='function')
def pod_args():
args = [
'--name',
'test',
'--parallel',
'2',
'--host',
'0.0.0.0',
]
return set_pod_parser().parse_args(args)


@pytest.fixture(scope='function')
def pod_args_singleton():
args = [
'--name',
'test2',
'--uses-before',
'_pass',
'--parallel',
'1',
'--host',
'0.0.0.0',
]
return set_pod_parser().parse_args(args)


def test_name(pod_args):
with Pod(pod_args) as pod:
assert pod.name == 'test'


def test_host(pod_args):
with Pod(pod_args) as pod:
assert pod.host == '0.0.0.0'
assert pod.host_in == '0.0.0.0'
assert pod.host_out == '0.0.0.0'


def test_address_in_out(pod_args):
with Pod(pod_args) as pod:
assert pod.host in pod.address_in
assert pod.host in pod.address_out


def test_is_ready(pod_args):
with Pod(pod_args) as pod:
assert pod.is_ready is True


def test_equal(pod_args, pod_args_singleton):
pod1 = Pod(pod_args)
pod2 = Pod(pod_args)
assert pod1 == pod2
pod1.close()
pod2.close()
# test not equal
pod1 = Pod(pod_args)
pod2 = Pod(pod_args_singleton)
assert pod1 != pod2
pod1.close()
pod2.close()


def test_head_args_get_set(pod_args, pod_args_singleton):
with Pod(pod_args) as pod:
assert pod.head_args == pod.peas_args['head']
pod.head_args = pod_args_singleton
assert pod.peas_args['head'] == pod_args_singleton

with Pod(pod_args_singleton) as pod:
assert pod.head_args == pod.first_pea_args
pod.head_args = pod_args
assert pod.peas_args['peas'][0] == pod_args


def test_tail_args_get_set(pod_args, pod_args_singleton):
with Pod(pod_args) as pod:
assert pod.tail_args == pod.peas_args['tail']
pod.tail_args = pod_args_singleton
assert pod.peas_args['tail'] == pod_args_singleton

with Pod(pod_args_singleton) as pod:
assert pod.tail_args == pod.first_pea_args
pod.tail_args = pod_args
assert pod.peas_args['peas'][0] == pod_args


@pytest.mark.parametrize('parallel', [1, 2, 4])
Expand Down