-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add X-Klaviyo- request headers and use Retry-After response header #149
Conversation
… of attempts. Consolidated and improved API Request tests, added tests for new features.
60a8a08
to
f096525
Compare
# Conflicts: # sdk/analytics/src/main/java/com/klaviyo/analytics/networking/requests/KlaviyoApiRequest.kt # sdk/analytics/src/test/java/com/klaviyo/analytics/KlaviyoTest.kt # sdk/analytics/src/test/java/com/klaviyo/analytics/networking/KlaviyoApiClientTest.kt # sdk/analytics/src/test/java/com/klaviyo/analytics/networking/requests/BaseRequestTest.kt # sdk/analytics/src/test/java/com/klaviyo/analytics/networking/requests/EventApiRequestTest.kt
@@ -87,6 +90,17 @@ internal class KlaviyoApiClientTest : BaseRequestTest() { | |||
} | |||
} | |||
|
|||
@After |
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.
Small thing, but I grouped setup and cleanup functions together for readability.
every { networkMonitorMock.isNetworkConnected() } returns true | ||
every { configMock.networkTimeout } returns 1 | ||
every { configMock.networkFlushIntervals } returns longArrayOf(10_000L, 30_000L, 60_000L) | ||
} | ||
|
||
@After |
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.
for clarity, I annotated all setup/cleanup, even though overrides technically inherit it
import org.junit.Before | ||
import org.junit.Test | ||
|
||
internal abstract class BaseApiRequestTest<T> : BaseTest() where T : KlaviyoApiRequest { |
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.
Abstract base class for API request tests. The tests in this class get applied to all API Request tests that inherit from here.
Assert.assertEquals(expectedQuery, makeTestRequest().query) | ||
} | ||
|
||
inline fun <reified T> testJsonInterop(request: T) where T : KlaviyoApiRequest { |
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.
Couldn't quite get this to work as a @test with generics alone, so made a reusable function and call it in one-liner tests in the subclasses.
Use header name "X-Klaviyo-Attempt-Count" Moved retry interval computation into Api Request since it is mainly driven by the header now Additional tests
sdk/analytics/src/main/java/com/klaviyo/analytics/networking/requests/ApiRequest.kt
Outdated
Show resolved
Hide resolved
sdk/analytics/src/main/java/com/klaviyo/analytics/networking/requests/KlaviyoApiRequest.kt
Show resolved
Hide resolved
sdk/analytics/src/main/java/com/klaviyo/analytics/networking/requests/KlaviyoApiRequest.kt
Outdated
Show resolved
Hide resolved
sdk/analytics/src/main/java/com/klaviyo/analytics/networking/requests/KlaviyoApiRequest.kt
Outdated
Show resolved
Hide resolved
sdk/analytics/src/main/java/com/klaviyo/analytics/networking/requests/KlaviyoApiRequest.kt
Outdated
Show resolved
Hide resolved
sdk/analytics/src/main/java/com/klaviyo/analytics/networking/requests/KlaviyoApiRequest.kt
Outdated
Show resolved
Hide resolved
sdk/analytics/src/main/java/com/klaviyo/analytics/networking/requests/KlaviyoApiRequest.kt
Show resolved
Hide resolved
- Add explicit test that API attempts count increments on send - Use val instead of var for request headers, now that its a mutable map. - Other cleanup
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 one question.
Description
Add new request headers, and make use of
Retry-After
response header on rate limited requests(429s)Check List
Changelog / Code Overview
X-Klaviyo-Mobile=1
X-Klaviyo-Retry-Attempt=N/MAX
Retry-After
header on rate limited requests (previously unavailable forclient/*
429s) and obey the server's retry timing, plus jitter.Sample of new request headers from test app:
Test Plan
Related Issues/Tickets
CHNL-6842
CHNL-6835