test_03_goaway.py 5.6 KB

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