def test_publish_subscribe_multiple_socket_network():
    """
    Creates several sockets on the same network and verifies that publishes make
    it to all sockets
    """
    cb = get_callback()

    sockets = LocalSocket.get_sockets(10)
    # each socket has their own callback
    callbacks = [get_callback() for s in sockets]

    # subscribe all sockets to their corresponding callbacks
    for s, cb, i in zip(sockets, callbacks, range(len(sockets))):
        s._subscribe(i, cb)

    sockets[1]._publish(11, b"hello world")
    for cb in callbacks:
        assert cb.log == []

    sockets[1]._publish(2, b"hello world")
    for i, cb in zip(range(len(callbacks)), callbacks):
        if i == 2:
            assert cb.log == [(sockets[2], 2, b"hello world")]
        else:
            assert cb.log == []

    sockets[1]._publish(5, b"hello world")
    sockets[1]._publish(5, b"hello world")
    assert callbacks[5].log == 2 * [(sockets[5], 5, b"hello world")]

    sockets[5]._publish(8, b"hello world")
    assert callbacks[8].log == [(sockets[8], 8, b"hello world")]

    sockets[4]._publish(4, b"hello world")
    assert callbacks[4].log == []  # does not look at local subscribers
예제 #2
0
def test_use_socket_one_location():
    """
    Verify that a provided socket can be used by a location
    """
    l = Location(1)
    s = LocalSocket.get_sockets(1)[0]
    l.use(s)
def test_publish():
    """
    Ensures that _publish method of hmap.sockets.AbstractSocket works in the
    most basic capacity
    """
    s = LocalSocket.get_sockets(1)[0]
    s._publish(2, b"message in a bottle")
def test_subscribe():
    """
    Ensures that _subscribe method of hmap.sockets.AbstractSocket works in the
    most basic capacity
    """
    s = LocalSocket.get_sockets(1)[0]
    s._subscribe(2, None)
예제 #5
0
def test_use_socket_multiple_times_on_location():
    """
    Verify that one socket used more than once on a location raises an error
    """
    l = Location(1)
    s = LocalSocket.get_sockets(1)[0]
    l.use(s)
def test_use_sockets_one_destination():
    """
    Verify multiple sockets can be used by one destination
    """
    sockets = LocalSocket.get_sockets(10)
    d = Destination(1)
    for s in sockets:
        d.use(s)
def test_use_socket_multiple_destination():
    """
    Verify that one socket can be used for multiple destinations
    """
    destinations = get_destinations(10)
    s = LocalSocket.get_sockets(1)[0]
    for d in destinations:
        d.use(s)
예제 #8
0
def test_use_sockets_one_location():
    """
    Verify multiple sockets can be used by one location
    """
    sockets = LocalSocket.get_sockets(10)
    l = Location(1)
    for s in sockets:
        l.use(s)
예제 #9
0
def test_use_socket_multiple_locations():
    """
    Verify that one socket can be used for multiple locations
    """
    locations = get_locations(10)
    s = LocalSocket.get_sockets(1)[0]
    for l in locations:
        l.use(s)
def test_use_sockets_multiple_destination_with_overlap():
    """
    Verify multiple sockets can be used by multiple destinations
    """
    destinations = get_destinations(10)
    sockets = LocalSocket.get_sockets(10)
    for d in destinations:
        for s in sockets:
            d.use(s)
예제 #11
0
def test_use_sockets_multiple_location_with_overlap():
    """
    Verify multiple sockets can be used by multiple locations
    """
    locations = get_locations(10)
    sockets = LocalSocket.get_sockets(10)
    for l in locations:
        for s in sockets:
            l.use(s)
def test_use_socket_multiple_times_on_destination():
    """
    Verify that one socket used more than once on a destination raises an error
    """
    d = Destination(1)
    s = LocalSocket.get_sockets(1)[0]
    d.use(s)
    try:
        d.use(s)
    except ValueError:
        assert True
    else:
        assert False
def test_publish_subscribe_2_socket_network():
    """
    Create two sockets and have one publish data and the other receive that
    data
    """
    cb = get_callback()

    sockets = LocalSocket.get_sockets(2)
    sockets[1]._subscribe(2, cb)
    p_count = 10
    for i in range(p_count):
        sockets[0]._publish(2, b"hello world")
    assert cb.log == [(sockets[1], 2, b"hello world")] * 10
def test_subscribe_value_error():
    """
    Ensures that _subscribe method of hmap.sockets.AbstractSocket raises a value
    error when more than one subscriber is being added for one id...
    """
    s = LocalSocket.get_sockets(1)[0]
    s._subscribe(2, None)
    try:
        s._subscribe(2, None)
    except ValueError:
        assert True
    else:
        assert False
예제 #15
0
def test_use_socket_one_location_over_use():
    """
    Verify that a provided socket can be used by a location
    """
    l = Location(1)
    s = LocalSocket.get_sockets(1)[0]
    l.use(s)
    try:
        l.use(s)
    except ValueError:
        assert True
    else:
        assert False
def test_use_socket_one_destination():
    """
    Verify that a provided socket can be used by a destination
    """
    d = Destination(1)
    s = LocalSocket.get_sockets(1)[0]
    d.use(s)
    try:
        d.use(s)
    except ValueError:
        assert True
    else:
        assert False
예제 #17
0
def test_use_socket_one_duplicate_location():
    """
    Verify that a value error is raised when two location instances with the
    same id (not inherently bad) use the same socket
    """
    l_1 = Location(1)
    l_2 = Location(1)
    s = LocalSocket.get_sockets(1)[0]
    l_1.use(s)
    try:
        l_2.use(s)
    except ValueError:
        assert True
    else:
        assert False
def test_initialization():
    """
    Ensures that local sockets can be created
    """
    sockets = LocalSocket.get_sockets(10)