Пример #1
0
def test_dead_letters_are_emitted_in_the_order_the_messages_were_sent(defer):
    node = DummyNode()
    defer(node.stop)
    a = node.spawn(Actor)
    with expect_one_event(DeadLetter(a, 'dummy1', sender=None)):
        with expect_one_event(DeadLetter(a, 'dummy2', sender=None)):
            a << 'dummy1' << 'dummy2'
            a.stop()
Пример #2
0
def test_dead_letters_are_emitted_in_the_order_the_messages_were_sent(defer):
    node = DummyNode()
    defer(node.stop)
    a = node.spawn(Actor)
    with expect_one_event(DeadLetter(a, 'dummy1', sender=None)):
        with expect_one_event(DeadLetter(a, 'dummy2', sender=None)):
            a << 'dummy1' << 'dummy2'
            a.stop()
Пример #3
0
def test_all_stashed_messages_are_reported_as_unhandled_on_flush_and_discarded(
        defer):
    class MyProc(Actor):
        def run(self):
            self.get('dummy')
            self.flush()
            self.get('dummy')
            self.flush()

    node = DummyNode()
    defer(node.stop)
    p = node.spawn(MyProc)
    p << 'should-be-reported-as-unhandled'
    with expect_event_not_emitted(
            DeadLetter(p, 'should-be-reported-as-unhandled', sender=None)):
        with expect_one_event(
                UnhandledMessage(p,
                                 'should-be-reported-as-unhandled',
                                 sender=None)):
            p << 'dummy'
    with expect_event_not_emitted(
            DeadLetter(p, 'should-be-reported-as-unhandled', sender=None)):
        with expect_event_not_emitted(
                UnhandledMessage(p,
                                 'should-be-reported-as-unhandled',
                                 sender=None)):
            p << 'dummy'
Пример #4
0
 def receive(self, message):
     eq_(message, ('terminated', watchee))
     _, sender = message
     with expect_one_event(DeadLetter(sender, 'dummy', sender=self.ref)):
         sender << 'dummy'
         idle()
     all_ok.set()
Пример #5
0
 def receive(self, message):
     eq_(message, ('terminated', watchee))
     _, sender = message
     with expect_one_event(DeadLetter(sender, 'dummy',
                                      sender=self.ref)):
         sender << 'dummy'
         idle()
     all_ok.set()
Пример #6
0
def test_messages_to_dead_actors_are_sent_to_dead_letters(defer):
    node = DummyNode()
    defer(node.stop)
    a = node.spawn(Actor)
    a.stop()
    with expect_one_event(DeadLetter(a, 'should-end-up-as-letter', sender=None)):
        a << 'should-end-up-as-letter'
        idle()
Пример #7
0
def test_messages_sent_to_nonexistent_remote_actors_are_deadlettered(defer):
    sender_node, receiver_node = (Node('localhost:20001', enable_remoting=True),
                                  Node('localhost:20002', enable_remoting=True))
    defer(sender_node.stop, receiver_node.stop)

    noexist = sender_node.lookup_str('localhost:20002/non-existent-actor')
    with expect_one_event(DeadLetter):
        noexist << 'straight-down-the-drain'
Пример #8
0
def test_messages_to_dead_actors_are_sent_to_dead_letters(defer):
    node = DummyNode()
    defer(node.stop)
    a = node.spawn(Actor)
    a.stop()
    with expect_one_event(DeadLetter(a, 'should-end-up-as-letter',
                                     sender=None)):
        a << 'should-end-up-as-letter'
        idle()
Пример #9
0
def test_messages_sent_to_nonexistent_remote_actors_are_deadlettered(defer):
    sender_node, receiver_node = (Node('localhost:20001',
                                       enable_remoting=True),
                                  Node('localhost:20002',
                                       enable_remoting=True))
    defer(sender_node.stop, receiver_node.stop)

    noexist = sender_node.lookup_str('localhost:20002/non-existent-actor')
    with expect_one_event(DeadLetter):
        noexist << 'straight-down-the-drain'
Пример #10
0
def test_unhandled_message_is_reported(defer):
    # Unhandled messages are reported to Events
    class MyActor(Actor):
        def receive(self, _):
            raise Unhandled
    node = DummyNode()
    defer(node.stop)
    a = node.spawn(MyActor)
    with expect_one_event(UnhandledMessage(a, 'foo', sender=None)):
        a << 'foo'
Пример #11
0
def test_unhandled_message_is_reported(defer):
    # Unhandled messages are reported to Events
    class MyActor(Actor):
        def receive(self, _):
            raise Unhandled

    node = DummyNode()
    defer(node.stop)
    a = node.spawn(MyActor)
    with expect_one_event(UnhandledMessage(a, 'foo', sender=None)):
        a << 'foo'
Пример #12
0
def test_sending_to_an_unknown_node_doesnt_start_if_the_node_doesnt_become_visible_and_the_message_is_later_dropped(
        defer):
    sender_node = Node('localhost:20001',
                       enable_remoting=True,
                       hub_kwargs={
                           'heartbeat_interval': 0.05,
                           'heartbeat_max_silence': 0.1
                       })
    defer(sender_node.stop)
    ref = sender_node.lookup_str('localhost:23456/actor2')
    with expect_one_event(DeadLetter(ref, 'bar', sender=None)):
        ref << 'bar'
Пример #13
0
def test_stopping_in_pre_start_directs_any_refs_to_deadletters(defer):
    class MyActor(Actor):
        def pre_start(self):
            self.stop()

        def receive(self, message):
            message_received.set()

    node = DummyNode()
    defer(node.stop)
    message_received = Event()
    a = node.spawn(MyActor)
    with expect_one_event(DeadLetter(a, 'dummy', sender=None)):
        a << 'dummy'
    ok_(not message_received.is_set())
Пример #14
0
def test_stopping_in_pre_start_directs_any_refs_to_deadletters(defer):
    class MyActor(Actor):
        def pre_start(self):
            self.stop()

        def receive(self, message):
            message_received.set()

    node = DummyNode()
    defer(node.stop)
    message_received = Event()
    a = node.spawn(MyActor)
    with expect_one_event(DeadLetter(a, 'dummy', sender=None)):
        a << 'dummy'
    ok_(not message_received.is_set())
Пример #15
0
def test_stopping_an_actor_prevents_it_from_processing_any_more_messages(defer):
    class MyActor(Actor):
        def receive(self, _):
            received.set()
    node = DummyNode()
    defer(node.stop)
    received = Event()
    a = node.spawn(MyActor)
    a << None
    received.wait()
    received.clear()
    a.stop()
    sleep(.001)
    ok_(not received.is_set(), "the '_stop' message should not be receivable in the actor")
    with expect_one_event(DeadLetter(a, None, sender=None)):
        a << None
Пример #16
0
def test_all_stashed_messages_are_reported_as_unhandled_on_flush_and_discarded(defer):
    class MyProc(Actor):
        def run(self):
            self.get('dummy')
            self.flush()
            self.get('dummy')
            self.flush()
    node = DummyNode()
    defer(node.stop)
    p = node.spawn(MyProc)
    p << 'should-be-reported-as-unhandled'
    with expect_event_not_emitted(DeadLetter(p, 'should-be-reported-as-unhandled', sender=None)):
        with expect_one_event(UnhandledMessage(p, 'should-be-reported-as-unhandled', sender=None)):
            p << 'dummy'
    with expect_event_not_emitted(DeadLetter(p, 'should-be-reported-as-unhandled', sender=None)):
        with expect_event_not_emitted(UnhandledMessage(p, 'should-be-reported-as-unhandled', sender=None)):
            p << 'dummy'
Пример #17
0
def test_sending_message_to_stopping_parent_from_post_stop_should_deadletter_the_message(defer):
    class Parent(Actor):
        def pre_start(self):
            self.spawn(Child)

        def receive(self, message):
            ok_(False)

    class Child(Actor):
        def post_stop(self):
            self._parent << 'should-not-be-received'

    node = DummyNode()
    defer(node.stop)
    p = node.spawn(Parent)
    with expect_one_event(DeadLetter(ANY, ANY, sender=ANY)):
        p.stop()
        idle()
Пример #18
0
def test_sending_message_to_stopping_parent_from_post_stop_should_deadletter_the_message(
        defer):
    class Parent(Actor):
        def pre_start(self):
            self.spawn(Child)

        def receive(self, message):
            ok_(False)

    class Child(Actor):
        def post_stop(self):
            self._parent << 'should-not-be-received'

    node = DummyNode()
    defer(node.stop)
    p = node.spawn(Parent)
    with expect_one_event(DeadLetter(ANY, ANY, sender=ANY)):
        p.stop()
        idle()
Пример #19
0
def test_stopping_an_actor_prevents_it_from_processing_any_more_messages(
        defer):
    class MyActor(Actor):
        def receive(self, _):
            received.set()

    node = DummyNode()
    defer(node.stop)
    received = Event()
    a = node.spawn(MyActor)
    a << None
    received.wait()
    received.clear()
    a.stop()
    sleep(.001)
    ok_(not received.is_set(),
        "the '_stop' message should not be receivable in the actor")
    with expect_one_event(DeadLetter(a, None, sender=None)):
        a << None
Пример #20
0
def test_with_no_receive_method_all_messages_are_unhandled(defer):
    node = DummyNode()
    defer(node.stop)
    a = node.spawn(Actor)
    with expect_one_event(UnhandledMessage(a, 'dummy', sender=None)):
        a << 'dummy'
Пример #21
0
def test_with_no_receive_method_all_messages_are_unhandled(defer):
    node = DummyNode()
    defer(node.stop)
    a = node.spawn(Actor)
    with expect_one_event(UnhandledMessage(a, 'dummy', sender=None)):
        a << 'dummy'
Пример #22
0
def test_unhandled_message_to_guardian_is_also_reported(defer):
    node = DummyNode()
    defer(node.stop)
    guardian = node.guardian
    with expect_one_event(UnhandledMessage(guardian, 'foo', sender=None)):
        guardian << 'foo'
Пример #23
0
def test_sending_to_an_unknown_node_doesnt_start_if_the_node_doesnt_become_visible_and_the_message_is_later_dropped(defer):
    sender_node = Node('localhost:20001', enable_remoting=True, hub_kwargs={'heartbeat_interval': 0.05, 'heartbeat_max_silence': 0.1})
    defer(sender_node.stop)
    ref = sender_node.lookup_str('localhost:23456/actor2')
    with expect_one_event(DeadLetter(ref, 'bar', sender=None)):
        ref << 'bar'
Пример #24
0
def test_unhandled_message_to_guardian_is_also_reported(defer):
    node = DummyNode()
    defer(node.stop)
    guardian = node.guardian
    with expect_one_event(UnhandledMessage(guardian, 'foo', sender=None)):
        guardian << 'foo'