Skip to content

Commit

Permalink
fix minor issues of interactive mode (#988)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Pyifan and Yifan Zhang authored Aug 30, 2023
1 parent 7fa3d3f commit 69c082d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion testplan/common/entity/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions testplan/runnable/interactive/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
7 changes: 4 additions & 3 deletions testplan/runnable/interactive/reloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/testplan/runnable/interactive/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 69c082d

Please sign in to comment.