示例#1
0
def test_agentchannel_async_rep():
    """
    Test basic ASYNC_REP AgentChannel operations: initialization, equivalence
    and basic methods.
    """
    receiver = AgentAddress('ipc', 'addr0', 'PULL', 'server', 'pickle')
    channel = AgentChannel('ASYNC_REP', receiver=receiver, sender=None)
    # Equivalence
    assert channel == AgentChannel('ASYNC_REP', receiver=receiver, sender=None)
    assert not channel == 'foo'
    assert channel != 'foo'
    # Basic methods
    assert channel.twin() == AgentChannel('ASYNC_REQ', sender=receiver.twin(),
                                          receiver=None)
    # Other attributes
    assert hasattr(channel, 'uuid')
    assert channel.transport == 'ipc'
    assert channel.serializer == 'pickle'
示例#2
0
def test_agentchannel_async_rep():
    """
    Test basic ASYNC_REP AgentChannel operations: initialization, equivalence
    and basic methods.
    """
    receiver = AgentAddress('ipc', 'addr0', 'PULL', 'server', 'pickle')
    channel = AgentChannel('ASYNC_REP', receiver=receiver, sender=None)
    # Equivalence
    assert channel == AgentChannel('ASYNC_REP', receiver=receiver, sender=None)
    assert not channel == 'foo'
    assert channel != 'foo'
    # Basic methods
    assert channel.twin() == AgentChannel(
        'ASYNC_REQ', sender=receiver.twin(), receiver=None
    )
    # Other attributes
    assert hasattr(channel, 'uuid')
    assert channel.transport == 'ipc'
    assert channel.serializer == 'pickle'
示例#3
0
def test_agentchannel_sync_pub():
    """
    Test basic SYNC_PUB AgentChannel operations: initialization, equivalence
    and basic methods.
    """
    sender = AgentAddress('ipc', 'addr0', 'PUB', 'server', 'pickle')
    receiver = AgentAddress('ipc', 'addr0', 'PULL', 'server', 'pickle')
    channel = AgentChannel('SYNC_PUB', sender=sender, receiver=receiver)
    # Equivalence
    assert channel == AgentChannel('SYNC_PUB', sender=sender,
                                   receiver=receiver)
    assert not channel == 'foo'
    assert channel != 'foo'
    # Basic methods
    assert channel.twin() == AgentChannel('SYNC_SUB', sender=receiver.twin(),
                                          receiver=sender.twin())
    # Other attributes
    assert hasattr(channel, 'uuid')
    assert channel.transport == 'ipc'
    assert channel.serializer == 'pickle'
示例#4
0
def test_agentchannel_sync_pub():
    """
    Test basic SYNC_PUB AgentChannel operations: initialization, equivalence
    and basic methods.
    """
    sender = AgentAddress('ipc', 'addr0', 'PUB', 'server', 'pickle')
    receiver = AgentAddress('ipc', 'addr0', 'PULL', 'server', 'pickle')
    channel = AgentChannel('SYNC_PUB', sender=sender, receiver=receiver)
    # Equivalence
    assert channel == AgentChannel(
        'SYNC_PUB', sender=sender, receiver=receiver
    )
    assert not channel == 'foo'
    assert channel != 'foo'
    # Basic methods
    assert channel.twin() == AgentChannel(
        'SYNC_SUB', sender=receiver.twin(), receiver=sender.twin()
    )
    # Other attributes
    assert hasattr(channel, 'uuid')
    assert channel.transport == 'ipc'
    assert channel.serializer == 'pickle'
示例#5
0
def test_agentchannel_uuid():
    """
    An AgentChannel's unique identifier must never contain the
    `osbrain.TOPIC_SEPARATOR` to avoid errors when using this identifier as
    topic in PUB-SUB communication patterns.
    """
    sender = AgentAddress('ipc', 'addr0', 'PUB', 'server', 'pickle')
    receiver = AgentAddress('ipc', 'addr0', 'PULL', 'server', 'pickle')
    for _ in range(1000):
        channel = AgentChannel('SYNC_PUB', sender=sender, receiver=receiver)
        identifier = channel.uuid
        assert isinstance(identifier, bytes)
        assert TOPIC_SEPARATOR not in identifier