Skip to content

Commit 304e390

Browse files
committed
tests: Add requests timeout hackery
Timeout requests after 60 seconds Signed-off-by: Cole Robinson <[email protected]>
1 parent b1d6b22 commit 304e390

3 files changed

Lines changed: 27 additions & 12 deletions

File tree

tests/test_ro_functional.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@
2424
def _open_bz(url, **kwargs):
2525
if "use_creds" not in kwargs:
2626
kwargs["use_creds"] = False
27-
bz = bugzilla.Bugzilla(url, **kwargs)
28-
29-
if kwargs.get("force_rest", False):
30-
assert bz.is_rest() is True
31-
if kwargs.get("force_xmlrpc", False):
32-
assert bz.is_xmlrpc() is True
33-
return bz
27+
return tests.utils.open_functional_bz(bugzilla.Bugzilla, url, kwargs)
3428

3529

3630
def _check(out, mincount, expectstr):

tests/test_rw_functional.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ def _split_int(s):
3333
return [int(i) for i in s.split(",")]
3434

3535

36-
if not bugzilla.RHBugzilla(url=RHURL).logged_in:
36+
def _open_bz(**kwargs):
37+
return tests.utils.open_functional_bz(bugzilla.RHBugzilla, RHURL, kwargs)
38+
39+
40+
if not _open_bz().logged_in:
3741
print("\nR/W tests require cached login credentials for url=%s\n" % RHURL)
3842
sys.exit(1)
3943

@@ -50,10 +54,6 @@ def _check_have_admin(bz):
5054
return ret
5155

5256

53-
def _open_bz(**kwargs):
54-
return bugzilla.RHBugzilla(url=RHURL, **kwargs)
55-
56-
5757
def test0LoggedInNoCreds():
5858
bz = _open_bz(use_creds=False)
5959
assert not bz.logged_in

tests/utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@ def monkeypatch_getpass(monkeypatch):
4343
raw_input) # pylint: disable=undefined-variable
4444

4545

46+
def open_functional_bz(bzclass, url, kwargs):
47+
bz = bzclass(url, **kwargs)
48+
49+
if kwargs.get("force_rest", False):
50+
assert bz.is_rest() is True
51+
if kwargs.get("force_xmlrpc", False):
52+
assert bz.is_xmlrpc() is True
53+
54+
# Set a session timeout of 30 seconds
55+
session = bz.get_requests_session()
56+
origrequest = session.request
57+
58+
def fake_request(*args, **kwargs):
59+
if "timeout" not in kwargs:
60+
kwargs["timeout"] = 60
61+
return origrequest(*args, **kwargs)
62+
63+
session.request = fake_request
64+
return bz
65+
66+
4667
def diff_compare(inputdata, filename):
4768
"""Compare passed string output to contents of filename"""
4869
filename = tests_path(filename)

0 commit comments

Comments
 (0)