Skip to content

Commit b030b37

Browse files
olivier-hubautOlivier Hubaut
andauthored
fix: Retry logic was never applied. (#146)
The implement of the Call object being stateful, the retry logic was never triggered as an IllegalStateException was bypassing the normal flow. Closes: #144 Co-authored-by: Olivier Hubaut <olivier.hubaut@onem.be>
1 parent 8d17f5a commit b030b37

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/main/java/com/flagsmith/threads/RequestProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ public Future<JsonNode> executeAsync(Request request, Boolean doThrow) {
7676
public <T> Future<T> executeAsync(
7777
Request request, TypeReference<T> clazz, Boolean doThrow, Retry retries) {
7878
CompletableFuture<T> completableFuture = new CompletableFuture<>();
79-
Call call = getClient().newCall(request);
8079
Retry localRetry = retries.toBuilder().build();
8180
// run the execute method in a fixed thread with retries.
8281
executor.submit(() -> {
8382
// retry until local retry reaches 0
8483
try {
8584
Integer statusCode = null;
8685
do {
86+
Call call = getClient().newCall(request);
8787
localRetry.waitWithBackoff();
8888
Boolean throwOrNot = localRetry.getAttempts() == localRetry.getTotal()
8989
? doThrow : Boolean.FALSE;

src/test/java/com/flagsmith/FlagsmithApiWrapperTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,27 @@ public void init() {
6565
sut = new FlagsmithApiWrapper(defaultConfig, null, flagsmithLogger, API_KEY);
6666
}
6767

68+
@Test
69+
void getFeatureFlags_retries() {
70+
// Arrange
71+
interceptor.addRule()
72+
.get(BASE_URL + "/flags/")
73+
.anyTimes()
74+
.respond(503);
75+
76+
// Act
77+
try {
78+
sut.getFeatureFlags(true);
79+
} catch (Exception e) {
80+
// ignore
81+
}
82+
83+
// Assert
84+
// Since the Retry object is local to the call, the only external behaviour we can watch
85+
// is the logger
86+
verify(flagsmithLogger, times(2)).httpError(any(), any(Response.class), anyBoolean());
87+
}
88+
6889
@Test
6990
public void getFeatureFlags_noUser_success() throws JsonProcessingException {
7091
// Arrange

0 commit comments

Comments
 (0)