2
0

test_08_caddy.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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.parametrize("proto", ['h2', 'h3'])
  102. def test_08_04a_download_10mb_sequential(self, env: Env, caddy: Caddy,
  103. repeat, proto):
  104. if proto == 'h3' and not env.have_h3_curl():
  105. pytest.skip("h3 not supported in curl")
  106. if proto == 'h3' and env.curl_uses_lib('msh3'):
  107. pytest.skip("msh3 itself crashes")
  108. count = 40
  109. curl = CurlClient(env=env)
  110. urln = f'https://{env.domain1}:{caddy.port}/data5.data?[0-{count-1}]'
  111. r = curl.http_download(urls=[urln], alpn_proto=proto)
  112. r.check_response(count=count, http_status=200, connect_count=1)
  113. # download 10MB files sequentially
  114. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  115. def test_08_04b_download_10mb_sequential(self, env: Env, caddy: Caddy,
  116. repeat, proto):
  117. if proto == 'h3' and not env.have_h3_curl():
  118. pytest.skip("h3 not supported in curl")
  119. if proto == 'h3' and env.curl_uses_lib('msh3'):
  120. pytest.skip("msh3 itself crashes")
  121. count = 20
  122. curl = CurlClient(env=env)
  123. urln = f'https://{env.domain1}:{caddy.port}/data10.data?[0-{count-1}]'
  124. r = curl.http_download(urls=[urln], alpn_proto=proto)
  125. r.check_response(count=count, http_status=200, connect_count=1)
  126. # download 10MB files parallel
  127. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  128. def test_08_05_download_1mb_parallel(self, env: Env, caddy: Caddy,
  129. repeat, proto):
  130. if proto == 'h3' and not env.have_h3_curl():
  131. pytest.skip("h3 not supported in curl")
  132. if proto == 'h3' and env.curl_uses_lib('msh3'):
  133. pytest.skip("msh3 itself crashes")
  134. count = 50
  135. curl = CurlClient(env=env)
  136. urln = f'https://{env.domain1}:{caddy.port}/data10.data?[0-{count-1}]'
  137. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  138. '--parallel'
  139. ])
  140. r.check_response(count=count, http_status=200)
  141. if proto == 'http/1.1':
  142. # http/1.1 parallel transfers will open multiple connections
  143. assert r.total_connects > 1, r.dump_logs()
  144. else:
  145. assert r.total_connects == 1, r.dump_logs()