test_03_goaway.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #***************************************************************************
  4. # _ _ ____ _
  5. # Project ___| | | | _ \| |
  6. # / __| | | | |_) | |
  7. # | (__| |_| | _ <| |___
  8. # \___|\___/|_| \_\_____|
  9. #
  10. # Copyright (C) 2008 - 2022, 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 json
  28. import logging
  29. import time
  30. from datetime import timedelta
  31. from threading import Thread
  32. from typing import Optional
  33. import pytest
  34. from testenv import Env, CurlClient, ExecResult
  35. log = logging.getLogger(__name__)
  36. @pytest.mark.skipif(condition=Env.setup_incomplete(),
  37. reason=f"missing: {Env.incomplete_reason()}")
  38. class TestGoAway:
  39. # download files sequentially with delay, reload server for GOAWAY
  40. def test_03_01_h2_goaway(self, env: Env, httpd, nghttpx, repeat):
  41. proto = 'h2'
  42. count = 3
  43. self.r = None
  44. def long_run():
  45. curl = CurlClient(env=env)
  46. # send 10 chunks of 1024 bytest in a response body with 100ms delay inbetween
  47. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  48. f'/curltest/tweak?id=[0-{count - 1}]'\
  49. '&chunks=10&chunk_size=1024&chunk_delay=100ms'
  50. self.r = curl.http_download(urls=[urln], alpn_proto=proto)
  51. t = Thread(target=long_run)
  52. t.start()
  53. # each request will take a second, reload the server in the middle
  54. # of the first one.
  55. time.sleep(1.5)
  56. assert httpd.reload()
  57. t.join()
  58. r: ExecResult = self.r
  59. assert r.exit_code == 0, f'{r}'
  60. r.check_responses(count=count, exp_status=200)
  61. assert len(r.stats) == count, f'{r.stats}'
  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_server(), reason="no h3 server")
  72. @pytest.mark.skipif(condition=True, reason="2nd and 3rd request sometimes fail")
  73. def test_03_02_h3_goaway(self, env: Env, httpd, nghttpx, repeat):
  74. proto = 'h3'
  75. count = 3
  76. self.r = None
  77. def long_run():
  78. curl = CurlClient(env=env)
  79. # send 10 chunks of 1024 bytest in a response body with 100ms delay inbetween
  80. urln = f'https://{env.authority_for(env.domain1, proto)}' \
  81. f'/curltest/tweak?id=[0-{count - 1}]'\
  82. '&chunks=10&chunk_size=1024&chunk_delay=100ms'
  83. self.r = curl.http_download(urls=[urln], alpn_proto=proto)
  84. t = Thread(target=long_run)
  85. t.start()
  86. # each request will take a second, reload the server in the middle
  87. # of the first one.
  88. time.sleep(1.5)
  89. assert nghttpx.reload(timeout=timedelta(seconds=5))
  90. t.join()
  91. r: ExecResult = self.r
  92. assert r.exit_code == 0, f'{r}'
  93. r.check_responses(count=count, exp_status=200)
  94. assert len(r.stats) == count, f'{r.stats}'
  95. # reload will shut down the connection gracefully with GOAWAY
  96. # we expect to see a second connection opened afterwards
  97. assert r.total_connects == 2
  98. for idx, s in enumerate(r.stats):
  99. if s['num_connects'] > 0:
  100. log.debug(f'request {idx} connected')
  101. # this should take `count` seconds to retrieve
  102. assert r.duration >= timedelta(seconds=count)