Skip to content

Commit

Permalink
first getReport of interactive mode to load full report
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyifan committed Jan 3, 2025
1 parent 2800cca commit 1f96aeb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
11 changes: 7 additions & 4 deletions testplan/runnable/interactive/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ class Report(flask_restx.Resource):

def get(self):
"""Get the state of the root interactive report."""
full = flask.request.args.get("full", "false").lower() == "true"
with ihandler.report_mutex:
return _serialize_report_entry(ihandler.report)
return _serialize_report_entry(ihandler.report, full=full)

def put(self):
"""Update the state of the root interactive report."""
Expand Down Expand Up @@ -752,16 +753,18 @@ def _validate_json_body(json_body: Dict) -> None:
if json_body is None:
raise werkzeug.exceptions.BadRequest("JSON body is required for PUT")


def _serialize_report_entry(report_entry):
def _serialize_report_entry(report_entry, full=False):
"""
Serialize a report entry representing a testcase or a test group.
For a test group shallow serialization is used instead.
"""
if isinstance(report_entry, TestCaseReport):
return report_entry.serialize()
elif isinstance(report_entry, (TestGroupReport, TestReport)):
return report_entry.shallow_serialize()
if full:
return report_entry.serialize()
else:
return report_entry.shallow_serialize()
else:
raise TypeError(f"Unexpected report entry type: {type(report_entry)}")

Expand Down
29 changes: 18 additions & 11 deletions testplan/web_ui/testing/src/Report/InteractiveReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ import { encodeURIComponent2, parseToJson } from "../Common/utils";
import { POLL_MS, CATEGORIES } from "../Common/defaults";
import { AssertionContext, defaultAssertionStatus } from "../Common/context";
import { ErrorBoundary } from "../Common/ErrorBoundary";
import { displayTimeInfoPreference, timeInfoUTCPreference } from "../UserSettings/UserSettings";
import {
displayTimeInfoPreference,
timeInfoUTCPreference,
} from "../UserSettings/UserSettings";

const api_prefix = "/api/v1/interactive";
const pendingEnvRequestAtom = atom("");
Expand Down Expand Up @@ -87,6 +90,7 @@ class InteractiveReportComponent extends BaseReport {
running: false,
aborting: false,
assertionStatus: defaultAssertionStatus,
firstGet: true, // state variable to track the first getReport
};
}

Expand Down Expand Up @@ -119,16 +123,19 @@ class InteractiveReportComponent extends BaseReport {
*
* If running in dev mode we just display a fake report.
*/
getReport() {
getReport(firstGet = true) {
if (this.state.aborting) {
this.setError({ message: "Server is aborting ..." });
return;
}
if (this.props.match.params.uid === "_dev") {
setTimeout(() => this.setReport(FakeInteractiveReport), 1500);
} else {
const url = firstGet
? "/api/v1/interactive/report?full=true"
: "/api/v1/interactive/report";
axios
.get("/api/v1/interactive/report", { transformResponse: parseToJson })
.get(url, { transformResponse: parseToJson })
.then((response) => {
if (
response.data.runtime_status === "ready" ||
Expand All @@ -142,10 +149,9 @@ class InteractiveReportComponent extends BaseReport {
this.setState({ running: false });
}
}
if (
!this.state.report ||
this.state.report.hash !== response.data.hash
) {
if (firstGet) {
this.setReport(response.data);
} else if (this.state.report.hash !== response.data.hash) {
this.getTests().then((tests) => {
const rawReport = { ...response.data, entries: tests };
this.setReport(rawReport);
Expand All @@ -155,7 +161,10 @@ class InteractiveReportComponent extends BaseReport {
.catch(this.setError)
.finally(() => {
// We poll for updates to the report every second.
setTimeout(this.getReport, this.props.poll_intervall || POLL_MS);
setTimeout(
() => this.getReport(false),
this.props.poll_intervall || POLL_MS
);
});
}
}
Expand Down Expand Up @@ -491,9 +500,7 @@ class InteractiveReportComponent extends BaseReport {
};

if (!isReportLeaf(reportEntry) && !_.isEmpty(entries)) {
pruneEntry.entries = entries.map((entry) =>
this.pruneReportEntry(entry)
);
pruneEntry.entries = entries.map((entry) => this.pruneReportEntry(entry));
}

return pruneEntry;
Expand Down

0 comments on commit 1f96aeb

Please sign in to comment.