Skip to content

Commit 5de7099

Browse files
algolia-botshortcutsantgilles
committed
fix(go): retry strategy (#5159) (generated) [skip ci]
Co-authored-by: Clément Vannicatte <[email protected]> Co-authored-by: Antoine GILLES <[email protected]>
1 parent cda123b commit 5de7099

File tree

11 files changed

+445
-49
lines changed

11 files changed

+445
-49
lines changed

tests/output/csharp/src/generated/client/Search.test.cs

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public async Task ApiTest3()
115115
);
116116
}
117117

118-
[Fact(DisplayName = "tests the retry strategy error")]
118+
[Fact(DisplayName = "tests the retry strategy on timeout")]
119119
public async Task ApiTest4()
120120
{
121121
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
@@ -148,8 +148,64 @@ public async Task ApiTest4()
148148
);
149149
}
150150

151-
[Fact(DisplayName = "test the compression strategy")]
151+
[Fact(DisplayName = "tests the retry strategy on 5xx")]
152152
public async Task ApiTest5()
153+
{
154+
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
155+
{
156+
CustomHosts = new List<StatefulHost>
157+
{
158+
new()
159+
{
160+
Scheme = HttpScheme.Http,
161+
Url =
162+
Environment.GetEnvironmentVariable("CI") == "true"
163+
? "localhost"
164+
: "host.docker.internal",
165+
Port = 6671,
166+
Up = true,
167+
LastUse = DateTime.UtcNow,
168+
Accept = CallType.Read | CallType.Write,
169+
},
170+
new()
171+
{
172+
Scheme = HttpScheme.Http,
173+
Url =
174+
Environment.GetEnvironmentVariable("CI") == "true"
175+
? "localhost"
176+
: "host.docker.internal",
177+
Port = 6672,
178+
Up = true,
179+
LastUse = DateTime.UtcNow,
180+
Accept = CallType.Read | CallType.Write,
181+
},
182+
new()
183+
{
184+
Scheme = HttpScheme.Http,
185+
Url =
186+
Environment.GetEnvironmentVariable("CI") == "true"
187+
? "localhost"
188+
: "host.docker.internal",
189+
Port = 6673,
190+
Up = true,
191+
LastUse = DateTime.UtcNow,
192+
Accept = CallType.Read | CallType.Write,
193+
},
194+
},
195+
};
196+
var client = new SearchClient(_config);
197+
198+
var res = await client.CustomPostAsync("1/test/error/csharp");
199+
200+
JsonAssert.EqualOverrideDefault(
201+
"{\"status\":\"ok\"}",
202+
JsonSerializer.Serialize(res, JsonConfig.Options),
203+
new JsonDiffConfig(false)
204+
);
205+
}
206+
207+
[Fact(DisplayName = "test the compression strategy")]
208+
public async Task ApiTest6()
153209
{
154210
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
155211
{
@@ -186,7 +242,7 @@ public async Task ApiTest5()
186242
}
187243

188244
[Fact(DisplayName = "calls api with default read timeouts")]
189-
public async Task ApiTest6()
245+
public async Task ApiTest7()
190246
{
191247
var client = new SearchClient(new SearchConfig("appId", "apiKey"), _echo);
192248
await client.CustomGetAsync("1/test");
@@ -197,7 +253,7 @@ public async Task ApiTest6()
197253
}
198254

199255
[Fact(DisplayName = "calls api with default write timeouts")]
200-
public async Task ApiTest7()
256+
public async Task ApiTest8()
201257
{
202258
var client = new SearchClient(new SearchConfig("appId", "apiKey"), _echo);
203259
await client.CustomPostAsync("1/test");
@@ -208,7 +264,7 @@ public async Task ApiTest7()
208264
}
209265

210266
[Fact(DisplayName = "can handle unknown response fields")]
211-
public async Task ApiTest8()
267+
public async Task ApiTest9()
212268
{
213269
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
214270
{
@@ -240,7 +296,7 @@ public async Task ApiTest8()
240296
}
241297

242298
[Fact(DisplayName = "can handle unknown response fields inside a nested oneOf")]
243-
public async Task ApiTest9()
299+
public async Task ApiTest10()
244300
{
245301
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
246302
{

tests/output/dart/test/client/search_test.dart

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void main() {
9090
}
9191
});
9292

93-
test('tests the retry strategy error', () async {
93+
test('tests the retry strategy on timeout', () async {
9494
final requester = RequestInterceptor();
9595
final client = SearchClient(
9696
appId: "test-app-id",
@@ -115,6 +115,36 @@ void main() {
115115
);
116116
});
117117

118+
test('tests the retry strategy on 5xx', () async {
119+
final requester = RequestInterceptor();
120+
final client = SearchClient(
121+
appId: "test-app-id",
122+
apiKey: "test-api-key",
123+
options: ClientOptions(hosts: [
124+
Host.create(
125+
url:
126+
'${Platform.environment['CI'] == 'true' ? 'localhost' : 'host.docker.internal'}:6671',
127+
scheme: 'http'),
128+
Host.create(
129+
url:
130+
'${Platform.environment['CI'] == 'true' ? 'localhost' : 'host.docker.internal'}:6672',
131+
scheme: 'http'),
132+
Host.create(
133+
url:
134+
'${Platform.environment['CI'] == 'true' ? 'localhost' : 'host.docker.internal'}:6673',
135+
scheme: 'http'),
136+
]));
137+
requester.setOnRequest((request) {});
138+
try {
139+
final res = await client.customPost(
140+
path: "1/test/error/dart",
141+
);
142+
expectBody(res, """{"status":"ok"}""");
143+
} on InterceptionException catch (_) {
144+
// Ignore InterceptionException
145+
}
146+
});
147+
118148
test('calls api with default read timeouts', () async {
119149
final requester = RequestInterceptor();
120150
final client = SearchClient(

tests/output/go/tests/client/search_test.go

Lines changed: 33 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/output/java/src/test/java/com/algolia/client/Search.test.java

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void apiTest3() {
119119
}
120120

121121
@Test
122-
@DisplayName("tests the retry strategy error")
122+
@DisplayName("tests the retry strategy on timeout")
123123
void apiTest4() {
124124
SearchClient client = new SearchClient(
125125
"test-app-id",
@@ -149,8 +149,44 @@ void apiTest4() {
149149
}
150150

151151
@Test
152-
@DisplayName("test the compression strategy")
152+
@DisplayName("tests the retry strategy on 5xx")
153153
void apiTest5() {
154+
SearchClient client = new SearchClient(
155+
"test-app-id",
156+
"test-api-key",
157+
withCustomHosts(
158+
Arrays.asList(
159+
new Host(
160+
"true".equals(System.getenv("CI")) ? "localhost" : "host.docker.internal",
161+
EnumSet.of(CallType.READ, CallType.WRITE),
162+
"http",
163+
6671
164+
),
165+
new Host(
166+
"true".equals(System.getenv("CI")) ? "localhost" : "host.docker.internal",
167+
EnumSet.of(CallType.READ, CallType.WRITE),
168+
"http",
169+
6672
170+
),
171+
new Host(
172+
"true".equals(System.getenv("CI")) ? "localhost" : "host.docker.internal",
173+
EnumSet.of(CallType.READ, CallType.WRITE),
174+
"http",
175+
6673
176+
)
177+
),
178+
false
179+
)
180+
);
181+
182+
Object res = client.customPost("1/test/error/java");
183+
184+
assertDoesNotThrow(() -> JSONAssert.assertEquals("{\"status\":\"ok\"}", json.writeValueAsString(res), JSONCompareMode.STRICT));
185+
}
186+
187+
@Test
188+
@DisplayName("test the compression strategy")
189+
void apiTest6() {
154190
SearchClient client = new SearchClient(
155191
"test-app-id",
156192
"test-api-key",
@@ -190,7 +226,7 @@ void apiTest5() {
190226

191227
@Test
192228
@DisplayName("calls api with default read timeouts")
193-
void apiTest6() {
229+
void apiTest7() {
194230
SearchClient client = createClient();
195231

196232
client.customGet("1/test");
@@ -201,7 +237,7 @@ void apiTest6() {
201237

202238
@Test
203239
@DisplayName("calls api with default write timeouts")
204-
void apiTest7() {
240+
void apiTest8() {
205241
SearchClient client = createClient();
206242

207243
client.customPost("1/test");
@@ -212,7 +248,7 @@ void apiTest7() {
212248

213249
@Test
214250
@DisplayName("can handle unknown response fields")
215-
void apiTest8() {
251+
void apiTest9() {
216252
SearchClient client = new SearchClient(
217253
"test-app-id",
218254
"test-api-key",
@@ -242,7 +278,7 @@ void apiTest8() {
242278

243279
@Test
244280
@DisplayName("can handle unknown response fields inside a nested oneOf")
245-
void apiTest9() {
281+
void apiTest10() {
246282
SearchClient client = new SearchClient(
247283
"test-app-id",
248284
"test-api-key",

tests/output/javascript/src/client/search.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe('api', () => {
9797
expect(result).toEqual({ message: 'ok test server response' });
9898
}, 25000);
9999

100-
test('tests the retry strategy error', async () => {
100+
test('tests the retry strategy on timeout', async () => {
101101
const client = algoliasearch('test-app-id', 'test-api-key', {
102102
hosts: [
103103
{
@@ -120,6 +120,35 @@ describe('api', () => {
120120
}
121121
}, 25000);
122122

123+
test('tests the retry strategy on 5xx', async () => {
124+
const client = algoliasearch('test-app-id', 'test-api-key', {
125+
hosts: [
126+
{
127+
url: 'localhost',
128+
port: 6671,
129+
accept: 'readWrite',
130+
protocol: 'http',
131+
},
132+
{
133+
url: 'localhost',
134+
port: 6672,
135+
accept: 'readWrite',
136+
protocol: 'http',
137+
},
138+
{
139+
url: 'localhost',
140+
port: 6673,
141+
accept: 'readWrite',
142+
protocol: 'http',
143+
},
144+
],
145+
});
146+
147+
const result = await client.customPost({ path: '1/test/error/javascript' });
148+
149+
expect(result).toEqual({ status: 'ok' });
150+
}, 25000);
151+
123152
test('calls api with default read timeouts', async () => {
124153
const client = createClient();
125154

0 commit comments

Comments
 (0)