test_08_caddy.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. import pytest
  30. from testenv import Env, CurlClient, Caddy
  31. log = logging.getLogger(__name__)
  32. @pytest.mark.skipif(condition=not Env.has_caddy(), reason=f"missing caddy")
  33. @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason=f"curl without SSL")
  34. class TestCaddy:
  35. @pytest.fixture(autouse=True, scope='class')
  36. def caddy(self, env):
  37. caddy = Caddy(env=env)
  38. assert caddy.start()
  39. yield caddy
  40. caddy.stop()
  41. def _make_docs_file(self, docs_dir: str, fname: str, fsize: int):
  42. fpath = os.path.join(docs_dir, fname)
  43. data1k = 1024*'x'
  44. flen = 0
  45. with open(fpath, 'w') as fd:
  46. while flen < fsize:
  47. fd.write(data1k)
  48. flen += len(data1k)
  49. return flen
  50. @pytest.fixture(autouse=True, scope='class')
  51. def _class_scope(self, env, caddy):
  52. self._make_docs_file(docs_dir=caddy.docs_dir, fname='data1.data', fsize=1024*1024)
  53. self._make_docs_file(docs_dir=caddy.docs_dir, fname='data5.data', fsize=5*1024*1024)
  54. self._make_docs_file(docs_dir=caddy.docs_dir, fname='data10.data', fsize=10*1024*1024)
  55. self._make_docs_file(docs_dir=caddy.docs_dir, fname='data100.data', fsize=100*1024*1024)
  56. # download 1 file
  57. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  58. def test_08_01_download_1(self, env: Env, caddy: Caddy, repeat, proto):
  59. if proto == 'h3' and not env.have_h3_curl():
  60. pytest.skip("h3 not supported in curl")
  61. if proto == 'h3' and env.curl_uses_lib('msh3'):
  62. pytest.skip("msh3 itself crashes")
  63. curl = CurlClient(env=env)
  64. url = f'https://{env.domain1}:{caddy.port}/data.json'
  65. r = curl.http_download(urls=[url], alpn_proto=proto)
  66. r.check_response(count=1, http_status=200)
  67. # download 1MB files sequentially
  68. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  69. def test_08_02_download_1mb_sequential(self, env: Env, caddy: Caddy,
  70. repeat, proto):
  71. if proto == 'h3' and not env.have_h3_curl():
  72. pytest.skip("h3 not supported in curl")
  73. if proto == 'h3' and env.curl_uses_lib('msh3'):
  74. pytest.skip("msh3 itself crashes")
  75. count = 50
  76. curl = CurlClient(env=env)
  77. urln = f'https://{env.domain1}:{caddy.port}/data1.data?[0-{count-1}]'
  78. r = curl.http_download(urls=[urln], alpn_proto=proto)
  79. r.check_response(count=count, http_status=200, connect_count=1)
  80. # download 1MB files parallel
  81. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  82. def test_08_03_download_1mb_parallel(self, env: Env, caddy: Caddy,
  83. repeat, proto):
  84. if proto == 'h3' and not env.have_h3_curl():
  85. pytest.skip("h3 not supported in curl")
  86. if proto == 'h3' and env.curl_uses_lib('msh3'):
  87. pytest.skip("msh3 itself crashes")
  88. count = 20
  89. curl = CurlClient(env=env)
  90. urln = f'https://{env.domain1}:{caddy.port}/data1.data?[0-{count-1}]'
  91. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  92. '--parallel'
  93. ])
  94. r.check_response(count=count, http_status=200)
  95. if proto == 'http/1.1':
  96. # http/1.1 parallel transfers will open multiple connections
  97. assert r.total_connects > 1, r.dump_logs()
  98. else:
  99. assert r.total_connects == 1, r.dump_logs()
  100. # download 5MB files sequentially
  101. @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
  102. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  103. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  104. def test_08_04a_download_10mb_sequential(self, env: Env, caddy: Caddy,
  105. repeat, proto):
  106. if proto == 'h3' and not env.have_h3_curl():
  107. pytest.skip("h3 not supported in curl")
  108. if proto == 'h3' and env.curl_uses_lib('msh3'):
  109. pytest.skip("msh3 itself crashes")
  110. count = 40
  111. curl = CurlClient(env=env)
  112. urln = f'https://{env.domain1}:{caddy.port}/data5.data?[0-{count-1}]'
  113. r = curl.http_download(urls=[urln], alpn_proto=proto)
  114. r.check_response(count=count, http_status=200, connect_count=1)
  115. # download 10MB files sequentially
  116. @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
  117. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  118. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  119. def test_08_04b_download_10mb_sequential(self, env: Env, caddy: Caddy,
  120. repeat, proto):
  121. if proto == 'h3' and not env.have_h3_curl():
  122. pytest.skip("h3 not supported in curl")
  123. if proto == 'h3' and env.curl_uses_lib('msh3'):
  124. pytest.skip("msh3 itself crashes")
  125. count = 20
  126. curl = CurlClient(env=env)
  127. urln = f'https://{env.domain1}:{caddy.port}/data10.data?[0-{count-1}]'
  128. r = curl.http_download(urls=[urln], alpn_proto=proto)
  129. r.check_response(count=count, http_status=200, connect_count=1)
  130. # download 10MB files parallel
  131. @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
  132. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  133. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  134. def test_08_05_download_1mb_parallel(self, env: Env, caddy: Caddy,
  135. repeat, proto):
  136. if proto == 'h3' and not env.have_h3_curl():
  137. pytest.skip("h3 not supported in curl")
  138. if proto == 'h3' and env.curl_uses_lib('msh3'):
  139. pytest.skip("msh3 itself crashes")
  140. count = 50
  141. curl = CurlClient(env=env)
  142. urln = f'https://{env.domain1}:{caddy.port}/data10.data?[0-{count-1}]'
  143. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  144. '--parallel'
  145. ])
  146. r.check_response(count=count, http_status=200)
  147. if proto == 'http/1.1':
  148. # http/1.1 parallel transfers will open multiple connections
  149. assert r.total_connects > 1, r.dump_logs()
  150. else:
  151. assert r.total_connects == 1, r.dump_logs()