##// END OF EJS Templates
tests: make the routing link tests retry connections. Reduced test failures
marcink -
r2139:665d2e32 default
parent child Browse files
Show More
@@ -1,49 +1,73 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2017 RhodeCode GmbH
3 # Copyright (C) 2010-2017 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import pytest
21 import pytest
22 import requests
22 import requests
23 from rhodecode.config import routing_links
23 from rhodecode.config import routing_links
24
24
25
25
26 def check_connection():
26 def check_connection():
27 try:
27 try:
28 response = requests.get('https://rhodecode.com')
28 response = requests.get('https://rhodecode.com')
29 return response.status_code == 200
29 return response.status_code == 200
30 except Exception as e:
30 except Exception as e:
31 print(e)
31 print(e)
32
32
33 return False
33 return False
34
34
35
35
36 connection_available = pytest.mark.skipif(
36 connection_available = pytest.mark.skipif(
37 not check_connection(), reason="No outside internet connection available")
37 not check_connection(), reason="No outside internet connection available")
38
38
39
39
40 @connection_available
40 import requests
41 def test_connect_redirection_links():
41 from requests.adapters import HTTPAdapter
42 from requests.packages.urllib3.util.retry import Retry
43
42
44
43 for link_data in routing_links.link_config:
45 def requests_retry_session(
44 response = requests.get(link_data['target'])
46 retries=3,
45 if link_data['name'] == 'enterprise_license_convert_from_old':
47 backoff_factor=0.3,
46 # special case for a page that requires a valid login
48 status_forcelist=(500, 502, 504),
47 assert response.url == 'https://rhodecode.com/login'
49 session=None,
48 else:
50 ):
49 assert response.url == link_data['external_target']
51 session = session or requests.Session()
52 retry = Retry(
53 total=retries,
54 read=retries,
55 connect=retries,
56 backoff_factor=backoff_factor,
57 status_forcelist=status_forcelist,
58 )
59 adapter = HTTPAdapter(max_retries=retry)
60 session.mount('http://', adapter)
61 session.mount('https://', adapter)
62 return session
63
64
65 @connection_available
66 @pytest.mark.parametrize('link_data', routing_links.link_config)
67 def test_connect_redirection_links(link_data):
68 response = requests_retry_session().get(link_data['target'])
69 if link_data['name'] == 'enterprise_license_convert_from_old':
70 # special case for a page that requires a valid login
71 assert response.url == 'https://rhodecode.com/login'
72 else:
73 assert response.url == link_data['external_target']
General Comments 0
You need to be logged in to leave comments. Login now