Skip to content

Retry polling event queue always, with backoff #515

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

Merged
merged 13 commits into from
Feb 22, 2024
Merged

Conversation

gnprice
Copy link
Member

@gnprice gnprice commented Feb 13, 2024

Fixes: #184

Along the way, add some infrastructure to help us better write tests for asynchronous code, and in particular to better use package:fake_async.

@chrisbobbe
Copy link
Collaborator

This now has some conflicts; would you mind resolving those?

@gnprice
Copy link
Member Author

gnprice commented Feb 22, 2024

Sure — done.

Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

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

Thanks! This is an important fix. One small comment to check my understanding on something, then please merge at will.

Comment on lines +71 to -73
lastRequest = request;
final response = _nextResponse!;
_nextResponse = null;
lastRequest = request;
Copy link
Collaborator

Choose a reason for hiding this comment

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

fake_api: Record premature requests, too, in lastRequest

Ah I think I see: a request is "premature" because it's made before its response has been prepared. So the difference is that in those cases (the cases where _nextResponse! fails), the premature request will be recorded as lastRequest, vs. not recorded.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, exactly.

This calls FakeAsync.flushMicrotasks on the FakeAsync that the
tester is using.  (In the AutomatedTestWidgetsFlutterBinding case,
that is, i.e. the `flutter test` case, which is where the tester
is already using a FakeAsync.)

Seems like it'd be dubious to try to introduce our own FakeAsync
(as with `awaitFakeAsync`) when already in another's zone.  It's
possible it would all work fine, but it seems complicated to
have to think about.
This is pretty much transcribed straight from the JS implementation
(and test) in zulip-mobile, in the files:
  src/utils/async.js
  src/utils/__tests__/async-test.js
This makes it a bit less close of a transcription from the JS version
in zulip-mobile (which is why I didn't squash this into the previous
commit), but I think a bit more idiomatic as Dart.
This seems like the least confusing behavior.
This has been a useful pattern for other test fakes and mocks.
All the tests still behave the same after this change, because
any subsequent checks on `lastRequest` in each test look for a
different value.
The new TODO comments are all things that we don't do today in
zulip-mobile, and haven't been aware of causing problems for people.
So there's no rush to do them here.

Fixes: zulip#184
@gnprice gnprice merged commit 8f2c5b3 into zulip:main Feb 22, 2024
@gnprice
Copy link
Member Author

gnprice commented Feb 22, 2024

Merged. Thanks for the review!

@gnprice gnprice deleted the pr-backoff branch February 22, 2024 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Retry long-poll failures, with backoff
2 participants