test_04_stuttered.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. import os
  29. from typing import Tuple, List, Dict
  30. import pytest
  31. from testenv import Env, CurlClient
  32. log = logging.getLogger(__name__)
  33. @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
  34. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  35. class TestStuttered:
  36. @pytest.fixture(autouse=True, scope='class')
  37. def _class_scope(self, env, httpd, nghttpx):
  38. if env.have_h3():
  39. nghttpx.start_if_needed()
  40. httpd.clear_extra_configs()
  41. httpd.reload()
  42. # download 1 file, check that delayed response works in general
  43. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  44. def test_04_01_download_1(self, env: Env, httpd, nghttpx, repeat,
  45. proto):
  46. if proto == 'h3' and not env.have_h3():
  47. pytest.skip("h3 not supported")
  48. count = 1
  49. curl = CurlClient(env=env)
  50. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  51. f'/curltest/tweak?id=[0-{count - 1}]'\
  52. '&chunks=100&chunk_size=100&chunk_delay=10ms'
  53. r = curl.http_download(urls=[urln], alpn_proto=proto)
  54. r.check_response(count=1, http_status=200)
  55. # download 50 files in 100 chunks a 100 bytes with 10ms delay between
  56. # prepend 100 file requests to warm up connection processing limits
  57. # (Apache2 increases # of parallel processed requests after successes)
  58. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  59. def test_04_02_100_100_10(self, env: Env,
  60. httpd, nghttpx, repeat, proto):
  61. if proto == 'h3' and not env.have_h3():
  62. pytest.skip("h3 not supported")
  63. count = 50
  64. warmups = 100
  65. curl = CurlClient(env=env)
  66. url1 = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{warmups-1}]'
  67. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  68. f'/curltest/tweak?id=[0-{count-1}]'\
  69. '&chunks=100&chunk_size=100&chunk_delay=10ms'
  70. r = curl.http_download(urls=[url1, urln], alpn_proto=proto,
  71. extra_args=['--parallel'])
  72. r.check_response(count=warmups+count, http_status=200)
  73. assert r.total_connects == 1
  74. t_avg, i_min, t_min, i_max, t_max = self.stats_spread(r.stats[warmups:], 'time_total')
  75. if t_max < (5 * t_min) and t_min < 2:
  76. log.warning(f'avg time of transfer: {t_avg} [{i_min}={t_min}, {i_max}={t_max}]')
  77. # download 50 files in 1000 chunks a 10 bytes with 1ms delay between
  78. # prepend 100 file requests to warm up connection processing limits
  79. # (Apache2 increases # of parallel processed requests after successes)
  80. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  81. def test_04_03_1000_10_1(self, env: Env, httpd, nghttpx, repeat, proto):
  82. if proto == 'h3' and not env.have_h3():
  83. pytest.skip("h3 not supported")
  84. count = 50
  85. warmups = 100
  86. curl = CurlClient(env=env)
  87. url1 = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{warmups-1}]'
  88. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  89. f'/curltest/tweak?id=[0-{count - 1}]'\
  90. '&chunks=1000&chunk_size=10&chunk_delay=100us'
  91. r = curl.http_download(urls=[url1, urln], alpn_proto=proto,
  92. extra_args=['--parallel'])
  93. r.check_response(count=warmups+count, http_status=200)
  94. assert r.total_connects == 1
  95. t_avg, i_min, t_min, i_max, t_max = self.stats_spread(r.stats[warmups:], 'time_total')
  96. if t_max < (5 * t_min):
  97. log.warning(f'avg time of transfer: {t_avg} [{i_min}={t_min}, {i_max}={t_max}]')
  98. # download 50 files in 10000 chunks a 1 byte with 10us delay between
  99. # prepend 100 file requests to warm up connection processing limits
  100. # (Apache2 increases # of parallel processed requests after successes)
  101. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  102. def test_04_04_1000_10_1(self, env: Env, httpd, nghttpx, repeat, proto):
  103. if proto == 'h3' and not env.have_h3():
  104. pytest.skip("h3 not supported")
  105. count = 50
  106. warmups = 100
  107. curl = CurlClient(env=env)
  108. url1 = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{warmups-1}]'
  109. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  110. f'/curltest/tweak?id=[0-{count - 1}]'\
  111. '&chunks=10000&chunk_size=1&chunk_delay=50us'
  112. r = curl.http_download(urls=[url1, urln], alpn_proto=proto,
  113. extra_args=['--parallel'])
  114. r.check_response(count=warmups+count, http_status=200)
  115. assert r.total_connects == 1
  116. t_avg, i_min, t_min, i_max, t_max = self.stats_spread(r.stats[warmups:], 'time_total')
  117. if t_max < (5 * t_min):
  118. log.warning(f'avg time of transfer: {t_avg} [{i_min}={t_min}, {i_max}={t_max}]')
  119. def stats_spread(self, stats: List[Dict], key: str) -> Tuple[float, int, float, int, float]:
  120. stotals = 0.0
  121. s_min = 100.0
  122. i_min = -1
  123. s_max = 0.0
  124. i_max = -1
  125. for idx, s in enumerate(stats):
  126. val = float(s[key])
  127. stotals += val
  128. if val > s_max:
  129. s_max = val
  130. i_max = idx
  131. if val < s_min:
  132. s_min = val
  133. i_min = idx
  134. return stotals/len(stats), i_min, s_min, i_max, s_max