-
-
Notifications
You must be signed in to change notification settings - Fork 762
st2client - elapsed time in a more user-friendly format #4963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
st2client - elapsed time in a more user-friendly format #4963
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
Old: status: succeeded (76s elapsed)
New: status: succeeded (0:01:16 hours elapsed)
Looking at the #4944, I think what that Issue suggested is to provide more user-friendly and human-readable format. Converting 5s to hours doesn't make it easier to understand.
Here is an example what would make sense behind that idea:
30s
remains30s
339s
becomes5m39s
7350s
becomes2h2m30s
Hi @armab, I updated the PR to present the elapsed time as requested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that definitely looks more user-friendly! 👍
For some reason looks like you deleted the st2tests
dir with existing tests, check the diff.
Can you please also update the initial PR description with the new design/behavior?
Oh jesus, sorry! This explains a lot... will fix this shortly. Update: already done. Something went wrong when I merged the upstream/master into my branch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we cover this change with some simple unit tests?
There are minor lint issues related to the new code in CI checks, - please take a look.
Additionally, please update the initial PR description with the new design/behavior.
I fixed the multiple spaces before the = operator as reported by lint. That's something I'll keep in mind as I use this to format my code in other projects from time to time. So it shouldn't happen again on a st2 PR. The PR description was updated as well. I will provide a proper unit test in the next days as I'm working on st2 and other open source projects mostly in the evening after my usual job (which also explains my delayed reaction to the CI status from time to time. :) ). Will mark this PR as draft until I provided working tests. |
This reverts commit aafca8b.
I added a test but it looks like I got something wrong. My expectation was that the reported duration will be calculated from |
Hey team, I definitely need some help here. :( The unit test keeps failing unless I use st2/st2client/tests/unit/test_formatters.py Line 137 in c5d8e63
But as far as I can say (and @nmaludy agreed here on our recent slack discussion on this topic) it should not be required to use The cause for the failing test is that the test always get's the default executions object with the duration of 1 second and not the expected execution_with_hours_in_elapsed_time.json with a duration of 2h0m1s as per:
So the question is, why (I also wrote a summary in the slack #development channel last week, just in case it is helpful in any way: https://stackstorm-community.slack.com/archives/CSBELJ78A/p1592686455460800) Any help or hint is highly appreciated. I'd also be fine to use Cheers, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helpful FYI (a warning of sorts): We just merged the PR that reformatted the code with black
. So, this needs to be rebased or master needs to be merged (resolve any conflicts & reformat with black).
As far as the unit test goes, I left a comment. All of the methods are employing mocked http responses, albeit indirectly for those that use self._get_execution
. So, if you don't want to mock, you'll need to come up with alternative test machinery.
@@ -112,6 +115,12 @@ def test_execution_get_attributes(self): | |||
content = self._get_execution(argv) | |||
self.assertEqual(content, FIXTURES['results']['execution_get_attributes.txt']) | |||
|
|||
def test_execution_get_attribute_with_hours_in_elapsed_time(self): | |||
argv = ['execution', 'get', DURATION_HOURS['id'], '--attr', 'status'] | |||
content = self._get_execution(argv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using self._get_execution()
is the source of the error because _get_execution()
has a mock so it always returns the json from EXECUTION
, but you need it to return DURATION_HOURS
.
Here's _get_execution
with the mocked EXECUTION
response:
@mock.patch.object(
httpclient.HTTPClient,
"get",
mock.MagicMock(
return_value=base.FakeResponse(json.dumps(EXECUTION), 200, "OK", {})
),
)
def _get_execution(self, argv):
self.assertEqual(self.shell.run(argv), 0)
self._undo_console_redirect()
with open(self.path, "r") as fd:
content = fd.read()
return content
That's why your example unit test that uses mock.MagicMock worked better than self._get_execution()
.
This PR changes the output format of the elapsed time on
st2 execution get
.Old:
status: succeeded (76s elapsed)
status: succeeded (7350s elapsed)
New:
status: succeeded (01m16s elapsed)
status: succeeded (2h2m30s elapsed)
Leading units with a value of 0 will be omitted.
fixes #4944