Skip to content
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

Multiple footer reset bug fix #725

Closed
wants to merge 2 commits into from

Conversation

kaustubh-nair
Copy link
Member

@kaustubh-nair kaustubh-nair commented Jul 17, 2020

This PR introduces a queue to keep track of the currently active sleep threads, and resets the footer only if the queue is empty.

Fixes #647
(Alternate fix: #748)

@zulipbot zulipbot added size: M [Automatic label added by zulipbot] bug Something isn't working labels Jul 17, 2020
@kaustubh-nair kaustubh-nair force-pushed the rapid-footer-updates branch 2 times, most recently from bbdfd8a to 3cc2b1c Compare July 17, 2020 18:24
Copy link
Member

@sumanthvrao sumanthvrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaustubh-nair Left a couple of comments, but broadly looks good!

view.controller.update_screen.assert_called_once_with()
view._reset_footer_text.assert_called_once_with(duration)

def _reset_footer_text(self, view, mocker, duration=46.2):
Copy link
Member

@sumanthvrao sumanthvrao Jul 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is a test, I think ti should start with test_*. Added I think pytest won't run this unless it starts with test__reset_footer_......

Do you want to remove the two blank lines below (81, 83)? It feels a little odd. And if we can save some space and not decrease readability, we should go for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, good catch - the tests weren't running.

@neiljp Suggests having blank lines surrounding the method under test 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The blank lines clarify the arrange, act and assert segments. Personally, I like having them. 😉

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this does add extra spacing, this is a style I've been moving towards for the reasons that @preetmishra mentioned.

That said, if a test needs zero setup, I might be tempted to avoid the one blank line, but consistency would still be good and we don't currently have many of those - perhaps unfortunately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure looks like a cleaner style. 👍

@@ -84,6 +86,15 @@ def _reset_footer_text(self, view, mocker, duration=46.2):
mock_sleep.assert_called_once_with(duration)
view.set_footer_text.assert_called_once_with()

def _reset_footer_text_multiple_resets(self, view, mocker, duration=1):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as previous, it should begin with test__.....

@kaustubh-nair kaustubh-nair force-pushed the rapid-footer-updates branch from 3cc2b1c to 0cf71c5 Compare July 19, 2020 08:02
@zulipbot zulipbot added size: L [Automatic label added by zulipbot] and removed size: M [Automatic label added by zulipbot] labels Jul 19, 2020
executor.submit(view._reset_footer_text, duration=0.5)

view.set_footer_text.assert_called_once_with()
assert time.sleep.call_count == 3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried something different here - this is more of an integration test rather than the unit tests we have everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Also, pytest cannot call methods asynchronously?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be a plugin for pytest to work with asychronous behavior, but currently we have a simpler solution where our asynch decorator knows whether it's in a test environment.

@kaustubh-nair kaustubh-nair force-pushed the rapid-footer-updates branch from 0cf71c5 to 2b3f47b Compare July 19, 2020 08:09
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaustubh-nair This PR does resolve the situation, based on manual testing 👍

That said, this doesn't use the queue in the way that I'd expected, and will essentially fire up two threads for each footer call with a duration, from what I can tell. My understanding is that a queue is typically used between threads, rather than within one - though as I said, this does work for this problem right now.

One additional behavior we may want to extend this to include, which I'm not sure if I mentioned, is to de-duplicate the calls for the same message, ie. avoid updating the text if we're already in a time period with that message. That's not so obvious an issue to users, but the idea would be that if we're in a 3-second update with message foo, then we don't restart the time period again.

executor.submit(view._reset_footer_text, duration=0.5)

view.set_footer_text.assert_called_once_with()
assert time.sleep.call_count == 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be a plugin for pytest to work with asychronous behavior, but currently we have a simpler solution where our asynch decorator knows whether it's in a test environment.

Move the duration based logic that sets footer to a default value to a
new method. Note that this method is private - for other classes that
want to set footer to default value should stick to using
set_footer_text() for the sake of uniformity.

Tests amended.
Currently, if multiple calls are made to set the footer along with a
duration to reset it (for example, when tries to edit an uneditable
message too often by pressing the key too many times) then it leads to
repeated footer updates because all those calls lead to resetting the
footer. The goal of this commit is to change that, and reset the footer
only once, by ignoring other updates.

A queue is maintained containing number of sleep threads currently
active, and if there are none left then the footer is reset. This
ensures that only the last call to set_footer_text() resets the footer,
thus avoiding multiple resets.

Also, note that it is not strictly necessary to store the duration in
the queue, we could any number we like. However it is kept this way in
case we would like to do more with this in the future, say, spacing out
tight reset calls with only a small duration between them.

Test added.

Fixes zulip#647.
@kaustubh-nair kaustubh-nair force-pushed the rapid-footer-updates branch from 2b3f47b to 113c495 Compare July 28, 2020 20:59
@neiljp neiljp added this to the Release after next milestone Jan 28, 2021
Base automatically changed from master to main January 30, 2021 20:30
@zulipbot
Copy link
Member

Heads up @kaustubh-nair, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

@neiljp
Copy link
Collaborator

neiljp commented Mar 13, 2022

@kaustubh-nair I'm closing this in favor of your later #748 (thanks for both during GSoC!). That is a simpler solution, though doesn't avoid threads per call, and I suspect we may need an improvement later to more cleanly handle 'stacking' footer-text-updates.

@neiljp neiljp closed this Mar 13, 2022
@neiljp neiljp removed this from the Next Release milestone Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has conflicts size: L [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Footer gets updated as many times as the edit key is pressed on any uneditable message
5 participants