Beispiel #1
0
def test_instantiate_link_and_connect_to_broker(mock_pikathread):
    """Test the Pika connection routine."""
    transport = PikaTransport()
    assert not transport.is_connected()

    transport.connect()
    mock_pikathread.start.assert_called_once()
    mock_pikathread.start.side_effect = RuntimeError

    assert transport.is_connected()

    with pytest.raises(RuntimeError):
        transport.connect()

    mock_pikathread.join.assert_not_called()
    assert transport.is_connected()

    transport.disconnect()

    mock_pikathread.join.assert_called_once()
    mock_pikathread.connection_alive = False
    assert not transport.is_connected()

    transport.disconnect()

    assert mock_pikathread.join.call_count == 2
    assert not transport.is_connected()
Beispiel #2
0
def pikatransport(revert_classvariables, connection_params):
    # connection_params is unused here, but implements the fixture skipping
    # logic following a single test, instead of attempting a connection for
    # every individual test.
    pt = PikaTransport()
    pt.connect()
    yield pt
    pt.disconnect()