2
0

test_04_stuttered.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #***************************************************************************
  4. # _ _ ____ _
  5. # Project ___| | | | _ \| |
  6. # / __| | | | |_) | |
  7. # | (__| |_| | _ <| |___
  8. # \___|\___/|_| \_\_____|
  9. #
  10. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  11. #
  12. # This software is licensed as described in the file COPYING, which
  13. # you should have received as part of this distribution. The terms
  14. # are also available at https://curl.se/docs/copyright.html.
  15. #
  16. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. # copies of the Software, and permit persons to whom the Software is
  18. # furnished to do so, under the terms of the COPYING file.
  19. #
  20. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. # KIND, either express or implied.
  22. #
  23. # SPDX-License-Identifier: curl
  24. #
  25. ###########################################################################
  26. #
  27. import logging
  28. from typing import Tuple, List, Dict
  29. import pytest
  30. from testenv import Env, CurlClient
  31. log = logging.getLogger(__name__)
  32. @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
  33. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  34. class TestStuttered:
  35. @pytest.fixture(autouse=True, scope='class')
  36. def _class_scope(self, env, httpd, nghttpx):
  37. if env.have_h3():
  38. nghttpx.start_if_needed()
  39. httpd.clear_extra_configs()
  40. httpd.reload()
  41. # download 1 file, check that delayed response works in general
  42. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  43. def test_04_01_download_1(self, env: Env, httpd, nghttpx, repeat,
  44. proto):
  45. if proto == 'h3' and not env.have_h3():
  46. pytest.skip("h3 not supported")
  47. count = 1
  48. curl = CurlClient(env=env)
  49. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  50. f'/curltest/tweak?id=[0-{count - 1}]'\
  51. '&chunks=100&chunk_size=100&chunk_delay=10ms'
  52. r = curl.http_download(urls=[urln], alpn_proto=proto)
  53. r.check_response(count=1, http_status=200)
  54. # download 50 files in 100 chunks a 100 bytes with 10ms delay between
  55. # prepend 100 file requests to warm up connection processing limits
  56. # (Apache2 increases # of parallel processed requests after successes)
  57. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  58. def test_04_02_100_100_10(self, env: Env,
  59. httpd, nghttpx, repeat, proto):
  60. if proto == 'h3' and not env.have_h3():
  61. pytest.skip("h3 not supported")
  62. count = 50
  63. warmups = 100
  64. curl = CurlClient(env=env)
  65. url1 = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{warmups-1}]'
  66. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  67. f'/curltest/tweak?id=[0-{count-1}]'\
  68. '&chunks=100&chunk_size=100&chunk_delay=10ms'
  69. r = curl.http_download(urls=[url1, urln], alpn_proto=proto,
  70. extra_args=['--parallel'])
  71. r.check_response(count=warmups+count, http_status=200)
  72. assert r.total_connects == 1
  73. t_avg, i_min, t_min, i_max, t_max = self.stats_spread(r.stats[warmups:], 'time_total')
  74. if t_max < (5 * t_min) and t_min < 2:
  75. log.warning(f'avg time of transfer: {t_avg} [{i_min}={t_min}, {i_max}={t_max}]')
  76. # download 50 files in 1000 chunks a 10 bytes with 1ms delay between
  77. # prepend 100 file requests to warm up connection processing limits
  78. # (Apache2 increases # of parallel processed requests after successes)
  79. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  80. def test_04_03_1000_10_1(self, env: Env, httpd, nghttpx, repeat, proto):
  81. if proto == 'h3' and not env.have_h3():
  82. pytest.skip("h3 not supported")
  83. count = 50
  84. warmups = 100
  85. curl = CurlClient(env=env)
  86. url1 = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{warmups-1}]'
  87. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  88. f'/curltest/tweak?id=[0-{count - 1}]'\
  89. '&chunks=1000&chunk_size=10&chunk_delay=100us'
  90. r = curl.http_download(urls=[url1, urln], alpn_proto=proto,
  91. extra_args=['--parallel'])
  92. r.check_response(count=warmups+count, http_status=200)
  93. assert r.total_connects == 1
  94. t_avg, i_min, t_min, i_max, t_max = self.stats_spread(r.stats[warmups:], 'time_total')
  95. if t_max < (5 * t_min):
  96. log.warning(f'avg time of transfer: {t_avg} [{i_min}={t_min}, {i_max}={t_max}]')
  97. # download 50 files in 10000 chunks a 1 byte with 10us delay between
  98. # prepend 100 file requests to warm up connection processing limits
  99. # (Apache2 increases # of parallel processed requests after successes)
  100. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  101. def test_04_04_1000_10_1(self, env: Env, httpd, nghttpx, repeat, proto):
  102. if proto == 'h3' and not env.have_h3():
  103. pytest.skip("h3 not supported")
  104. count = 50
  105. warmups = 100
  106. curl = CurlClient(env=env)
  107. url1 = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{warmups-1}]'
  108. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  109. f'/curltest/tweak?id=[0-{count - 1}]'\
  110. '&chunks=10000&chunk_size=1&chunk_delay=50us'
  111. r = curl.http_download(urls=[url1, urln], alpn_proto=proto,
  112. extra_args=['--parallel'])
  113. r.check_response(count=warmups+count, http_status=200)
  114. assert r.total_connects == 1
  115. t_avg, i_min, t_min, i_max, t_max = self.stats_spread(r.stats[warmups:], 'time_total')
  116. if t_max < (5 * t_min):
  117. log.warning(f'avg time of transfer: {t_avg} [{i_min}={t_min}, {i_max}={t_max}]')
  118. def stats_spread(self, stats: List[Dict], key: str) -> Tuple[float, int, float, int, float]:
  119. stotals = 0.0
  120. s_min = 100.0
  121. i_min = -1
  122. s_max = 0.0
  123. i_max = -1
  124. for idx, s in enumerate(stats):
  125. val = float(s[key])
  126. stotals += val
  127. if val > s_max:
  128. s_max = val
  129. i_max = idx
  130. if val < s_min:
  131. s_min = val
  132. i_min = idx
  133. return stotals/len(stats), i_min, s_min, i_max, s_max