test_06_eyeballs.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. from typing import Optional, Tuple, List, Dict
  30. import pytest
  31. from testenv import Env, CurlClient, ExecResult
  32. log = logging.getLogger(__name__)
  33. @pytest.mark.skipif(condition=Env.setup_incomplete(),
  34. reason=f"missing: {Env.incomplete_reason()}")
  35. @pytest.mark.skipif(condition=not Env.have_h3_server(),
  36. reason=f"missing HTTP/3 server")
  37. @pytest.mark.skipif(condition=not Env.have_h3_curl(),
  38. reason=f"curl built without HTTP/3")
  39. class TestEyeballs:
  40. @pytest.fixture(autouse=True, scope='class')
  41. def _class_scope(self, env, nghttpx):
  42. if env.have_h3():
  43. nghttpx.start_if_needed()
  44. # download using only HTTP/3 on working server
  45. def test_06_01_h3_only(self, env: Env, httpd, nghttpx, repeat):
  46. curl = CurlClient(env=env)
  47. urln = f'https://{env.authority_for(env.domain1, "h3")}/data.json'
  48. r = curl.http_download(urls=[urln], extra_args=['--http3-only'])
  49. assert r.exit_code == 0, f'{r}'
  50. r.check_stats(count=1, exp_status=200)
  51. assert r.stats[0]['http_version'] == '3'
  52. # download using only HTTP/3 on missing server
  53. def test_06_02_h3_only(self, env: Env, httpd, nghttpx, repeat):
  54. nghttpx.stop_if_running()
  55. curl = CurlClient(env=env)
  56. urln = f'https://{env.authority_for(env.domain1, "h3")}/data.json'
  57. r = curl.http_download(urls=[urln], extra_args=['--http3-only'])
  58. assert r.exit_code == 7, f'{r}' # could not connect
  59. # download using HTTP/3 on missing server with fallback on h2
  60. def test_06_03_h3_fallback_h2(self, env: Env, httpd, nghttpx, repeat):
  61. nghttpx.stop_if_running()
  62. curl = CurlClient(env=env)
  63. urln = f'https://{env.authority_for(env.domain1, "h3")}/data.json'
  64. r = curl.http_download(urls=[urln], extra_args=['--http3'])
  65. assert r.exit_code == 0, f'{r}'
  66. r.check_stats(count=1, exp_status=200)
  67. assert r.stats[0]['http_version'] == '2'
  68. # download using HTTP/3 on missing server with fallback on http/1.1
  69. def test_06_04_h3_fallback_h1(self, env: Env, httpd, nghttpx, repeat):
  70. nghttpx.stop_if_running()
  71. curl = CurlClient(env=env)
  72. urln = f'https://{env.authority_for(env.domain2, "h3")}/data.json'
  73. r = curl.http_download(urls=[urln], extra_args=['--http3'])
  74. assert r.exit_code == 0, f'{r}'
  75. r.check_stats(count=1, exp_status=200)
  76. assert r.stats[0]['http_version'] == '1.1'