From f4359668ab8631af3301671090c7bd6e305b9439 Mon Sep 17 00:00:00 2001 From: Emmanuel Espitia Rea Date: Thu, 3 Jan 2019 17:48:34 -0600 Subject: [PATCH 1/4] Added an option to disable persistent connections --- pyresttest/resttest.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyresttest/resttest.py b/pyresttest/resttest.py index 0344746e..443e32eb 100644 --- a/pyresttest/resttest.py +++ b/pyresttest/resttest.py @@ -110,6 +110,7 @@ class TestConfig: interactive = False verbose = False ssl_insecure = False + non_persistent = False # Disables keep-alive pycurl option skip_term_colors = False # Turn off output term colors # Binding and creation of generators @@ -331,6 +332,8 @@ def run_test(mytest, test_config=TestConfig(), context=None, curl_handle=None, * if test_config.ssl_insecure: curl.setopt(pycurl.SSL_VERIFYPEER, 0) curl.setopt(pycurl.SSL_VERIFYHOST, 0) + if test_config.non_persistent: + curl.setopt(pycurl.CURLOPT_TCP_KEEPALIVE, 0) result.passed = None @@ -853,6 +856,9 @@ def main(args): if 'ssl_insecure' in args and args['ssl_insecure'] is not None: t.config.ssl_insecure = safe_to_bool(args['ssl_insecure']) + + if 'non_persistent' in args and args['non_persistent'] is not None: + t.config.non_persistent = safe_to_bool(args['non_persistent']) if 'skip_term_colors' in args and args['skip_term_colors'] is not None: t.config.skip_term_colors = safe_to_bool(args['skip_term_colors']) @@ -887,6 +893,8 @@ def parse_command_line_args(args_in): action='store_true', default=False, dest="verbose") parser.add_option(u'--ssl-insecure', help='Disable cURL host and peer cert verification', action='store_true', default=False, dest="ssl_insecure") + parser.add_option(u'--non-persistent', help='Disables persistent connections', + action='store_true', default=False, dest="non_persistent") parser.add_option(u'--absolute-urls', help='Enable absolute URLs in tests instead of relative paths', action="store_true", dest="absolute_urls") parser.add_option(u'--skip_term_colors', help='Turn off the output term colors', From 0e3452fbea2a6186a47d706dd0f551cc44b4e677 Mon Sep 17 00:00:00 2001 From: Emmanuel Espitia Rea Date: Fri, 4 Jan 2019 12:27:15 -0600 Subject: [PATCH 2/4] Normalized name --- pyresttest/resttest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyresttest/resttest.py b/pyresttest/resttest.py index 443e32eb..41331671 100644 --- a/pyresttest/resttest.py +++ b/pyresttest/resttest.py @@ -333,7 +333,7 @@ def run_test(mytest, test_config=TestConfig(), context=None, curl_handle=None, * curl.setopt(pycurl.SSL_VERIFYPEER, 0) curl.setopt(pycurl.SSL_VERIFYHOST, 0) if test_config.non_persistent: - curl.setopt(pycurl.CURLOPT_TCP_KEEPALIVE, 0) + curl.setopt(pycurl.TCP_KEEPALIVE, 0) result.passed = None From 04af7d62ecb6e5160598e57bd497ff325d340bb5 Mon Sep 17 00:00:00 2001 From: Emmanuel Espitia Rea Date: Fri, 4 Jan 2019 13:03:19 -0600 Subject: [PATCH 3/4] Reset prior to reuse --- pyresttest/resttest.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyresttest/resttest.py b/pyresttest/resttest.py index 41331671..c57eaff8 100644 --- a/pyresttest/resttest.py +++ b/pyresttest/resttest.py @@ -662,6 +662,9 @@ def run_testsets(testsets): group_results[test.group] = list() group_failure_counts[test.group] = 0 + # Reuse handle, but clean first + if curl_handle: + curl_handle.reset() result = run_test(test, test_config=myconfig, context=context, curl_handle=curl_handle) result.body = None # Remove the body, save some memory! From c79bd9ab4d84b619676ad2ac7a01f6ccb835687c Mon Sep 17 00:00:00 2001 From: Emmanuel Espitia Rea Date: Sat, 5 Jan 2019 07:05:47 -0600 Subject: [PATCH 4/4] Do not reuse handles, pycurl already takes care of it --- pyresttest/resttest.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pyresttest/resttest.py b/pyresttest/resttest.py index c57eaff8..62faf994 100644 --- a/pyresttest/resttest.py +++ b/pyresttest/resttest.py @@ -632,7 +632,6 @@ def run_testsets(testsets): group_failure_counts = dict() total_failures = 0 myinteractive = False - curl_handle = pycurl.Curl() for testset in testsets: mytests = testset.tests @@ -662,10 +661,7 @@ def run_testsets(testsets): group_results[test.group] = list() group_failure_counts[test.group] = 0 - # Reuse handle, but clean first - if curl_handle: - curl_handle.reset() - result = run_test(test, test_config=myconfig, context=context, curl_handle=curl_handle) + result = run_test(test, test_config=myconfig, context=context) result.body = None # Remove the body, save some memory! if not result.passed: # Print failure, increase failure counts for that test group