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