From 69c082d2bf9b9985db77d1d25a3f423ecf016e00 Mon Sep 17 00:00:00 2001 From: Pyifan <37059868+Pyifan@users.noreply.github.com> Date: Wed, 30 Aug 2023 16:08:29 +0800 Subject: [PATCH] fix minor issues of interactive mode (#988) * fix minor issues of interactive mode * fix 400 Bad Request: Cannot update runtime status of entry from waiting to running --------- Co-authored-by: Yifan Zhang --- testplan/common/entity/base.py | 4 +++- testplan/runnable/interactive/http.py | 15 ++++++++++++--- testplan/runnable/interactive/reloader.py | 7 ++++--- .../testplan/runnable/interactive/test_api.py | 4 +++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/testplan/common/entity/base.py b/testplan/common/entity/base.py index a1ebc51e6..11d9bc813 100644 --- a/testplan/common/entity/base.py +++ b/testplan/common/entity/base.py @@ -1678,7 +1678,9 @@ def run(self): break_join=lambda: self.aborted is True, ) if self._runnable.interactive is not None: - return self._runnable.interactive + # for testing purpose + if self.cfg.interactive_block is False: + return self._runnable.interactive if isinstance(self._runnable.result, Exception): raise self._runnable.result return self._runnable.result diff --git a/testplan/runnable/interactive/http.py b/testplan/runnable/interactive/http.py index affa83385..cc2798786 100644 --- a/testplan/runnable/interactive/http.py +++ b/testplan/runnable/interactive/http.py @@ -827,14 +827,23 @@ def _should_run(uid, curr_status, new_status): """ if new_status == curr_status: return False + + # test entry already triggered + elif ( + new_status == RuntimeStatus.RUNNING + and curr_status == RuntimeStatus.WAITING + ): + return False + elif new_status == RuntimeStatus.RUNNING: - if curr_status not in (RuntimeStatus.RESETTING, RuntimeStatus.WAITING): - return True - else: + + if curr_status == RuntimeStatus.RESETTING: raise werkzeug.exceptions.BadRequest( "Cannot update runtime status of entry" f' "{uid}" from "{curr_status}" to "{new_status}"' ) + return True + return False diff --git a/testplan/runnable/interactive/reloader.py b/testplan/runnable/interactive/reloader.py index aeeca0102..dd9a34256 100644 --- a/testplan/runnable/interactive/reloader.py +++ b/testplan/runnable/interactive/reloader.py @@ -198,10 +198,11 @@ def _build_dep_graph(self, main_module_file, reload_dirs): try: with io.open(main_module_file, "r") as fp: text = fp.read() - except OSError: + except OSError as exc: raise RuntimeError( - "Could not run main module {} as a script.".format( - main_module_file + "Could not run main module {} as a script: {}.".format( + main_module_file, + exc, ) ) else: diff --git a/tests/unit/testplan/runnable/interactive/test_api.py b/tests/unit/testplan/runnable/interactive/test_api.py index a72e4f91a..15e138561 100644 --- a/tests/unit/testplan/runnable/interactive/test_api.py +++ b/tests/unit/testplan/runnable/interactive/test_api.py @@ -368,7 +368,9 @@ def test_put_validation(self, api_env): rsp = client.put(api_url, json=json_test) assert rsp.status_code == 200 rsp = client.put(api_url, json=json_test) - assert rsp.status_code == 400 + assert rsp.status_code == 200 + json_rsp = rsp.get_json() + assert json_rsp["runtime_status"] == report.RuntimeStatus.WAITING class TestAllSuites: