def test_sad_path_events(self, ses, fail_script):
        """
        Verify that OET events are published at the appropriate times for a
        script that raises an exception.
        """
        helper = PubSubHelper()

        prepare_cmd = PrepareProcessCommand(script=fail_script,
                                            init_args=ProcedureInput())
        summary = ses.prepare(prepare_cmd)

        helper.wait_for_message_on_topic(topics.procedure.lifecycle.created,
                                         timeout=3.0)
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.created)) == 1
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.started)) == 0
        assert len(
            helper.messages_on_topic(topics.procedure.lifecycle.complete)) == 0
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.failed)) == 0
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.stopped)) == 0

        run_cmd = StartProcessCommand(process_uid=summary.id,
                                      fn_name="main",
                                      run_args=ProcedureInput(msg="foo"))
        _ = ses.start(run_cmd)

        helper.wait_for_message_on_topic(topics.procedure.lifecycle.stacktrace,
                                         timeout=3.0)
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.created)) == 1
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.started)) == 1
        assert len(
            helper.messages_on_topic(topics.procedure.lifecycle.complete)) == 0
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.failed)) == 1
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.stopped)) == 0

        filtered = [
            t for t in helper.topic_list
            if t != topics.procedure.lifecycle.statechange
        ]
        assert filtered == [
            topics.procedure.lifecycle.created,
            topics.procedure.lifecycle.started,
            topics.procedure.lifecycle.failed,
            topics.procedure.lifecycle.stacktrace,
        ]
Пример #2
0
 def assert_states(helper: PubSubHelper, pid: int,
                   expected: List[ProcedureState]):
     msgs = helper.messages_on_topic(topics.procedure.lifecycle.statechange)
     states = [
         msg["new_state"] for msg in msgs if int(msg["msg_src"]) == pid
     ]
     assert states == expected
Пример #3
0
    def test_internal_messages_not_republished(self, mp, caplog):
        """
        Verify that message event is not published if the event originates from
        an internal source.
        """
        helper = PubSubHelper()

        work_q = MPQueue(ctx=mp)
        # TEST is the default component name assigned in
        # _proc_worker_wrapper_helper. This message should not be published to pypubsub
        msg = EventMessage(
            "TEST",
            "PUBSUB",
            dict(topic=topics.request.procedure.list,
                 kwargs={"request_id": "123"}),
        )
        work_q.put(msg)

        _proc_worker_wrapper_helper(mp,
                                    caplog,
                                    ScriptWorker,
                                    args=(work_q, ),
                                    expect_shutdown_evt=True)

        msgs_on_topic = helper.messages_on_topic(topics.request.procedure.list)
        assert len(msgs_on_topic) == 0
Пример #4
0
    def test_events_emitted_from_scripts_are_republished(
            self, manager, pubsub_script):
        """
        Verify that OET events are published at the appropriate times for a
        sad-path script.
        """
        helper = PubSubHelper()

        pid = manager.create(pubsub_script, init_args=ProcedureInput())
        wait_for_state(manager, pid, ProcedureState.READY)

        manager.run(pid, call="main", run_args=ProcedureInput(msg="foo"))
        helper.wait_for_message_on_topic(topics.user.script.announce)
        user_msgs = helper.messages_on_topic(topics.user.script.announce)
        assert len(user_msgs) == 1
    def test_stop_events(self, ses, init_hang_script):
        """
        Verify the behaviour of SES.stop(), confirming that OET events are published
        at the appropriate times when a script is terminated.
        """
        helper = PubSubHelper()

        init_running = multiprocessing.Barrier(2)
        prepare_cmd = PrepareProcessCommand(
            script=init_hang_script, init_args=ProcedureInput(init_running))
        summary = ses.prepare(prepare_cmd)
        pid = summary.id
        ses._wait_for_state(pid, ProcedureState.IDLE)

        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.created)) == 1
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.started)) == 1
        assert len(
            helper.messages_on_topic(topics.procedure.lifecycle.complete)) == 0
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.failed)) == 0
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.stopped)) == 0

        init_running.wait(0.1)
        ses._wait_for_state(pid, ProcedureState.READY)

        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.created)) == 1
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.started)) == 1
        assert len(
            helper.messages_on_topic(topics.procedure.lifecycle.complete)) == 0
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.failed)) == 0
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.stopped)) == 0

        stop_cmd = StopProcessCommand(process_uid=pid, run_abort=False)
        _ = ses.stop(stop_cmd)
        ses._wait_for_state(pid, ProcedureState.STOPPED)

        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.created)) == 1
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.started)) == 1
        assert len(
            helper.messages_on_topic(topics.procedure.lifecycle.complete)) == 0
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.failed)) == 0
        assert len(helper.messages_on_topic(
            topics.procedure.lifecycle.stopped)) == 1

        filtered = [
            t for t in helper.topic_list
            if t != topics.procedure.lifecycle.statechange
        ]
        assert filtered == [
            topics.procedure.lifecycle.created,
            topics.procedure.lifecycle.started,
            topics.procedure.lifecycle.stopped,
        ]