예제 #1
0
def test_one_pub_many_sub(Transceiver):
    """
    Get one publisher instance and many subscribers and verify that the 
    messages are published to all subscribers
    """
    TOPIC = 10
    DIFF_TOPIC = 11
    p = Publisher(TOPIC)

    sub_callbacks = [get_callback() for _ in range(10)]
    subs = [Subscriber(TOPIC, cb) for cb in sub_callbacks]

    diff_sub_callbacks = [get_callback() for _ in range(10)]
    diff_subs = [Subscriber(DIFF_TOPIC, cb) for cb in diff_sub_callbacks]
    Transceiver.connect([p] + subs + diff_subs)

    p.publish(b"hello")
    for cb in sub_callbacks:
        assert cb.log == [b"hello"]
    for cb in diff_sub_callbacks:
        assert cb.log == []

    p.publish(b"goodbye")
    for cb in sub_callbacks:
        assert cb.log == [b"hello", b"goodbye"]
    for cb in diff_sub_callbacks:
        assert cb.log == []
def test_publish_no_transceiver():
    """
    Verify publisher can publish even with no means of transceiver. May want to
    consider raising an error if publish is called with no tranceiver...
    """
    p = Publisher(5)
    p.publish(b"hello world")
def test_publish_one_transceiver(Transceiver):
    """
    Verify publish works with when using one tranceiver
    """
    p = Publisher(5)
    t = Transceiver()
    p.use(t)
    p.publish(b"hello world")
def test_publish_many_transceivers(Transceiver):
    """
    Verify publish works with when using multiple tranceivers
    """
    p = Publisher(5)
    ts = [Transceiver() for _ in range(10)]
    for t in ts:
        p.use(t)
    p.publish(b"goodbye yellow brick road")
예제 #5
0
def test_one_pub_one_sub_one_connection(Transceiver):
    """
    Get one publisher instance and one subscriber instance and connect them
    over the same topic and confirm that messages get sent 
    """
    TOPIC = 10
    p = Publisher(TOPIC)
    cb = get_callback()
    s = Subscriber(TOPIC, cb)
    Transceiver.connect([p, s])
    p.publish(b"hello")
    assert cb.log == [b"hello"]
    p.publish(b"goodbye")
    assert cb.log == [b"hello", b"goodbye"]
예제 #6
0
def test_one_pub_one_sub_many_connections(Transceiver):
    """
    Get one publisher instance and one subscriber instance and connect them
    with multiple transceivers and verify that the message only gets delivered
    once... is that a property we want to enforce to some capacity?
    """
    TOPIC = 10
    p = Publisher(TOPIC)
    cb = get_callback()
    s = Subscriber(TOPIC, cb)
    for i in range(10):
        Transceiver.connect([p, s])
    p.publish(b"hello")
    assert cb.log == [b"hello"]
    p.publish(b"goodbye")
    assert cb.log == [b"hello", b"goodbye"]