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
[Internal] Add retries to Authentication Repository #2414
Conversation
5c5735a
to
922f710
Compare
922f710
to
c558462
Compare
c558462
to
22abb42
Compare
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 ✅ I've also manually tested and it recovers after an initial token failure. Would be nice if @alteral does more tests.
Before merging:
- we should update the CHANGELOG, since it can be considered as a new feature
- add more tests (and fix the existing ones if broken)
JWT tests just fly! @polqf, you rock! |
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 ✅ just few short things.
XCTAssertNotNil(repository.tokenProvider) | ||
waitForExpectations(timeout: 0.1) | ||
waitForExpectations(timeout: 10000) |
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.
why 10000? 😁
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.
😂 leftover
@@ -549,6 +590,9 @@ final class AuthenticationRepository_Tests: XCTestCase { | |||
let testError = TestError() | |||
connectionRepository.connectResult = .failure(testError) | |||
|
|||
// API Result | |||
apiClient.test_mockResponseResult(Result<GuestUserTokenPayload, Error>.success(GuestUserTokenPayload(user: CurrentUserPayload.dummy(userId: "", role: .user), token: apiToken))) |
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.
We should format this one for better readability. Wonder why this was not done on the pre-commit hook?
@@ -580,6 +621,9 @@ final class AuthenticationRepository_Tests: XCTestCase { | |||
// Simulate Success on Connection Repository | |||
connectionRepository.connectResult = .success(()) | |||
|
|||
// API Result | |||
apiClient.test_mockResponseResult(Result<GuestUserTokenPayload, Error>.success(GuestUserTokenPayload(user: CurrentUserPayload.dummy(userId: "", role: .user), token: apiToken))) |
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.
Same here (formatting)
Kudos, SonarCloud Quality Gate passed! |
🔗 Issue Links
🎯 Goal
Fix E2E tests which were failing due to missing retries after a token fetch failure
🛠 Implementation
This PR adds retries when a token fetch process fails. It does it under the following circumstances:
In order to do that, it also removes state tracking of token attempts refresh from the APIClient.
Now, whenever the Authentication Repository is fetching a token, it notifies the APIClient so it can temporarily suspend the queue. In the case where requests are already in the queue and are being executed, those will be requeued as soon as an expired token is received, to then be relaunched when the queue is resumed.
To be quicker detecting expired tokens, we also try to refresh tokens when the connection changes to
.disconnecting
, as well as when it does to.disconnected
, and the server error reflects an expired token. Before we were only doing so when the state was.disconnected
.🎨 Showcase
☑️ Contributor Checklist
🎁 Meme