test_03_goaway.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 time
  29. from datetime import timedelta
  30. from threading import Thread
  31. import pytest
  32. from testenv import Env, CurlClient, ExecResult
  33. log = logging.getLogger(__name__)
  34. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  35. class TestGoAway:
  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 files sequentially with delay, reload server for GOAWAY
  43. def test_03_01_h2_goaway(self, env: Env, httpd, nghttpx, repeat):
  44. proto = 'h2'
  45. count = 3
  46. self.r = None
  47. def long_run():
  48. curl = CurlClient(env=env)
  49. # send 10 chunks of 1024 bytes in a response body with 100ms delay in between
  50. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  51. f'/curltest/tweak?id=[0-{count - 1}]'\
  52. '&chunks=10&chunk_size=1024&chunk_delay=100ms'
  53. self.r = curl.http_download(urls=[urln], alpn_proto=proto)
  54. t = Thread(target=long_run)
  55. t.start()
  56. # each request will take a second, reload the server in the middle
  57. # of the first one.
  58. time.sleep(1.5)
  59. assert httpd.reload()
  60. t.join()
  61. r: ExecResult = self.r
  62. r.check_response(count=count, http_status=200)
  63. # reload will shut down the connection gracefully with GOAWAY
  64. # we expect to see a second connection opened afterwards
  65. assert r.total_connects == 2
  66. for idx, s in enumerate(r.stats):
  67. if s['num_connects'] > 0:
  68. log.debug(f'request {idx} connected')
  69. # this should take `count` seconds to retrieve
  70. assert r.duration >= timedelta(seconds=count)
  71. # download files sequentially with delay, reload server for GOAWAY
  72. @pytest.mark.skipif(condition=not Env.have_h3(), reason="h3 not supported")
  73. def test_03_02_h3_goaway(self, env: Env, httpd, nghttpx, repeat):
  74. proto = 'h3'
  75. if proto == 'h3' and env.curl_uses_lib('msh3'):
  76. pytest.skip("msh3 stalls here")
  77. if proto == 'h3' and env.curl_uses_lib('quiche'):
  78. pytest.skip("does not work in CI, but locally for some reason")
  79. if proto == 'h3' and env.curl_uses_ossl_quic():
  80. pytest.skip('OpenSSL QUIC fails here')
  81. count = 3
  82. self.r = None
  83. def long_run():
  84. curl = CurlClient(env=env)
  85. # send 10 chunks of 1024 bytes in a response body with 100ms delay in between
  86. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  87. f'/curltest/tweak?id=[0-{count - 1}]'\
  88. '&chunks=10&chunk_size=1024&chunk_delay=100ms'
  89. self.r = curl.http_download(urls=[urln], alpn_proto=proto)
  90. t = Thread(target=long_run)
  91. t.start()
  92. # each request will take a second, reload the server in the middle
  93. # of the first one.
  94. time.sleep(1.5)
  95. assert nghttpx.reload(timeout=timedelta(seconds=2))
  96. t.join()
  97. r: ExecResult = self.r
  98. # this should take `count` seconds to retrieve, maybe a little less
  99. assert r.duration >= timedelta(seconds=count-1)
  100. r.check_response(count=count, http_status=200, connect_count=2)
  101. # reload will shut down the connection gracefully with GOAWAY
  102. # we expect to see a second connection opened afterwards
  103. for idx, s in enumerate(r.stats):
  104. if s['num_connects'] > 0:
  105. log.debug(f'request {idx} connected')
  106. # download files sequentially with delay, reload server for GOAWAY
  107. def test_03_03_h1_goaway(self, env: Env, httpd, nghttpx, repeat):
  108. proto = 'http/1.1'
  109. count = 3
  110. self.r = None
  111. def long_run():
  112. curl = CurlClient(env=env)
  113. # send 10 chunks of 1024 bytes in a response body with 100ms delay in between
  114. # pause 2 seconds between requests
  115. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  116. f'/curltest/tweak?id=[0-{count - 1}]'\
  117. '&chunks=10&chunk_size=1024&chunk_delay=100ms'
  118. self.r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  119. '--rate', '30/m',
  120. ])
  121. t = Thread(target=long_run)
  122. t.start()
  123. # each request will take a second, reload the server in the middle
  124. # of the first one.
  125. time.sleep(1.5)
  126. assert httpd.reload()
  127. t.join()
  128. r: ExecResult = self.r
  129. r.check_response(count=count, http_status=200, connect_count=2)
  130. # reload will shut down the connection gracefully
  131. # we expect to see a second connection opened afterwards
  132. for idx, s in enumerate(r.stats):
  133. if s['num_connects'] > 0:
  134. log.debug(f'request {idx} connected')
  135. # this should take `count` seconds to retrieve
  136. assert r.duration >= timedelta(seconds=count)