Artifactspublic-v0

curl

master
ply4 git calls143 ms290 KiB2 cachedprotocol v2
301 lines12 KiBRaw
1#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
21# SPDX-License-Identifier: curl
23###########################################################################
25import base64
26import hashlib
27import logging
28import os
29import re
30import socket
31import threading
32import time
34import pytest
35from testenv import CurlClient, Env, LocalClient, WsServer
37log = logging.getLogger(__name__)
40@pytest.mark.skipif(condition=not Env.curl_has_protocol('ws'),
41 reason='curl lacks ws protocol support')
42class TestWebsockets:
44 @pytest.fixture(autouse=True, scope='class')
45 @classmethod
46 def ws_echo(cls, env):
47 server = WsServer('ws_echo', env)
48 server.startup()
49 yield server
50 server.shutdown()
52 @pytest.fixture(autouse=True, scope='class')
53 @classmethod
54 def ws_4frames(cls, env):
55 server = WsServer('ws_4frames', env)
56 server.startup()
57 yield server
58 server.shutdown()
60 @pytest.fixture(autouse=True, scope='class')
61 @classmethod
62 def ws_dl(cls, env):
63 server = WsServer('ws_dl', env)
64 server.startup()
65 yield server
66 server.shutdown()
68 def test_20_01_basic(self, env: Env, ws_echo):
69 curl = CurlClient(env=env)
70 url = f'http://localhost:{ws_echo.port}/'
71 r = curl.http_download(urls=[url])
72 r.check_response(http_status=426)
74 def test_20_02_pingpong_small(self, env: Env, ws_echo):
75 payload = 125 * "x"
76 client = LocalClient(env=env, name='cli_ws_pingpong')
77 if not client.exists():
78 pytest.skip(f'example client not built: {client.name}')
79 url = f'ws://localhost:{ws_echo.port}/'
80 r = client.run(args=[url, payload])
81 r.check_exit_code(0)
83 # the python websocket server does not like 'large' control frames
84 def test_20_03_pingpong_too_large(self, env: Env, ws_echo):
85 payload = 127 * "x"
86 client = LocalClient(env=env, name='cli_ws_pingpong')
87 if not client.exists():
88 pytest.skip(f'example client not built: {client.name}')
89 url = f'ws://localhost:{ws_echo.port}/'
90 r = client.run(args=[url, payload])
91 r.check_exit_code(100) # CURLE_TOO_LARGE
93 @pytest.mark.parametrize("model", [
94 pytest.param(1, id='multi_perform'),
95 pytest.param(2, id='curl_ws_send+recv'),
96 ])
97 def test_20_04_data_small(self, env: Env, ws_echo, model):
98 client = LocalClient(env=env, name='cli_ws_data')
99 if not client.exists():
100 pytest.skip(f'example client not built: {client.name}')
101 url = f'ws://localhost:{ws_echo.port}/'
102 r = client.run(args=[f'-{model}', '-c', '10', '-m', str(1), '-M', str(10), url])
103 r.check_exit_code(0)
105 @pytest.mark.parametrize("model", [
106 pytest.param(1, id='multi_perform'),
107 pytest.param(2, id='curl_ws_send+recv'),
108 ])
109 def test_20_05_data_med(self, env: Env, ws_echo, model):
110 client = LocalClient(env=env, name='cli_ws_data')
111 if not client.exists():
112 pytest.skip(f'example client not built: {client.name}')
113 url = f'ws://localhost:{ws_echo.port}/'
114 r = client.run(args=[f'-{model}', '-m', str(120), '-M', str(130), url])
115 r.check_exit_code(0)
117 @pytest.mark.parametrize("model", [
118 pytest.param(1, id='multi_perform'),
119 pytest.param(2, id='curl_ws_send+recv'),
120 ])
121 def test_20_06_data_large(self, env: Env, ws_echo, model):
122 client = LocalClient(env=env, name='cli_ws_data')
123 if not client.exists():
124 pytest.skip(f'example client not built: {client.name}')
125 url = f'ws://localhost:{ws_echo.port}/'
126 r = client.run(args=[f'-{model}', '-m', str(65535 - 5), '-M', str(65535 + 5), url])
127 r.check_exit_code(0)
129 @pytest.mark.parametrize("model", [
130 pytest.param(1, id='multi_perform'),
131 pytest.param(2, id='curl_ws_send+recv'),
132 ])
133 def test_20_07_data_large_small_recv(self, env: Env, ws_echo, model):
134 run_env = os.environ.copy()
135 run_env['CURL_WS_CHUNK_SIZE'] = '1024'
136 client = LocalClient(env=env, name='cli_ws_data', run_env=run_env)
137 if not client.exists():
138 pytest.skip(f'example client not built: {client.name}')
139 url = f'ws://localhost:{ws_echo.port}/'
140 r = client.run(args=[f'-{model}', '-m', str(65535 - 5), '-M', str(65535 + 5), url])
141 r.check_exit_code(0)
143 # Send large frames and simulate send blocking on 8192 bytes chunks
144 # Simulates error reported in #15865
145 @pytest.mark.parametrize("model", [
146 pytest.param(1, id='multi_perform'),
147 pytest.param(2, id='curl_ws_send+recv'),
148 ])
149 def test_20_08_data_very_large(self, env: Env, ws_echo, model):
150 run_env = os.environ.copy()
151 run_env['CURL_WS_CHUNK_EAGAIN'] = '8192'
152 client = LocalClient(env=env, name='cli_ws_data', run_env=run_env)
153 if not client.exists():
154 pytest.skip(f'example client not built: {client.name}')
155 url = f'ws://localhost:{ws_echo.port}/'
156 count = 10
157 large = 20000
158 r = client.run(args=[f'-{model}', '-c', str(count), '-m', str(large), url])
159 r.check_exit_code(0)
161 @pytest.mark.parametrize("model", [
162 pytest.param(1, id='multi_perform'),
163 pytest.param(2, id='curl_ws_send+recv'),
164 ])
165 def test_20_09_data_empty(self, env: Env, ws_echo, model):
166 client = LocalClient(env=env, name='cli_ws_data')
167 if not client.exists():
168 pytest.skip(f'example client not built: {client.name}')
169 url = f'ws://localhost:{ws_echo.port}/'
170 count = 10
171 large = 0
172 r = client.run(args=[f'-{model}', '-c', str(count), '-m', str(large), url])
173 r.check_exit_code(0)
175 # use ws:// URL with HTTP proxy, check that it tunnels automatically
176 def test_20_10_proxy_http(self, env: Env, httpd, ws_echo):
177 curl = CurlClient(env=env)
178 url = f'ws://127.0.0.1:{ws_echo.port}/'
179 xargs = curl.get_proxy_args(proxys=False)
180 xargs.extend([
181 '--max-time', '2'
182 ])
183 r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
184 extra_args=xargs)
185 # The CONNECT through the proxy fails as it does not allow it
186 r.check_exit_code(7) # CURLE_COULDNT_CONNECT
187 assert r.stats[0]['http_connect'] == 403, f'{r}'
189 def test_20_11_crazy_pings(self, env: Env):
190 st = {}
191 send_rounds = 1
193 def srv():
194 try:
195 with socket.socket() as s:
196 s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
197 s.bind(("127.0.0.1", 0))
198 s.listen(1)
199 st["p"] = s.getsockname()[1]
201 c, _ = s.accept()
202 c.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 4096)
203 c.settimeout(Env.SERVER_TIMEOUT)
204 req = b""
205 while b"\r\n\r\n" not in req:
206 req += c.recv(4096)
208 k = re.search(rb"(?im)^Sec-WebSocket-Key:\s*(\S+)", req).group(1)
209 a = base64.b64encode(
210 hashlib.sha1(k + b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11").digest()
211 ).decode()
212 c.sendall(
213 "HTTP/1.1 101 Switching Protocols\r\n"
214 "Upgrade: websocket\r\n"
215 "Connection: Upgrade\r\n"
216 f"Sec-WebSocket-Accept: {a}\r\n\r\n"
217 .encode()
218 )
220 f = b"\x89\x00" * 65536 # PING frames, many
221 try:
222 for _ in range(send_rounds):
223 c.sendall(f)
224 f = b"\x88\x00" # CLOSE frame
225 c.sendall(f)
226 except OSError:
227 # Client may close/reset while we intentionally flood frames.
228 # Send errors are expected here, ignore them.
229 pass
230 time.sleep(1)
231 c.close()
232 except OSError as e:
233 st["err"] = e
235 run_env = os.environ.copy()
236 if 'CURL_DEBUG' in run_env:
237 del run_env['CURL_DEBUG']
238 curl = CurlClient(env=env, run_env=run_env)
239 send_rounds = 2
240 threading.Thread(target=srv, daemon=True).start()
241 while "p" not in st and "err" not in st:
242 time.sleep(0.01)
243 assert "err" not in st, f'ws-ping server failed to start: {st["err"]}'
245 url = f'ws://127.0.0.1:{st["p"]}/'
246 r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
247 with_profile=True)
248 assert r.exit_code in [0, 55, 56], f'{r.dump_logs()}' # SEND/RECV_ERROR
249 assert r.profile, f'{r}'
250 rss1 = r.profile.stats['rss-max'] / (1024 * 1024)
252 st.clear()
253 send_rounds = 10
254 threading.Thread(target=srv, daemon=True).start()
255 while "p" not in st and "err" not in st:
256 time.sleep(0.01)
257 assert "err" not in st, f'ws-ping server failed to start: {st["err"]}'
259 url = f'ws://127.0.0.1:{st["p"]}/'
260 r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
261 with_profile=True)
262 assert r.exit_code in [0, 55, 56], f'{r.dump_logs()}' # SEND/RECV_ERROR
263 assert r.profile, f'{r}'
264 rss2 = r.profile.stats['rss-max'] / (1024 * 1024)
265 assert (rss1 * 1.35) > rss2, 'bad memory increase'
267 # test small frames delivery when pausing
268 def test_20_12_pause_frames_small(self, env: Env, ws_4frames):
269 payload = 127 * "x"
270 client = LocalClient(env=env, name='cli_ws_pause')
271 if not client.exists():
272 pytest.skip(f'example client not built: {client.name}')
273 url = f'ws://localhost:{ws_4frames.port}/small'
274 r = client.run(args=[url, payload])
275 r.check_exit_code(0)
277 # test small frames delivery when pausing
278 def test_20_13_pause_frames_large(self, env: Env, ws_4frames):
279 payload = 127 * "x"
280 client = LocalClient(env=env, name='cli_ws_pause')
281 if not client.exists():
282 pytest.skip(f'example client not built: {client.name}')
283 url = f'ws://localhost:{ws_4frames.port}/large'
284 r = client.run(args=[url, payload])
285 r.check_exit_code(0)
287 # test handling of write callback errors
288 def test_20_14_write_err(self, env: Env, ws_4frames):
289 payload = 127 * "x"
290 client = LocalClient(env=env, name='cli_ws_write_err')
291 if not client.exists():
292 pytest.skip(f'example client not built: {client.name}')
293 url = f'ws://localhost:{ws_4frames.port}/small'
294 r = client.run(args=[url, payload])
295 r.check_exit_code(0)
297 def test_20_15_dl_10mb(self, env: Env, httpd, ws_dl):
298 curl = CurlClient(env=env)
299 url = f'ws://127.0.0.1:{ws_dl.port}/10mb'
300 r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True)
301 r.check_exit_code(0)
Diagnostics4 git calls · 143 ms
CallStatusSizeTime0143 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=137
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2003.0 KiB137 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=3046
git.response.cache=MISS
git.response.duration_ms=137
git.fetch.wants=0c99b27d70b9d12b1c7f6fee0c30adf11eb5087d
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=3046
git.pkt.payload.max=3025
git.sideband.band1.bytes=3024
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e2e62669c82947
Request
92cca87d…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format