def test_compound_pod_do_not_forward_uses_before_uses_after(): polling = 'all' shards = 2 replicas = 2 args = set_pod_parser().parse_args( [ '--name', 'pod', '--shards', f'{shards}', '--polling', f'{polling}', '--replicas', f'{replicas}', '--uses-after', 'BaseExecutor', '--uses-before', 'BaseExecutor', ] ) cpod = CompoundPod(args) for pod in cpod.shards: assert pod.args.uses_before is None assert pod.args.uses_after is None
def test_pod_naming_with_parallel(runtime): args = set_pod_parser().parse_args([ '--name', 'pod', '--parallel', '2', '--replicas', '3', '--runtime-backend', runtime, ]) with CompoundPod(args) as bp: assert bp.peas[0].name == 'pod/head' assert bp.peas[1].name == 'pod/tail' assert bp.replica_list[0].name == 'pod/0' assert bp.replica_list[0].peas[0].name == 'pod/0/head' assert bp.replica_list[0].peas[1].name == 'pod/0/tail' assert bp.replica_list[0].peas[2].name == 'pod/0/0' assert bp.replica_list[0].peas[3].name == 'pod/0/1' assert bp.replica_list[1].name == 'pod/1' assert bp.replica_list[1].peas[0].name == 'pod/1/head' assert bp.replica_list[1].peas[1].name == 'pod/1/tail' assert bp.replica_list[1].peas[2].name == 'pod/1/0' assert bp.replica_list[1].peas[3].name == 'pod/1/1' assert bp.replica_list[2].name == 'pod/2' assert bp.replica_list[2].peas[0].name == 'pod/2/head' assert bp.replica_list[2].peas[1].name == 'pod/2/tail' assert bp.replica_list[2].peas[2].name == 'pod/2/0' assert bp.replica_list[2].peas[3].name == 'pod/2/1' # runtime assert bp.peas[0].runtime.name == 'pod/head/ZEDRuntime' assert bp.peas[1].runtime.name == 'pod/tail/ZEDRuntime' assert bp.replica_list[0].peas[ 0].runtime.name == 'pod/0/head/ZEDRuntime' assert bp.replica_list[0].peas[ 1].runtime.name == 'pod/0/tail/ZEDRuntime' assert bp.replica_list[0].peas[2].runtime.name == 'pod/0/0/ZEDRuntime' assert bp.replica_list[0].peas[3].runtime.name == 'pod/0/1/ZEDRuntime' assert bp.replica_list[1].peas[ 0].runtime.name == 'pod/1/head/ZEDRuntime' assert bp.replica_list[1].peas[ 1].runtime.name == 'pod/1/tail/ZEDRuntime' assert bp.replica_list[1].peas[2].runtime.name == 'pod/1/0/ZEDRuntime' assert bp.replica_list[1].peas[3].runtime.name == 'pod/1/1/ZEDRuntime' assert bp.replica_list[2].peas[ 0].runtime.name == 'pod/2/head/ZEDRuntime' assert bp.replica_list[2].peas[ 1].runtime.name == 'pod/2/tail/ZEDRuntime' assert bp.replica_list[2].peas[2].runtime.name == 'pod/2/0/ZEDRuntime' assert bp.replica_list[2].peas[3].runtime.name == 'pod/2/1/ZEDRuntime'
def test_pod_context_parallel(runtime, parallel, replicas): args = set_pod_parser().parse_args([ '--runtime-backend', runtime, '--parallel', str(parallel), '--replicas', str(replicas), ]) with CompoundPod(args) as bp: if parallel == 1: assert bp.num_peas == parallel * replicas + 2 else: # count head and tail assert bp.num_peas == (parallel + 2) * replicas + 2 with CompoundPod(args) as pod: pass
def test_pod_context_sharded(runtime, shards, replicas): args = set_pod_parser().parse_args( [ '--runtime-backend', runtime, '--shards', str(shards), '--replicas', str(replicas), ] ) with CompoundPod(args) as bp: if replicas == 1: assert bp.num_peas == shards + 2 else: # count head and tail assert bp.num_peas == shards * (replicas + 2) + 2 with CompoundPod(args): pass
def test_sockets(polling, shards, pea_socket_in): polling_type = PollingType.ALL if polling == 'all' else PollingType.ANY args = set_pod_parser().parse_args( [ '--name', 'pod', '--shards', f'{shards}', '--polling', f'{polling}', '--replicas', '3', ] ) with CompoundPod(args) as compound_pod: head = compound_pod.head_args tail = compound_pod.tail_args assert compound_pod.args.polling == polling_type assert head.socket_in == SocketType.ROUTER_BIND if polling_type == PollingType.ANY: assert head.socket_out == SocketType.ROUTER_BIND assert tail.num_part == 1 else: assert head.socket_out == SocketType.PUB_BIND assert tail.num_part == shards assert head.scheduling == SchedulerType.LOAD_BALANCE assert tail.socket_in == SocketType.PULL_BIND assert tail.socket_out == SocketType.ROUTER_BIND assert tail.scheduling == SchedulerType.LOAD_BALANCE pod_shards = compound_pod.shards for shard in pod_shards: assert shard.num_peas == 5 assert shard.head_args.socket_in == pea_socket_in assert shard.head_args.socket_out == SocketType.ROUTER_BIND assert shard.tail_args.socket_in == SocketType.PULL_BIND assert shard.tail_args.socket_out == SocketType.PUSH_CONNECT for pea in shard.peas_args['peas']: assert pea.socket_in == SocketType.DEALER_CONNECT assert pea.socket_out == SocketType.PUSH_CONNECT
def test_host_list_matching(num_hosts, used_hosts): args = set_pod_parser().parse_args([ '--name', 'pod', '--parallel', '2', '--replicas', '3', '--peas-hosts', *[f'0.0.0.{i + 1}' for i in range(num_hosts)], '--runtime-backend', 'process', ]) compound_pod = CompoundPod(args) replica_args = compound_pod.replicas_args assert replica_args[0].peas_hosts == used_hosts[0] assert replica_args[1].peas_hosts == used_hosts[1] assert replica_args[2].peas_hosts == used_hosts[2]
def test_pod_naming_with_parallel(runtime): args = set_pod_parser().parse_args([ '--name', 'pod', '--parallel', '2', '--replicas', '3', '--runtime-backend', runtime, ]) with CompoundPod(args) as bp: assert bp.head_pea.name == 'pod/head' assert bp.tail_pea.name == 'pod/tail' assert bp.replicas[0].name == 'pod/rep-0' assert bp.replicas[0].peas[0].name == 'pod/rep-0/head' assert bp.replicas[0].peas[0]._is_inner_pea is False assert bp.replicas[0].peas[1].name == 'pod/rep-0/pea-0' assert bp.replicas[0].peas[1]._is_inner_pea assert bp.replicas[0].peas[2].name == 'pod/rep-0/pea-1' assert bp.replicas[0].peas[2]._is_inner_pea assert bp.replicas[0].peas[3].name == 'pod/rep-0/tail' assert bp.replicas[0].peas[3]._is_inner_pea is False assert bp.replicas[1].name == 'pod/rep-1' assert bp.replicas[1].peas[0].name == 'pod/rep-1/head' assert bp.replicas[1].peas[0]._is_inner_pea is False assert bp.replicas[1].peas[1].name == 'pod/rep-1/pea-0' assert bp.replicas[1].peas[1]._is_inner_pea assert bp.replicas[1].peas[2].name == 'pod/rep-1/pea-1' assert bp.replicas[1].peas[2]._is_inner_pea assert bp.replicas[1].peas[3].name == 'pod/rep-1/tail' assert bp.replicas[1].peas[3]._is_inner_pea is False assert bp.replicas[2].name == 'pod/rep-2' assert bp.replicas[2].peas[0].name == 'pod/rep-2/head' assert bp.replicas[2].peas[0]._is_inner_pea is False assert bp.replicas[2].peas[1].name == 'pod/rep-2/pea-0' assert bp.replicas[2].peas[1]._is_inner_pea assert bp.replicas[2].peas[2].name == 'pod/rep-2/pea-1' assert bp.replicas[2].peas[2]._is_inner_pea assert bp.replicas[2].peas[3].name == 'pod/rep-2/tail' assert bp.replicas[2].peas[3]._is_inner_pea is False
def test_pod_naming_with_shards(runtime): args = set_pod_parser().parse_args( [ '--name', 'pod', '--shards', '2', '--replicas', '3', '--runtime-backend', runtime, ] ) with CompoundPod(args) as bp: assert bp.head_pea.name == 'pod/head' assert bp.tail_pea.name == 'pod/tail' assert bp.shards[0].name == 'pod/shard-0' assert bp.shards[0].head_pea.name == 'pod/shard-0/head' assert bp.shards[0].head_pea._is_inner_pea is False assert bp.shards[0].replica_set._peas[0].name == 'pod/shard-0/rep-0' assert bp.shards[0].replica_set._peas[0]._is_inner_pea assert bp.shards[0].replica_set._peas[1].name == 'pod/shard-0/rep-1' assert bp.shards[0].replica_set._peas[1]._is_inner_pea assert bp.shards[0].replica_set._peas[2].name == 'pod/shard-0/rep-2' assert bp.shards[0].replica_set._peas[2]._is_inner_pea assert bp.shards[0].tail_pea.name == 'pod/shard-0/tail' assert bp.shards[0].tail_pea._is_inner_pea is False assert bp.shards[1].name == 'pod/shard-1' assert bp.shards[1].head_pea.name == 'pod/shard-1/head' assert bp.shards[1].head_pea._is_inner_pea is False assert bp.shards[1].replica_set._peas[0].name == 'pod/shard-1/rep-0' assert bp.shards[1].replica_set._peas[0]._is_inner_pea assert bp.shards[1].replica_set._peas[1].name == 'pod/shard-1/rep-1' assert bp.shards[1].replica_set._peas[1]._is_inner_pea assert bp.shards[1].replica_set._peas[2].name == 'pod/shard-1/rep-2' assert bp.shards[1].replica_set._peas[2]._is_inner_pea assert bp.shards[1].tail_pea.name == 'pod/shard-1/tail' assert bp.shards[1].tail_pea._is_inner_pea is False
def test_sockets(polling, parallel, pea_scheduling, pea_socket_in, pea_socket_out): polling_type = PollingType.ALL if polling == 'all' else PollingType.ANY args = set_pod_parser().parse_args([ '--name', 'pod', '--parallel', f'{parallel}', '--polling', f'{polling}', '--replicas', '3', ]) with CompoundPod(args) as compound_pod: head = compound_pod.head_args assert head.socket_in == SocketType.ROUTER_BIND assert head.socket_out == SocketType.ROUTER_BIND assert head.scheduling == SchedulerType.LOAD_BALANCE tail = compound_pod.tail_args assert tail.socket_in == SocketType.PULL_BIND assert tail.socket_out == SocketType.ROUTER_BIND assert tail.scheduling == SchedulerType.LOAD_BALANCE replicas = compound_pod.replicas for replica in replicas: if parallel > 1: assert len(replica.peas_args['peas']) == parallel for pea in replica.peas_args['peas']: assert pea.polling == PollingType.ALL assert pea.socket_in == pea_socket_in assert pea.socket_out == pea_socket_out assert pea.scheduling == pea_scheduling else: assert len(replica.peas) == 1 assert replica.peas[0].args.polling == polling_type assert replica.peas[0].args.socket_in == pea_socket_in assert replica.peas[0].args.socket_out == pea_socket_out assert replica.peas[0].args.scheduling == pea_scheduling
def test_tail_args_get_set(pod_args): with CompoundPod(pod_args) as pod: assert pod.tail_args == pod.replicas_args['tail']
def test_equal(pod_args, pod_args_singleton): pod1 = CompoundPod(pod_args) pod2 = CompoundPod(pod_args) assert pod1 == pod2 pod1.close() pod2.close() # test not equal pod1 = CompoundPod(pod_args) pod2 = CompoundPod(pod_args_singleton) assert pod1 != pod2 pod1.close() pod2.close()
def test_is_ready(pod_args): with CompoundPod(pod_args) as pod: assert pod.is_ready is True
def test_host(pod_args): with CompoundPod(pod_args) as pod: assert pod.host == __default_host__ assert pod.head_host == __default_host__
def test_name(pod_args): with CompoundPod(pod_args) as pod: assert pod.name == 'test'
def test_host(pod_args): with CompoundPod(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 CompoundPod(pod_args) as pod: assert pod.host in pod.address_in assert pod.host in pod.address_out
def test_head_args_get_set(pod_args): with CompoundPod(pod_args) as pod: assert pod.head_args == pod.replicas_args['head']