test_03_goaway.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. count = 3
  80. self.r = None
  81. def long_run():
  82. curl = CurlClient(env=env)
  83. # send 10 chunks of 1024 bytes in a response body with 100ms delay in between
  84. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  85. f'/curltest/tweak?id=[0-{count - 1}]'\
  86. '&chunks=10&chunk_size=1024&chunk_delay=100ms'
  87. self.r = curl.http_download(urls=[urln], alpn_proto=proto)
  88. t = Thread(target=long_run)
  89. t.start()
  90. # each request will take a second, reload the server in the middle
  91. # of the first one.
  92. time.sleep(1.5)
  93. assert nghttpx.reload(timeout=timedelta(seconds=2))
  94. t.join()
  95. r: ExecResult = self.r
  96. # this should take `count` seconds to retrieve
  97. assert r.duration >= timedelta(seconds=count)
  98. r.check_response(count=count, http_status=200, connect_count=2)
  99. # reload will shut down the connection gracefully with GOAWAY
  100. # we expect to see a second connection opened afterwards
  101. for idx, s in enumerate(r.stats):
  102. if s['num_connects'] > 0:
  103. log.debug(f'request {idx} connected')
  104. # download files sequentially with delay, reload server for GOAWAY
  105. def test_03_03_h1_goaway(self, env: Env, httpd, nghttpx, repeat):
  106. proto = 'http/1.1'
  107. count = 3
  108. self.r = None
  109. def long_run():
  110. curl = CurlClient(env=env)
  111. # send 10 chunks of 1024 bytes in a response body with 100ms delay in between
  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)
  116. t = Thread(target=long_run)
  117. t.start()
  118. # each request will take a second, reload the server in the middle
  119. # of the first one.
  120. time.sleep(1.5)
  121. assert httpd.reload()
  122. t.join()
  123. r: ExecResult = self.r
  124. r.check_response(count=count, http_status=200, connect_count=2)
  125. # reload will shut down the connection gracefully with GOAWAY
  126. # we expect to see a second connection opened afterwards
  127. for idx, s in enumerate(r.stats):
  128. if s['num_connects'] > 0:
  129. log.debug(f'request {idx} connected')
  130. # this should take `count` seconds to retrieve
  131. assert r.duration >= timedelta(seconds=count)