Skip to content

Commit 5364f66

Browse files
committed
Add AuTest for connect_attempts
1 parent bb4b904 commit 5364f66

8 files changed

Lines changed: 514 additions & 0 deletions

tests/gold_tests/autest-site/ats_replay.test.ext

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ def configure_ats(obj: 'TestRun', server: 'Process', ats_config: dict, dns: Opti
119119
gold_file = diags_log['gold_file']
120120
ts.Disk.diags_log.Content += gold_file
121121

122+
# error_log validation.
123+
error_log = log_validation.get('error_log', {})
124+
for contains_entry in error_log.get('contains', []):
125+
expression = contains_entry['expression']
126+
description = contains_entry.get('description', f'Verify error_log contains: {expression}')
127+
ts.Disk.error_log.Content += Testers.ContainsExpression(expression, description)
128+
for excludes_entry in error_log.get('excludes', []):
129+
expression = excludes_entry['expression']
130+
description = excludes_entry.get('description', f'Verify error_log excludes: {expression}')
131+
ts.Disk.error_log.Content += Testers.ExcludesExpression(expression, description)
132+
# Gold file validation for error_log.
133+
if 'gold_file' in error_log:
134+
gold_file = error_log['gold_file']
135+
ts.Disk.error_log.Content += gold_file
136+
122137
# access_log validation.
123138
access_log = log_validation.get('access_log', {})
124139
if 'gold_file' in access_log:
@@ -182,6 +197,8 @@ def ATSReplayTest(obj, replay_file: str):
182197
dns = tr.MakeDNServer(name, **process_config)
183198
else:
184199
dns = tr.MakeDNServer(name, default='127.0.0.1')
200+
if 'records' in dns_config:
201+
dns.addRecords(dns_config['records'])
185202

186203
# Proxy Verifier Server configuration.
187204
if not 'server' in autest_config:
@@ -215,6 +232,7 @@ def ATSReplayTest(obj, replay_file: str):
215232
ats_config = autest_config['ats']
216233
enable_tls = ats_config.get('enable_tls', False)
217234
metric_checks = ats_config.get('metric_checks', [])
235+
log_validation = ats_config.get('log_validation', None)
218236

219237
ats_owner = obj if _requires_persistent_ats(ats_config) else tr
220238
ts = configure_ats(ats_owner, server=server, ats_config=ats_config, dns=dns)
@@ -272,6 +290,13 @@ def ATSReplayTest(obj, replay_file: str):
272290
f'^{re.escape(metric_name)}\\s+{expected_value}$', f'{metric_name} should be {expected_value}')
273291
check_tr.StillRunningAfter = ts
274292

293+
# wait for error log
294+
if log_validation != None and log_validation['error_log'] != None:
295+
wait_for_log = obj.AddTestRun('Wait for logs of ' + ats_config.get('name', 'ts'))
296+
wait_for_log.Processes.Default.Command = (
297+
os.path.join(obj.Variables.AtsTestToolsDir, 'condwait') + ' 60 1 -f ' + os.path.join(ts.Variables.LOGDIR, 'error.log'))
298+
wait_for_log.Processes.Default.ReturnCode = 0
299+
275300
return tr
276301

277302

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'''
2+
Verify Origin Server Connect Attempts Behavior
3+
'''
4+
# Licensed to the Apache Software Foundation (ASF) under one
5+
# or more contributor license agreements. See the NOTICE file
6+
# distributed with this work for additional information
7+
# regarding copyright ownership. The ASF licenses this file
8+
# to you under the Apache License, Version 2.0 (the
9+
# "License"); you may not use this file except in compliance
10+
# with the License. You may obtain a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS,
16+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
# See the License for the specific language governing permissions and
18+
# limitations under the License.
19+
20+
Test.Summary = '''
21+
Verify Origin Server Connect Attempts Behavior
22+
'''
23+
24+
# No retry
25+
Test.ATSReplayTest(replay_file="replay/connect_attempts_rr_no_retry.replay.yaml")
26+
27+
# max_retries
28+
Test.ATSReplayTest(replay_file="replay/connect_attempts_rr_max_retries.replay.yaml")
29+
30+
# rr_retries
31+
Test.ATSReplayTest(replay_file="replay/connect_attempts_rr_retries.replay.yaml")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.1:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=0 url='http://backend.example.com:``/path/'
2+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.1:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=1 url='http://backend.example.com:``/path/'
3+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.1:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=2 url='http://backend.example.com:``/path/'
4+
`` CONNECT : EIO [5] connecting to 0.0.0.1:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='1' marking down
5+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.2:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=0 url='http://backend.example.com:``/path/'
6+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.2:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=1 url='http://backend.example.com:``/path/'
7+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.2:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=2 url='http://backend.example.com:``/path/'
8+
`` CONNECT : EIO [5] connecting to 0.0.0.2:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='1' marking down
9+
`` DNS Error: no valid server http://backend.example.com:``/path/
10+
``
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.1:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=0 url='http://backend.example.com:``/path/'
2+
`` CONNECT : EIO [5] connecting to 0.0.0.1:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='1' marking down
3+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.2:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=0 url='http://backend.example.com:``/path/'
4+
`` CONNECT : EIO [5] connecting to 0.0.0.2:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='1' marking down
5+
`` DNS Error: no valid server http://backend.example.com:``/path/
6+
``
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.1:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=0 url='http://backend.example.com:``/path/'
2+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.1:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=0 url='http://backend.example.com:``/path/'
3+
`` CONNECT : EIO [5] connecting to 0.0.0.1:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='2' marking down
4+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.2:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=0 url='http://backend.example.com:``/path/'
5+
`` CONNECT: attempt fail [CONNECTION_ERROR] to 0.0.0.2:`` for host='example.com' connection_result=EIO [5] error=SUCCESS [0] retry_attempts=0 url='http://backend.example.com:``/path/'
6+
`` CONNECT : EIO [5] connecting to 0.0.0.2:`` for host='example.com' url='http://backend.example.com:``/path/' fail_count='2' marking down
7+
`` DNS Error: no valid server http://backend.example.com:``/path/
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
#
18+
# This replay file assumes that caching is enabled.
19+
#
20+
21+
meta:
22+
version: "1.0"
23+
24+
# Configuration section for autest integration
25+
autest:
26+
description: 'Verify connect attempts behavior - round robin'
27+
28+
dns:
29+
name: 'dns-rr'
30+
records: {"backend.example.com": ["0.0.0.1", "0.0.0.2"]}
31+
32+
server:
33+
name: 'server-rr'
34+
35+
client:
36+
name: 'client-rr'
37+
38+
ats:
39+
name: 'ts-rr'
40+
process_config:
41+
enable_cache: false
42+
43+
records_config:
44+
proxy.config.diags.debug.enabled: 1
45+
proxy.config.diags.debug.tags: 'http|hostdb|dns'
46+
proxy.config.http.connect_attempts_rr_retries: 0
47+
proxy.config.http.connect_attempts_max_retries: 2
48+
proxy.config.http.connect_attempts_max_retries_down_server: 0
49+
proxy.config.http.connect_attempts_timeout: 1
50+
proxy.config.http.down_server.cache_time: 5
51+
52+
remap_config:
53+
- from: "http://example.com/"
54+
to: "http://backend.example.com:{SERVER_HTTP_PORT}/"
55+
56+
log_validation:
57+
error_log:
58+
gold_file: "gold/connect_attempts_rr_max_retries_error_log.gold"
59+
60+
sessions:
61+
- transactions:
62+
# try 0.0.0.1
63+
- client-request:
64+
method: GET
65+
url: /path/
66+
version: '1.1'
67+
headers:
68+
fields:
69+
- [Host, example.com]
70+
- [uuid, 1]
71+
72+
# should not hit
73+
server-response:
74+
status: 200
75+
reason: OK
76+
77+
proxy-response:
78+
status: 502
79+
80+
# try 0.0.0.2
81+
- client-request:
82+
method: GET
83+
url: /path/
84+
version: '1.1'
85+
headers:
86+
fields:
87+
- [Host, example.com]
88+
- [uuid, 2]
89+
90+
# should not hit
91+
server-response:
92+
status: 200
93+
reason: OK
94+
95+
proxy-response:
96+
status: 502
97+
98+
# request expected hit down_server cache and immidiately get 500
99+
- client-request:
100+
method: GET
101+
url: /path/
102+
version: '1.1'
103+
headers:
104+
fields:
105+
- [Host, example.com]
106+
- [uuid, 10]
107+
108+
# should not hit
109+
server-response:
110+
status: 200
111+
reason: OK
112+
113+
proxy-response:
114+
status: 500
115+
116+
# when down_server.cache_time is expired, try connect attempts
117+
- client-request:
118+
method: GET
119+
url: /path/
120+
version: '1.1'
121+
headers:
122+
fields:
123+
- [Host, example.com]
124+
- [uuid, 20]
125+
delay: 10s
126+
127+
# should not hit
128+
server-response:
129+
status: 200
130+
reason: OK
131+
132+
proxy-response:
133+
status: 502
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
#
18+
# This replay file assumes that caching is enabled.
19+
#
20+
21+
meta:
22+
version: "1.0"
23+
24+
# Configuration section for autest integration
25+
autest:
26+
description: 'Verify connect attempts behavior - no retry'
27+
28+
dns:
29+
name: 'dns-no'
30+
records: {"backend.example.com": ["0.0.0.1", "0.0.0.2"]}
31+
32+
server:
33+
name: 'server-no'
34+
35+
client:
36+
name: 'client-no'
37+
38+
ats:
39+
name: 'ts-no'
40+
process_config:
41+
enable_cache: false
42+
43+
records_config:
44+
proxy.config.diags.debug.enabled: 1
45+
proxy.config.diags.debug.tags: 'http|hostdb|dns'
46+
proxy.config.http.connect_attempts_rr_retries: 0
47+
proxy.config.http.connect_attempts_max_retries: 0
48+
proxy.config.http.connect_attempts_max_retries_down_server: 0
49+
proxy.config.http.connect_attempts_timeout: 1
50+
proxy.config.http.down_server.cache_time: 5
51+
52+
remap_config:
53+
- from: "http://example.com/"
54+
to: "http://backend.example.com:{SERVER_HTTP_PORT}/"
55+
56+
log_validation:
57+
error_log:
58+
gold_file: "gold/connect_attempts_rr_no_error_log.gold"
59+
60+
sessions:
61+
- transactions:
62+
# try 0.0.0.1
63+
- client-request:
64+
method: GET
65+
url: /path/
66+
version: '1.1'
67+
headers:
68+
fields:
69+
- [Host, example.com]
70+
- [uuid, 1]
71+
72+
# should not hit
73+
server-response:
74+
status: 200
75+
reason: OK
76+
77+
proxy-response:
78+
status: 502
79+
80+
# try 0.0.0.2
81+
- client-request:
82+
method: GET
83+
url: /path/
84+
version: '1.1'
85+
headers:
86+
fields:
87+
- [Host, example.com]
88+
- [uuid, 2]
89+
90+
# should not hit
91+
server-response:
92+
status: 200
93+
reason: OK
94+
95+
proxy-response:
96+
status: 502
97+
98+
# request expected hit down_server cache and immidiately get 500
99+
- client-request:
100+
method: GET
101+
url: /path/
102+
version: '1.1'
103+
headers:
104+
fields:
105+
- [Host, example.com]
106+
- [uuid, 10]
107+
108+
# should not hit
109+
server-response:
110+
status: 200
111+
reason: OK
112+
113+
proxy-response:
114+
status: 500
115+
116+
# when down_server.cache_time is expired, try connect attempts
117+
- client-request:
118+
method: GET
119+
url: /path/
120+
version: '1.1'
121+
headers:
122+
fields:
123+
- [Host, example.com]
124+
- [uuid, 20]
125+
delay: 10s
126+
127+
# should not hit
128+
server-response:
129+
status: 200
130+
reason: OK
131+
132+
proxy-response:
133+
status: 502

0 commit comments

Comments
 (0)