-
Notifications
You must be signed in to change notification settings - Fork 18
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
ECS-5104 Hutch-python feature: auto-close after timeout #385
ECS-5104 Hutch-python feature: auto-close after timeout #385
Conversation
…ython.ipython_session_timer'.
…ariable in each hutch's conf.yml file.
There are some pre-commit fixes to address here. If you install pre-commit locally you can catch these before pushing. Some weirdness in CI here. Looks like the passing tests grab an older version of pcdscalc, which doesn't depend on xraylib? |
docs/source/upcoming_release_notes/385-Hutch-python_feature:_auto-close_after_timeout.rst
Outdated
Show resolved
Hide resolved
docs/source/upcoming_release_notes/385-Hutch-python_feature:_auto-close_after_timeout.rst
Outdated
Show resolved
Hide resolved
I think we also need some unit tests here. This is the kind of feature that can be super disruptive if we ever get some kind of regression |
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 the logic of this is looking a lot better 👍 Stray prints and debug settings aside
…ogic to check if user is currently active once every 60 seconds.
…se note for Jira ticket ECS-5104_Hutch-python_feature:_auto-close_after_timeout.
…cy (time.monotonic() is in floating point).
...ource/upcoming_release_notes/385-ECS-5104_Hutch-python_feature:_auto-close_after_timeout.rst
Outdated
Show resolved
Hide resolved
…ython.ipython_session_timer'.
I put together some unit tests for ipython_session_timer.py. There is probably a better way to test IPythonSessionTimer._start_session() but this was the only version I was able to get working. |
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 we could refine the tests, but perhaps we leave that for a follow up. We've sat on this long enough. One test I'd like to add later on is one that actually tests the timer functionality. As in: we set the timeout time to ~1s, and watch for the exit signal to be sent. But that can be a later problem.
The last two tests also don't actually assert anything, the if statements always resolve to False
I think interactively this works as advertised, and the default being at 48 hours is good enough to be minimally intrusive.
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.
Consolidating small nitpick suggestions into one group here
I added some code to
|
You could probably use from types import SimpleNamespace
from unittest.mock import MagicMock
class FakePtApp:
app = SimpleNamespace(exit=MagicMock())
class FakeIPython:
"""A fake replacement of IPython's ``TerminalInteractiveShell``."""
user_ns: dict[str, Any]
events: FakeIPythonEvents
def __init__(self):
self.user_ns = dict(In=[""])
self.events = FakeIPythonEvents()
self.pt_app = FakePtApp()
self.ask_exit = MagicMock() later in the tests: @unittest.mock.patch('time.sleep', lambda seconds: None)
def test_start_session_case1(session_timer, fake_ipython, capsys):
session_timer.user_active = False
session_timer._start_session()
captured = capsys.readouterr()
assert "timed out" in captured.out
assert session_timer.ip.ask_exit.called
assert session_timer.ip.pt_app.app.exit.called Aside from that, the code snippet you shared doesn't look entirely right / complete. You're creating the |
Thanks for the MagicMock suggestion. Going to read up on it and learn what it's doing. I've added this and the unit tests are passing. Does the hutch-python session timer feature look ready to merge? |
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 this looks good to me. Some hard fought lines of code but I like where it ended up! 🎉
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.
Three questions/thoughts about the unit tests
Overall this is great and we can probably merge soon
fwiw I think we could definitely merge as-is, it does the thing correctly and is well-documented. I'm splitting hairs on the unit tests at this point. |
cool, it's done! I'll merge tomorrow morning. |
Description
PR for the IPython session timer
Motivation and Context
https://jira.slac.stanford.edu/browse/ECS-5104
How Has This Been Tested?
Haven't been able to test changes to load_config.py and rix/conf.yml. How are changes to /conf.yml file tested?
Where Has This Been Documented?
Documentation is in the file comments.
Pre-merge checklist
docs/pre-release-notes.sh
and created a pre-release documentation page