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 = ReportSession( ioloop=self._ioloop, script_path=self._script_path, command_line=self._command_line, uploaded_file_manager=self._uploaded_file_mgr, ) 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()
def test_shutdown(self, _1): """Test that ReportSession.shutdown behaves sanely.""" file_mgr = MagicMock(spec=UploadedFileManager) rs = ReportSession(None, "", "", file_mgr) rs.shutdown() self.assertEqual(ReportSessionState.SHUTDOWN_REQUESTED, rs._state) file_mgr.remove_session_files.assert_called_once_with(rs.id) # A 2nd shutdown call should have no effect. rs.shutdown() self.assertEqual(ReportSessionState.SHUTDOWN_REQUESTED, rs._state) file_mgr.remove_session_files.assert_called_once_with(rs.id)