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