def test_get_stream_new_without_transport(self): node_a, node_b = MockNode(), MockNode() session_mock = MockSession(MockNetwork()) session_mock._id = "1" session_mock.closed = False session_mock.closing_mode = None transport_mock = ZeroTransport(MockConnector()) def transport_factory(_): return transport_mock transport_factory_mock = mock.MagicMock(side_effect=transport_factory) ZeroPipe.set_transport_factory(transport_factory_mock) pipe = ZeroPipe(node_a, node_b) ZeroStream.load = load ZeroStream.save = mock.MagicMock() stream = pipe.get_stream(session_mock) ZeroStream.save.assert_called_once_with(save_dependency=False) ZeroPipe._transport_factory.assert_called_once_with(pipe) assert stream.transport == transport_mock
def test_set_transport_factory_as_transport(self): node_a, node_b = MockNode(), MockNode() pipe = ZeroPipe(node_a, node_b) transport = ZeroTransport(MockConnector()) pipe.set_transport_factory(transport) assert pipe._transport_factory() == transport
def config_transport(): def connections_factory(connector, stream): return connector.connect("{}/{}".format(stream.session.id, stream.id)) def transport_factory(pipe): connector = PersistQueueConnector("/tmp/tethys/queues/{}/".format( pipe.id)) return ZeroTransport(connector, connections_factory) ZeroPipe.set_transport_factory(transport_factory)
def test_set_transport_factory_and_create_pipe(self): node_a, node_b = MockNode(), MockNode() transport = ZeroTransport(MockConnector()) transport_factory = mock.MagicMock( side_effect=lambda *_, **__: transport) ZeroPipe.set_transport_factory(transport_factory) pipe = ZeroPipe(node_a, node_b) assert ZeroPipe._transport_factory == transport_factory assert pipe.transport == transport ZeroPipe._transport_factory.assert_called_once_with(pipe)