Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/http/test_03_goaway.py
2659 views
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
#***************************************************************************
4
# _ _ ____ _
5
# Project ___| | | | _ \| |
6
# / __| | | | |_) | |
7
# | (__| |_| | _ <| |___
8
# \___|\___/|_| \_\_____|
9
#
10
# Copyright (C) Daniel Stenberg, <[email protected]>, 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
33
from testenv import Env, CurlClient, ExecResult
34
35
36
log = logging.getLogger(__name__)
37
38
39
class TestGoAway:
40
41
# download files sequentially with delay, reload server for GOAWAY
42
def test_03_01_h2_goaway(self, env: Env, httpd, nghttpx):
43
proto = 'h2'
44
count = 3
45
self.r = None
46
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
55
t = Thread(target=long_run)
56
t.start()
57
# each request will take a second, reload the server in the middle
58
# of the first one.
59
time.sleep(1.5)
60
assert httpd.reload()
61
t.join()
62
r: ExecResult = self.r
63
r.check_response(count=count, http_status=200)
64
# reload will shut down the connection gracefully with GOAWAY
65
# we expect to see a second connection opened afterwards
66
assert r.total_connects == 2
67
for idx, s in enumerate(r.stats):
68
if s['num_connects'] > 0:
69
log.debug(f'request {idx} connected')
70
# this should take `count` seconds to retrieve
71
assert r.duration >= timedelta(seconds=count)
72
73
# download files sequentially with delay, reload server for GOAWAY
74
@pytest.mark.skipif(condition=not Env.have_h3(), reason="h3 not supported")
75
def test_03_02_h3_goaway(self, env: Env, httpd, nghttpx):
76
proto = 'h3'
77
if proto == 'h3' and env.curl_uses_ossl_quic():
78
pytest.skip('OpenSSL QUIC fails here')
79
count = 3
80
self.r = None
81
82
def long_run():
83
curl = CurlClient(env=env)
84
# send 10 chunks of 1024 bytes in a response body with 100ms delay in between
85
urln = f'https://{env.authority_for(env.domain1, proto)}' \
86
f'/curltest/tweak?id=[0-{count - 1}]'\
87
'&chunks=10&chunk_size=1024&chunk_delay=100ms'
88
self.r = curl.http_download(urls=[urln], alpn_proto=proto)
89
90
t = Thread(target=long_run)
91
t.start()
92
# each request will take a second, reload the server in the middle
93
# of the first one.
94
time.sleep(1.5)
95
assert nghttpx.reload(timeout=timedelta(seconds=Env.SERVER_TIMEOUT))
96
t.join()
97
r: ExecResult = self.r
98
# this should take `count` seconds to retrieve, maybe a little less
99
assert r.duration >= timedelta(seconds=count-1)
100
r.check_response(count=count, http_status=200, connect_count=2)
101
# reload will shut down the connection gracefully with GOAWAY
102
# we expect to see a second connection opened afterwards
103
for idx, s in enumerate(r.stats):
104
if s['num_connects'] > 0:
105
log.debug(f'request {idx} connected')
106
107
# download files sequentially with delay, reload server for GOAWAY
108
def test_03_03_h1_goaway(self, env: Env, httpd, nghttpx):
109
proto = 'http/1.1'
110
count = 3
111
self.r = None
112
113
def long_run():
114
curl = CurlClient(env=env)
115
# send 10 chunks of 1024 bytes in a response body with 100ms delay in between
116
# pause 2 seconds between requests
117
urln = f'https://{env.authority_for(env.domain1, proto)}' \
118
f'/curltest/tweak?id=[0-{count - 1}]'\
119
'&chunks=10&chunk_size=1024&chunk_delay=100ms'
120
self.r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
121
'--rate', '30/m',
122
])
123
124
t = Thread(target=long_run)
125
t.start()
126
# each request will take a second, reload the server in the middle
127
# of the first one.
128
time.sleep(1.5)
129
assert httpd.reload()
130
t.join()
131
r: ExecResult = self.r
132
r.check_response(count=count, http_status=200, connect_count=2)
133
# reload will shut down the connection gracefully
134
# we expect to see a second connection opened afterwards
135
for idx, s in enumerate(r.stats):
136
if s['num_connects'] > 0:
137
log.debug(f'request {idx} connected')
138
# this should take `count` seconds to retrieve
139
assert r.duration >= timedelta(seconds=count)
140
141