Skip to content

Commit 2ced1c5

Browse files
authored
chore: assert long lasting requests on the ingestion api (#4615)
1 parent 7db97d1 commit 2ced1c5

File tree

6 files changed

+289
-246
lines changed

6 files changed

+289
-246
lines changed

clients/algoliasearch-client-ruby/lib/algolia/configuration.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def initialize(app_id, api_key, hosts, client_name, opts = {})
2525
@app_id = app_id
2626
@api_key = api_key
2727
@client_side_validation = opts[:client_side_validation].nil? ? true : opts[:client_side_validation]
28-
@connect_timeout = opts[:connect_timeout] || 2_000
29-
@read_timeout = opts[:read_timeout] || 5_000
30-
@write_timeout = opts[:write_timeout] || 30_000
28+
@connect_timeout = opts[:connect_timeout]
29+
@read_timeout = opts[:read_timeout]
30+
@write_timeout = opts[:write_timeout]
3131
@compression_type = opts[:compression_type] || "none"
3232
@requester = opts[:requester]
3333

scripts/cts/testServer/timeout.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ function addRoutes(app: express.Express): void {
102102
res.setHeader('Content-Type', 'text/html');
103103
res.status(429).send('<html><body>429 Too Many Requests</body></html>');
104104
});
105+
106+
app.get('/1/long-wait', (req, res) => {
107+
setTimeout(() => {
108+
res.json({ message: 'OK' });
109+
}, 8000);
110+
});
105111
}
106112

107113
export function timeoutServer(): Promise<Server> {

templates/javascript/tests/client/tests.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('{{testType}}', () => {
5555
}
5656
{{/times}}
5757
{{/steps}}
58-
}, 15000);
58+
}, 25000);
5959

6060
{{/tests}}
6161
});

templates/ruby/api.mustache

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ module {{moduleName}}
3030
region = nil
3131
end
3232

33-
if opts.nil? || opts[:connect_timeout].nil?
34-
opts[:connect_timeout] = {{x-timeouts.server.connect}}
35-
end
36-
37-
if opts.nil? || opts[:read_timeout].nil?
38-
opts[:read_timeout] = {{x-timeouts.server.read}}
39-
end
40-
41-
if opts.nil? || opts[:write_timeout].nil?
42-
opts[:write_timeout] = {{x-timeouts.server.write}}
43-
end
44-
4533
{{^fallbackToAliasHost}}
4634
raise "`region` is required and must be one of the following: #{regions.join(', ')}" if region.nil? || !region.is_a?(String) || !regions.include?(region)
4735
{{/fallbackToAliasHost}}
@@ -70,6 +58,18 @@ module {{moduleName}}
7058
end
7159

7260
def self.create_with_config(config)
61+
if config.connect_timeout.nil? ||config.connect_timeout.empty?
62+
config.connect_timeout = {{x-timeouts.server.connect}}
63+
end
64+
65+
if config.read_timeout.nil? || config.read_timeout.empty?
66+
config.read_timeout = {{x-timeouts.server.read}}
67+
end
68+
69+
if config.write_timeout.nil? || config.write_timeout.empty?
70+
config.write_timeout = {{x-timeouts.server.write}}
71+
end
72+
7373
new(config)
7474
end
7575

tests/CTS/client/ingestion/api.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,36 @@
7777
}
7878
]
7979
},
80+
{
81+
"testName": "can leave call opened for a long time",
82+
"autoCreateClient": false,
83+
"steps": [
84+
{
85+
"type": "createClient",
86+
"parameters": {
87+
"appId": "test-app-id",
88+
"apiKey": "test-api-key",
89+
"region": "us",
90+
"customHosts": [
91+
{
92+
"port": 6676
93+
}
94+
]
95+
}
96+
},
97+
{
98+
"type": "method",
99+
"method": "customGet",
100+
"parameters": {
101+
"path": "1/long-wait"
102+
},
103+
"expected": {
104+
"type": "response",
105+
"match": {"message":"OK"}
106+
}
107+
}
108+
]
109+
},
80110
{
81111
"testName": "endpoint level timeout",
82112
"steps": [

0 commit comments

Comments
 (0)