Path: blob/main/external/curl/tests/http/test_04_stuttered.py
2066 views
#!/usr/bin/env python31# -*- coding: utf-8 -*-2#***************************************************************************3# _ _ ____ _4# Project ___| | | | _ \| |5# / __| | | | |_) | |6# | (__| |_| | _ <| |___7# \___|\___/|_| \_\_____|8#9# Copyright (C) Daniel Stenberg, <[email protected]>, et al.10#11# This software is licensed as described in the file COPYING, which12# you should have received as part of this distribution. The terms13# are also available at https://curl.se/docs/copyright.html.14#15# You may opt to use, copy, modify, merge, publish, distribute and/or sell16# copies of the Software, and permit persons to whom the Software is17# furnished to do so, under the terms of the COPYING file.18#19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY20# KIND, either express or implied.21#22# SPDX-License-Identifier: curl23#24###########################################################################25#26import logging27from typing import Tuple, List, Dict28import pytest2930from testenv import Env, CurlClient313233log = logging.getLogger(__name__)343536@pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")37@pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")38class TestStuttered:3940# download 1 file, check that delayed response works in general41@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])42def test_04_01_download_1(self, env: Env, httpd, nghttpx, proto):43if proto == 'h3' and not env.have_h3():44pytest.skip("h3 not supported")45count = 146curl = CurlClient(env=env)47urln = f'https://{env.authority_for(env.domain1, proto)}' \48f'/curltest/tweak?id=[0-{count - 1}]'\49'&chunks=100&chunk_size=100&chunk_delay=10ms'50r = curl.http_download(urls=[urln], alpn_proto=proto)51r.check_response(count=1, http_status=200)5253# download 50 files in 100 chunks a 100 bytes with 10ms delay between54# prepend 100 file requests to warm up connection processing limits55# (Apache2 increases # of parallel processed requests after successes)56@pytest.mark.parametrize("proto", ['h2', 'h3'])57def test_04_02_100_100_10(self, env: Env, httpd, nghttpx, proto):58if proto == 'h3' and not env.have_h3():59pytest.skip("h3 not supported")60count = 5061warmups = 10062curl = CurlClient(env=env)63url1 = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{warmups-1}]'64urln = f'https://{env.authority_for(env.domain1, proto)}' \65f'/curltest/tweak?id=[0-{count-1}]'\66'&chunks=100&chunk_size=100&chunk_delay=10ms'67r = curl.http_download(urls=[url1, urln], alpn_proto=proto,68extra_args=['--parallel'])69r.check_response(count=warmups+count, http_status=200)70assert r.total_connects == 171t_avg, i_min, t_min, i_max, t_max = self.stats_spread(r.stats[warmups:], 'time_total')72if t_max < (5 * t_min) and t_min < 2:73log.warning(f'avg time of transfer: {t_avg} [{i_min}={t_min}, {i_max}={t_max}]')7475# download 50 files in 1000 chunks a 10 bytes with 1ms delay between76# prepend 100 file requests to warm up connection processing limits77# (Apache2 increases # of parallel processed requests after successes)78@pytest.mark.parametrize("proto", ['h2', 'h3'])79def test_04_03_1000_10_1(self, env: Env, httpd, nghttpx, proto):80if proto == 'h3' and not env.have_h3():81pytest.skip("h3 not supported")82count = 5083warmups = 10084curl = CurlClient(env=env)85url1 = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{warmups-1}]'86urln = f'https://{env.authority_for(env.domain1, proto)}' \87f'/curltest/tweak?id=[0-{count - 1}]'\88'&chunks=1000&chunk_size=10&chunk_delay=100us'89r = curl.http_download(urls=[url1, urln], alpn_proto=proto,90extra_args=['--parallel'])91r.check_response(count=warmups+count, http_status=200)92assert r.total_connects == 193t_avg, i_min, t_min, i_max, t_max = self.stats_spread(r.stats[warmups:], 'time_total')94if t_max < (5 * t_min):95log.warning(f'avg time of transfer: {t_avg} [{i_min}={t_min}, {i_max}={t_max}]')9697# download 50 files in 10000 chunks a 1 byte with 10us delay between98# prepend 100 file requests to warm up connection processing limits99# (Apache2 increases # of parallel processed requests after successes)100@pytest.mark.parametrize("proto", ['h2', 'h3'])101def test_04_04_1000_10_1(self, env: Env, httpd, nghttpx, proto):102if proto == 'h3' and not env.have_h3():103pytest.skip("h3 not supported")104count = 50105warmups = 100106curl = CurlClient(env=env)107url1 = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{warmups-1}]'108urln = f'https://{env.authority_for(env.domain1, proto)}' \109f'/curltest/tweak?id=[0-{count - 1}]'\110'&chunks=10000&chunk_size=1&chunk_delay=50us'111r = curl.http_download(urls=[url1, urln], alpn_proto=proto,112extra_args=['--parallel'])113r.check_response(count=warmups+count, http_status=200)114assert r.total_connects == 1115t_avg, i_min, t_min, i_max, t_max = self.stats_spread(r.stats[warmups:], 'time_total')116if t_max < (5 * t_min):117log.warning(f'avg time of transfer: {t_avg} [{i_min}={t_min}, {i_max}={t_max}]')118119def stats_spread(self, stats: List[Dict], key: str) -> Tuple[float, int, float, int, float]:120stotals = 0.0121s_min = 100.0122i_min = -1123s_max = 0.0124i_max = -1125for idx, s in enumerate(stats):126val = float(s[key])127stotals += val128if val > s_max:129s_max = val130i_max = idx131if val < s_min:132s_min = val133i_min = idx134return stotals/len(stats), i_min, s_min, i_max, s_max135136137