master
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.
13#
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.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
24#
25import difflib
26import filecmp
27import logging
28import os
29import re
30import string
32import pytest
33from testenv import Caddy, CurlClient, Env, LocalClient
35log = logging.getLogger(__name__)
38@pytest.mark.skipif(condition=not Env.has_caddy(), reason="missing caddy")
39@pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL")
40class TestCaddy:
42 @pytest.fixture(autouse=True, scope='class')
43 @classmethod
44 def caddy(cls, env):
45 caddy = Caddy(env=env)
46 assert caddy.initial_start()
47 yield caddy
48 caddy.stop()
50 @classmethod
51 def _make_docs_file(cls, docs_dir: str, fname: str, fsize: int):
52 fpath = os.path.join(docs_dir, fname)
53 data1k = 1024*'x'
54 flen = 0
55 with open(fpath, 'w') as fd:
56 while flen < fsize:
57 fd.write(data1k)
58 flen += len(data1k)
59 return flen
61 @pytest.fixture(autouse=True, scope='class')
62 @classmethod
63 def _class_scope(cls, env, caddy):
64 cls._make_docs_file(docs_dir=caddy.docs_dir, fname='data10k.data', fsize=10 * 1024)
65 cls._make_docs_file(docs_dir=caddy.docs_dir, fname='data1.data', fsize=1024 * 1024)
66 cls._make_docs_file(docs_dir=caddy.docs_dir, fname='data5.data', fsize=5 * 1024 * 1024)
67 cls._make_docs_file(docs_dir=caddy.docs_dir, fname='data10.data', fsize=10 * 1024 * 1024)
68 cls._make_docs_file(docs_dir=caddy.docs_dir, fname='data100.data', fsize=100 * 1024 * 1024)
69 env.make_data_file(indir=env.gen_dir, fname="data-10m", fsize=10 * 1024 * 1024)
71 # download 1 file
72 @pytest.mark.parametrize("proto", Env.http_protos())
73 def test_08_01_download_1(self, env: Env, caddy: Caddy, proto):
74 curl = CurlClient(env=env)
75 url = f'https://{env.domain1}:{caddy.port}/data.json'
76 r = curl.http_download(urls=[url], alpn_proto=proto)
77 r.check_response(count=1, http_status=200)
79 # download 1MB files sequentially
80 @pytest.mark.parametrize("proto", Env.http_protos())
81 def test_08_02_download_1mb_sequential(self, env: Env, caddy: Caddy, proto):
82 count = 50
83 curl = CurlClient(env=env)
84 urln = f'https://{env.domain1}:{caddy.port}/data1.data?[0-{count-1}]'
85 r = curl.http_download(urls=[urln], alpn_proto=proto)
86 r.check_response(count=count, http_status=200, connect_count=1)
88 # download 1MB files parallel
89 @pytest.mark.parametrize("proto", Env.http_protos())
90 def test_08_03_download_1mb_parallel(self, env: Env, caddy: Caddy, proto):
91 count = 20
92 curl = CurlClient(env=env)
93 urln = f'https://{env.domain1}:{caddy.port}/data1.data?[0-{count-1}]'
94 r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
95 '--parallel'
96 ])
97 r.check_response(count=count, http_status=200)
98 if proto == 'http/1.1':
99 # http/1.1 parallel transfers will open multiple connections
100 assert r.total_connects > 1, r.dump_logs()
101 else:
102 assert r.total_connects == 1, r.dump_logs()
104 # download 5MB files sequentially
105 @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
106 @pytest.mark.parametrize("proto", Env.http_mplx_protos())
107 def test_08_04a_download_10mb_sequential(self, env: Env, caddy: Caddy, proto):
108 count = 40
109 curl = CurlClient(env=env)
110 urln = f'https://{env.domain1}:{caddy.port}/data5.data?[0-{count-1}]'
111 r = curl.http_download(urls=[urln], alpn_proto=proto)
112 r.check_response(count=count, http_status=200, connect_count=1)
114 # download 10MB files sequentially
115 @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
116 @pytest.mark.parametrize("proto", Env.http_mplx_protos())
117 def test_08_04b_download_10mb_sequential(self, env: Env, caddy: Caddy, proto):
118 count = 20
119 curl = CurlClient(env=env)
120 urln = f'https://{env.domain1}:{caddy.port}/data10.data?[0-{count-1}]'
121 r = curl.http_download(urls=[urln], alpn_proto=proto)
122 r.check_response(count=count, http_status=200, connect_count=1)
124 # download 10MB files parallel
125 @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
126 @pytest.mark.parametrize("proto", Env.http_protos())
127 def test_08_05_download_1mb_parallel(self, env: Env, caddy: Caddy, proto):
128 if proto == 'http/1.1' and env.curl_uses_lib('mbedtls'):
129 pytest.skip("mbedtls 3.6.0 fails on 50 connections with: "
130 "ssl_handshake returned: (-0x7F00) SSL - Memory allocation failed")
131 count = 50
132 curl = CurlClient(env=env)
133 urln = f'https://{env.domain1}:{caddy.port}/data10.data?[0-{count-1}]'
134 r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
135 '--parallel'
136 ])
137 r.check_response(count=count, http_status=200)
138 if proto == 'http/1.1':
139 # http/1.1 parallel transfers will open multiple connections
140 assert r.total_connects > 1, r.dump_logs()
141 else:
142 assert r.total_connects == 1, r.dump_logs()
144 # post data parallel, check that they were echoed
145 @pytest.mark.parametrize("proto", Env.http_protos())
146 def test_08_06_post_parallel(self, env: Env, httpd, caddy, proto):
147 # limit since we use a separate connection in h1
148 count = 20
149 data = string.digits
150 curl = CurlClient(env=env)
151 url = f'https://{env.domain2}:{caddy.port}/curltest/echo?id=[0-{count-1}]'
152 r = curl.http_upload(urls=[url], data=data, alpn_proto=proto,
153 extra_args=['--parallel'])
154 r.check_stats(count=count, http_status=200, exitcode=0)
155 for i in range(count):
156 with open(curl.response_file(i)) as fr:
157 respdata = fr.readlines()
158 assert respdata == [data]
160 # put large file, check that they length were echoed
161 @pytest.mark.parametrize("proto", Env.http_protos())
162 def test_08_07_put_large(self, env: Env, httpd, caddy, proto):
163 # limit since we use a separate connection in h1<
164 count = 1
165 fdata = os.path.join(env.gen_dir, 'data-10m')
166 curl = CurlClient(env=env)
167 url = f'https://{env.domain2}:{caddy.port}/curltest/put?id=[0-{count-1}]'
168 r = curl.http_put(urls=[url], fdata=fdata, alpn_proto=proto)
169 exp_data = [f'{os.path.getsize(fdata)}']
170 r.check_response(count=count, http_status=200)
171 for i in range(count):
172 with open(curl.response_file(i)) as fr:
173 respdata = fr.readlines()
174 assert respdata == exp_data
176 @pytest.mark.parametrize("proto", Env.http_protos())
177 def test_08_08_earlydata(self, env: Env, httpd, caddy, proto):
178 if not env.curl_can_early_data():
179 pytest.skip('TLS earlydata not implemented')
180 if proto == 'h3' and not env.curl_can_h3_early_data():
181 pytest.skip("h3 early data not supported")
182 count = 2
183 docname = 'data10k.data'
184 url = f'https://{env.domain1}:{caddy.port}/{docname}'
185 client = LocalClient(name='cli_hx_download', env=env)
186 if not client.exists():
187 pytest.skip(f'example client not built: {client.name}')
188 r = client.run(args=[
189 '-n', f'{count}',
190 '-C', env.ca.cert_file,
191 '-e', # use TLS earlydata
192 '-f', # forbid reuse of connections
193 '-r', f'{env.domain1}:{caddy.port}:127.0.0.1',
194 '-V', proto, url
195 ])
196 r.check_exit_code(0)
197 srcfile = os.path.join(caddy.docs_dir, docname)
198 self.check_downloads(client, srcfile, count)
199 earlydata = {}
200 for line in r.trace_lines:
201 m = re.match(r'^\[t-(\d+)] EarlyData: (-?\d+)', line)
202 if m:
203 earlydata[int(m.group(1))] = int(m.group(2))
204 assert earlydata[0] == 0, f'{earlydata}'
205 if proto == 'h3':
206 assert earlydata[1] == 113, f'{earlydata}'
207 else:
208 # Caddy does not support early data on TCP
209 assert earlydata[1] == 0, f'{earlydata}'
211 def check_downloads(self, client, srcfile: str, count: int,
212 complete: bool = True):
213 for i in range(count):
214 dfile = client.download_file(i)
215 assert os.path.exists(dfile)
216 if complete and not filecmp.cmp(srcfile, dfile, shallow=False):
217 with open(srcfile) as fa, open(dfile) as fb:
218 a = fa.readlines()
219 b = fb.readlines()
220 diff = "".join(difflib.unified_diff(a=a, b=b,
221 fromfile=srcfile,
222 tofile=dfile,
223 n=1))
224 assert False, f'download {dfile} differs:\n{diff}'
Diagnostics4 git calls · 159 ms
CallStatusSizeTime0159 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=153 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=86Open pack map
fetch2002.7 KiB153 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2743 git.response.cache=MISS git.response.duration_ms=153 git.fetch.wants=09a0be64de604715870879d4a8159926069dc36a 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=2743 git.pkt.payload.max=2722 git.sideband.band1.bytes=2721 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
- a5e2dfaa6d042308
- Request
- a86b46f6…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format