Skip to content

Commit

Permalink
address review comments; some minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyu-ms committed Jan 20, 2025
1 parent d0ba6ff commit 03bf37e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 63 deletions.
2 changes: 1 addition & 1 deletion testplan/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

__version__ = "24.9.2"

dev_build = int(os.environ.get("DEV_BUILD", "1"))
dev_build = int(os.environ.get("DEV_BUILD", "0"))
dev_suffix = f"dev{int(time.time())}" if dev_build else ""

__build_version__ = f"{__version__}{dev_suffix}"
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,8 @@ export function prepareTableLogRowData(indexes, table, columns, display_index) {

indexes.forEach((index) => {
let row = columns.reduce((accumulator, column, idx) => {
if (Array.isArray(table[index])) accumulator[column] = table[index][idx];
// TODO: remove this branch after 3 months 2021.06.01
else accumulator[column] = table[index][column];
// Array.isArray(table[index])
accumulator[column] = table[index][idx];
return accumulator;
}, {});
if (display_index) row["id"] = index;
Expand Down
60 changes: 26 additions & 34 deletions testplan/web_ui/testing/src/Common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,12 @@ import _ from "lodash";
* Calculate execution time of an entry with timer field
*/
function calcExecutionTime(entry) {
let elapsed = null;
let elapsed = 0;
if (entry.timer && entry.timer.run) {
// TODO: remove the else branch after Aug. 1 2024
if (Array.isArray(entry.timer.run) && !_.isEmpty(entry.timer.run)) {
elapsed = 0;
entry.timer.run.forEach((interval) => {
elapsed +=
entry.timer.run.forEach((interval) => {
elapsed +=
timeToTimestamp(interval.end) - timeToTimestamp(interval.start);
});
} else {
elapsed =
timeToTimestamp(entry.timer.run.end) -
timeToTimestamp(entry.timer.run.start);
}
});
}
return elapsed;
}
Expand All @@ -36,7 +28,7 @@ function calcElapsedTime(timerField) {
elapsed = 0;
timerField.forEach((interval) => {
elapsed +=
timeToTimestamp(interval.end) - timeToTimestamp(interval.start);
timeToTimestamp(interval.end) - timeToTimestamp(interval.start);
});
}
return elapsed < 0 ? null : elapsed;
Expand Down Expand Up @@ -168,12 +160,14 @@ function formatSeconds(durationInSeconds) {
* @returns {string}
*/
function formatMilliseconds(durationInMilliseconds) {
if (!_.isNumber(durationInMilliseconds)) { return "na"; };
if (!_.isNumber(durationInMilliseconds)) {
return "na";
}

let secondsInMilliseconds = durationInMilliseconds % 60000;
let seconds = secondsInMilliseconds / 1000;
let minutesInMilliseconds = (durationInMilliseconds - secondsInMilliseconds)
/ 60000;
let minutesInMilliseconds =
(durationInMilliseconds - secondsInMilliseconds) / 60000;
let minutes = minutesInMilliseconds % 60;
let hours = (minutesInMilliseconds - minutes) / 60;

Expand All @@ -185,13 +179,11 @@ function formatMilliseconds(durationInMilliseconds) {
let secondsDisplay = seconds.toFixed(3) + "s";

return (
[hoursDisplay, minutesDisplay, secondsDisplay]
.filter(Boolean)
.join(" ") || "0s"
[hoursDisplay, minutesDisplay, secondsDisplay].filter(Boolean).join(" ") ||
"0s"
);
}


/**
* Formats the input number representing milliseconds into a string
* with format H:m:s.SSS. Each value is displayed only if it is greater
Expand All @@ -200,14 +192,16 @@ function formatMilliseconds(durationInMilliseconds) {
* @returns {string}
*/
function formatShortDuration(durationInMilliseconds) {
if (!_.isNumber(durationInMilliseconds)) { return "na"; };
if (!_.isNumber(durationInMilliseconds)) {
return "na";
}

durationInMilliseconds = _.round(durationInMilliseconds, -2);

let secondsInMilliseconds = durationInMilliseconds % 60000;
let seconds = secondsInMilliseconds / 1000;
let minutesInMilliseconds = (durationInMilliseconds - secondsInMilliseconds)
/ 60000;
let minutesInMilliseconds =
(durationInMilliseconds - secondsInMilliseconds) / 60000;
let minutes = minutesInMilliseconds % 60;
let hours = (minutesInMilliseconds - minutes) / 60;

Expand All @@ -219,19 +213,17 @@ function formatShortDuration(durationInMilliseconds) {
let hoursDisplay = isDisplayedHours ? hours + "h" : "";
let minutesDisplay = isDisplayedMinutes ? minutes + "m" : "";
let secondsDisplay = isDisplayedSeconds
? isDisplayedMilliseconds
? seconds.toFixed(1) + "s"
: seconds.toFixed(0) + "s"
: null;
? isDisplayedMilliseconds
? seconds.toFixed(1) + "s"
: seconds.toFixed(0) + "s"
: null;

return (
[hoursDisplay, minutesDisplay, secondsDisplay]
.filter(Boolean)
.join(":") || "0s"
[hoursDisplay, minutesDisplay, secondsDisplay].filter(Boolean).join(":") ||
"0s"
);
}


export {
calcExecutionTime,
calcElapsedTime,
Expand Down Expand Up @@ -436,15 +428,15 @@ export const truncateString = (
str,
maxLength = 15,
startLength = 7,
endLength = 7
endLength = 7
) => {
if (str.length <= maxLength) {
return str;
}

const startPortion = str.slice(0, startLength);
const endPortion = str.slice(-1 * endLength);

return `${startPortion}...${endPortion}`;
};

Expand All @@ -453,7 +445,7 @@ export const truncateString = (
* @param {String} path
*/
export const getWorkspacePath = (path) => {
const srcIndex = path.indexOf('/src/');
const srcIndex = path.indexOf("/src/");

if (srcIndex !== -1) {
return path.slice(srcIndex + 1);
Expand Down
26 changes: 5 additions & 21 deletions testplan/web_ui/testing/src/Report/reportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,7 @@ const GetCenterPane = (
/** TODO */
const getAssertions = (selectedEntries, displayTime, UTCTime) => {
// get timezone from nearest (test-level) report
let IANAtz = ""; // default to utc
for (let e of selectedEntries) {
if (e.timezone) {
IANAtz = e.timezone;
break;
}
}
const IANAtz = selectedEntries.find((e) => e.timezone)?.timezone || ""; // default to utc

// get all assertions from groups and list them sequentially in an array
const getAssertionsRecursively = (links, entries) => {
Expand Down Expand Up @@ -328,21 +322,11 @@ const getAssertions = (selectedEntries, displayTime, UTCTime) => {
let duration = "Unknown";
if (selectedEntry.timer && selectedEntry.timer.run) {
if (links[0].utc_time) {
let previousEntryTime = null;
// TODO: remove the else branch after Aug. 1 2024
if (
Array.isArray(selectedEntry.timer.run) &&
!_.isEmpty(selectedEntry.timer.run)
) {
previousEntryTime = new Date(
selectedEntry.timer.run.at(-1).start
);
} else {
previousEntryTime = new Date(selectedEntry.timer.run.start);
}
const previousEntryTime = new Date(
selectedEntry.timer.run.at(-1).start
);
const currentEntryTime = new Date(links[0].utc_time);
const durationInMilliseconds = currentEntryTime - previousEntryTime;
duration = formatMilliseconds(durationInMilliseconds);
duration = formatMilliseconds(currentEntryTime - previousEntryTime);
} else if (links[0].timestamp) {
const previousEntryTime = selectedEntry.timer.run.at(-1).start;
const currentEntryTime = links[0].timestamp;
Expand Down
5 changes: 1 addition & 4 deletions tests/unit/testplan/runnable/interactive/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
from testplan.common import entity
from testplan.runnable.interactive import base, http

# XXX: tmp solution
from testplan.common.utils.json import json_dumps, json_loads


class TestRunnerIHandlerConfig(base.TestRunnerIHandlerConfig):
"""Only for testing."""
Expand Down Expand Up @@ -216,7 +213,7 @@ def test_put_filtered(self, api_env):
assert rsp.status_code == 200

ihandler.run_all_tests.assert_called_once_with(
shallow_report=json_loads(json_dumps(json_report)),
shallow_report=json_report,
await_results=False,
)

Expand Down

0 comments on commit 03bf37e

Please sign in to comment.