Ejemplo n.º 1
0
    async def does_script_run_without_error(self) -> Tuple[bool, str]:
        """Load and execute the app's script to verify it runs without an error.

        Returns
        -------
        (True, "ok") if the script completes without error, or (False, err_msg)
        if the script raises an exception.
        """
        session_data = SessionData(self._main_script_path, self._command_line)
        local_sources_watcher = LocalSourcesWatcher(session_data)
        session = AppSession(
            ioloop=self._ioloop,
            session_data=session_data,
            uploaded_file_manager=self._uploaded_file_mgr,
            message_enqueued_callback=self._enqueued_some_message,
            local_sources_watcher=local_sources_watcher,
        )

        try:
            session.request_rerun(None)

            now = time.perf_counter()
            while (SCRIPT_RUN_WITHOUT_ERRORS_KEY not in session.session_state
                   and (time.perf_counter() - now) < SCRIPT_RUN_CHECK_TIMEOUT):
                await tornado.gen.sleep(0.1)

            if SCRIPT_RUN_WITHOUT_ERRORS_KEY not in session.session_state:
                return False, "timeout"

            ok = session.session_state[SCRIPT_RUN_WITHOUT_ERRORS_KEY]
            msg = "ok" if ok else "error"

            return ok, msg
        finally:
            session.shutdown()
Ejemplo n.º 2
0
    def test_shutdown(self, _, patched_disconnect):
        """Test that AppSession.shutdown behaves sanely."""
        file_mgr = MagicMock(spec=UploadedFileManager)
        rs = AppSession(None, SessionData("", ""), file_mgr, None, MagicMock())

        rs.shutdown()
        self.assertEqual(AppSessionState.SHUTDOWN_REQUESTED, rs._state)
        file_mgr.remove_session_files.assert_called_once_with(rs.id)
        patched_disconnect.assert_called_once_with(rs._on_secrets_file_changed)

        # A 2nd shutdown call should have no effect.
        rs.shutdown()
        self.assertEqual(AppSessionState.SHUTDOWN_REQUESTED, rs._state)
        file_mgr.remove_session_files.assert_called_once_with(rs.id)
Ejemplo n.º 3
0
    def test_shutdown(self, patched_disconnect):
        """Test that AppSession.shutdown behaves sanely."""
        file_mgr = MagicMock(spec=UploadedFileManager)
        session = AppSession(
            ioloop=MagicMock(),
            session_data=SessionData("", ""),
            uploaded_file_manager=file_mgr,
            message_enqueued_callback=None,
            local_sources_watcher=MagicMock(),
        )

        session.shutdown()
        self.assertEqual(AppSessionState.SHUTDOWN_REQUESTED, session._state)
        file_mgr.remove_session_files.assert_called_once_with(session.id)
        patched_disconnect.assert_called_once_with(session._on_secrets_file_changed)

        # A 2nd shutdown call should have no effect.
        session.shutdown()
        self.assertEqual(AppSessionState.SHUTDOWN_REQUESTED, session._state)
        file_mgr.remove_session_files.assert_called_once_with(session.id)