def test_connect_to_predecessor(): f = Flow().add(name='pod1').add(name='pod2', connect_to_predecessor=True) f.build() assert len(f._pod_nodes['gateway'].head_args.hosts_in_connect) == 0 assert len(f._pod_nodes['pod1'].head_args.hosts_in_connect) == 0 assert len(f._pod_nodes['pod2'].head_args.hosts_in_connect) == 1
def test_remote_pod_local_gateway(local_ip, on_public): # BIND socket's host must always be 0.0.0.0 remote_ip = '111.111.111.111' f = Flow(expose_public=on_public).add(host=remote_ip, name='executor1') f.build() assert ip_from(f, 'start-gateway') == __default_host__ assert ip_from(f, 'executor1') == remote_ip assert ip_from(f, 'end-gateway') == ip_from(f, 'start-gateway')
def test_socket_types_2_remote_one_local(): f = Flow().add(name='pod1', host='0.0.0.1'). \ add(name='pod2', parallel=2, host='0.0.0.2'). \ add(name='pod3', parallel=2, host='1.2.3.4', needs=['gateway']). \ join(name='join', needs=['pod2', 'pod3']) f.build() assert f._pod_nodes['join'].head_args.socket_in == SocketType.PULL_BIND assert f._pod_nodes['pod2'].tail_args.socket_out == SocketType.PUSH_CONNECT assert f._pod_nodes['pod3'].tail_args.socket_out == SocketType.PUSH_CONNECT
def test_remote_pod_local_gateway(local_ip, on_public): # BIND socket's host must always be 0.0.0.0 remote_ip = '111.111.111.111' f = Flow(expose_public=on_public).add(host=remote_ip) f.build() for k, v in f: print(f'{v.name}\tIN: {v.address_in}\t{v.address_out}') assert f['pod0'].host_in == __default_host__ assert f['pod0'].host_out == __default_host__ assert f['gateway'].host_in == remote_ip assert f['gateway'].host_out == remote_ip
def test_remote_pod_local_pod_local_gateway(local_ip, on_public): remote_ip = '111.111.111.111' f = Flow(expose_public=on_public).add(host=remote_ip).add() f.build() for k, v in f._pod_nodes.items(): print(f'{v.name}\tIN: {v.address_in}\t{v.address_out}') assert f['pod0'].host_in == __default_host__ assert f['pod0'].host_out == local_ip assert f['pod1'].host_in == __default_host__ assert f['pod1'].host_out == __default_host__ assert f['gateway'].host_in == __default_host__ assert f['gateway'].host_out == remote_ip
def test_socket_types_2_remote_one_local_input_socket_pull_connect_from_remote(): f = Flow().add(name='pod1', host='0.0.0.1'). \ add(name='pod2', parallel=2, host='0.0.0.2'). \ add(name='pod3', parallel=2, host='1.2.3.4', needs=['gateway']). \ join(name='join', needs=['pod2', 'pod3']) f.build() for k, v in f: print(f'{v.name}\tIN: {v.address_in}\t{v.address_out}') assert f._pod_nodes['join'].head_args.socket_in == SocketType.PULL_BIND assert f._pod_nodes['pod2'].tail_args.socket_out == SocketType.PUSH_CONNECT assert f._pod_nodes['pod3'].tail_args.socket_out == SocketType.PUSH_CONNECT
def test_two_flow_using_on_same_build_succed(port_generator): # hacky test but there is now good way to wait that a flow exit port = port_generator() f1 = Flow(port=port) f2 = Flow(port=port) with f1: f2.build() with pytest.raises(PortAlreadyUsed): with f2: pass
def test_local_pod_remote_pod_remote_pod_local_gateway(local_ip, on_public): remote1 = '111.111.111.111' remote2 = '222.222.222.222' f = Flow(expose_public=on_public).add().add(host=remote1).add(host=remote2) f.build() for k, v in f: print(f'{v.name}\tIN: {v.address_in}\t{v.address_out}') assert f['pod0'].host_in == __default_host__ assert f['pod0'].host_out == remote1 assert f['pod1'].host_in == __default_host__ assert f['pod1'].host_out == remote2 assert f['pod2'].host_in == __default_host__ assert f['pod2'].host_out == __default_host__ assert f['gateway'].host_in == remote2 assert f['gateway'].host_out == __default_host__
def test_disable_monitoring_on_gatway_only(port_generator, get_executor): port0 = port_generator() port1 = port_generator() f = Flow(monitoring=False, port_monitoring=port0).add( uses=get_executor(), port_monitoring=port1, monitoring=True, ) f = f.build() assert not f._deployment_nodes['gateway'].pod_args['pods'][0][0].monitoring assert f._deployment_nodes['executor0'].pod_args['pods'][0][0].monitoring