test_02_download.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #***************************************************************************
  4. # _ _ ____ _
  5. # Project ___| | | | _ \| |
  6. # / __| | | | |_) | |
  7. # | (__| |_| | _ <| |___
  8. # \___|\___/|_| \_\_____|
  9. #
  10. # Copyright (C) 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 difflib
  28. import filecmp
  29. import logging
  30. import math
  31. import os
  32. from datetime import timedelta
  33. import pytest
  34. from testenv import Env, CurlClient, LocalClient
  35. log = logging.getLogger(__name__)
  36. class TestDownload:
  37. @pytest.fixture(autouse=True, scope='class')
  38. def _class_scope(self, env, httpd, nghttpx):
  39. if env.have_h3():
  40. nghttpx.start_if_needed()
  41. httpd.clear_extra_configs()
  42. httpd.reload()
  43. @pytest.fixture(autouse=True, scope='class')
  44. def _class_scope(self, env, httpd):
  45. indir = httpd.docs_dir
  46. env.make_data_file(indir=indir, fname="data-10k", fsize=10*1024)
  47. env.make_data_file(indir=indir, fname="data-100k", fsize=100*1024)
  48. env.make_data_file(indir=indir, fname="data-1m", fsize=1024*1024)
  49. env.make_data_file(indir=indir, fname="data-10m", fsize=10*1024*1024)
  50. env.make_data_file(indir=indir, fname="data-50m", fsize=50*1024*1024)
  51. # download 1 file
  52. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  53. def test_02_01_download_1(self, env: Env, httpd, nghttpx, repeat, proto):
  54. if proto == 'h3' and not env.have_h3():
  55. pytest.skip("h3 not supported")
  56. curl = CurlClient(env=env)
  57. url = f'https://{env.authority_for(env.domain1, proto)}/data.json'
  58. r = curl.http_download(urls=[url], alpn_proto=proto)
  59. r.check_response(http_status=200)
  60. # download 2 files
  61. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  62. def test_02_02_download_2(self, env: Env, httpd, nghttpx, repeat, proto):
  63. if proto == 'h3' and not env.have_h3():
  64. pytest.skip("h3 not supported")
  65. curl = CurlClient(env=env)
  66. url = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-1]'
  67. r = curl.http_download(urls=[url], alpn_proto=proto)
  68. r.check_response(http_status=200, count=2)
  69. # download 100 files sequentially
  70. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  71. def test_02_03_download_sequential(self, env: Env,
  72. httpd, nghttpx, repeat, proto):
  73. if proto == 'h3' and not env.have_h3():
  74. pytest.skip("h3 not supported")
  75. count = 10
  76. curl = CurlClient(env=env)
  77. urln = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{count-1}]'
  78. r = curl.http_download(urls=[urln], alpn_proto=proto)
  79. r.check_response(http_status=200, count=count, connect_count=1)
  80. # download 100 files parallel
  81. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  82. def test_02_04_download_parallel(self, env: Env,
  83. httpd, nghttpx, repeat, proto):
  84. if proto == 'h3' and not env.have_h3():
  85. pytest.skip("h3 not supported")
  86. count = 10
  87. max_parallel = 5
  88. curl = CurlClient(env=env)
  89. urln = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{count-1}]'
  90. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  91. '--parallel', '--parallel-max', f'{max_parallel}'
  92. ])
  93. r.check_response(http_status=200, count=count)
  94. if proto == 'http/1.1':
  95. # http/1.1 parallel transfers will open multiple connections
  96. assert r.total_connects > 1, r.dump_logs()
  97. else:
  98. # http2 parallel transfers will use one connection (common limit is 100)
  99. assert r.total_connects == 1, r.dump_logs()
  100. # download 500 files sequential
  101. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  102. def test_02_05_download_many_sequential(self, env: Env,
  103. httpd, nghttpx, repeat, proto):
  104. if proto == 'h3' and not env.have_h3():
  105. pytest.skip("h3 not supported")
  106. if proto == 'h3' and env.curl_uses_lib('msh3'):
  107. pytest.skip("msh3 shaky here")
  108. count = 200
  109. curl = CurlClient(env=env)
  110. urln = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{count-1}]'
  111. r = curl.http_download(urls=[urln], alpn_proto=proto)
  112. r.check_response(http_status=200, count=count)
  113. if proto == 'http/1.1':
  114. # http/1.1 parallel transfers will open multiple connections
  115. assert r.total_connects > 1, r.dump_logs()
  116. else:
  117. # http2 parallel transfers will use one connection (common limit is 100)
  118. assert r.total_connects == 1, r.dump_logs()
  119. # download 500 files parallel
  120. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  121. def test_02_06_download_many_parallel(self, env: Env,
  122. httpd, nghttpx, repeat, proto):
  123. if proto == 'h3' and not env.have_h3():
  124. pytest.skip("h3 not supported")
  125. count = 200
  126. max_parallel = 50
  127. curl = CurlClient(env=env)
  128. urln = f'https://{env.authority_for(env.domain1, proto)}/data.json?[000-{count-1}]'
  129. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  130. '--parallel', '--parallel-max', f'{max_parallel}'
  131. ])
  132. r.check_response(http_status=200, count=count, connect_count=1)
  133. # download files parallel, check connection reuse/multiplex
  134. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  135. def test_02_07_download_reuse(self, env: Env,
  136. httpd, nghttpx, repeat, proto):
  137. if proto == 'h3' and not env.have_h3():
  138. pytest.skip("h3 not supported")
  139. count = 200
  140. curl = CurlClient(env=env)
  141. urln = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{count-1}]'
  142. r = curl.http_download(urls=[urln], alpn_proto=proto,
  143. with_stats=True, extra_args=[
  144. '--parallel', '--parallel-max', '200'
  145. ])
  146. r.check_response(http_status=200, count=count)
  147. # should have used at most 2 connections only (test servers allow 100 req/conn)
  148. # it may be just 1 on slow systems where request are answered faster than
  149. # curl can exhaust the capacity or if curl runs with address-sanitizer speed
  150. assert r.total_connects <= 2, "h2 should use fewer connections here"
  151. # download files parallel with http/1.1, check connection not reused
  152. @pytest.mark.parametrize("proto", ['http/1.1'])
  153. def test_02_07b_download_reuse(self, env: Env,
  154. httpd, nghttpx, repeat, proto):
  155. if env.curl_uses_lib('wolfssl'):
  156. pytest.skip("wolfssl session reuse borked")
  157. count = 6
  158. curl = CurlClient(env=env)
  159. urln = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-{count-1}]'
  160. r = curl.http_download(urls=[urln], alpn_proto=proto,
  161. with_stats=True, extra_args=[
  162. '--parallel'
  163. ])
  164. r.check_response(count=count, http_status=200)
  165. # http/1.1 should have used count connections
  166. assert r.total_connects == count, "http/1.1 should use this many connections"
  167. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  168. def test_02_08_1MB_serial(self, env: Env,
  169. httpd, nghttpx, repeat, proto):
  170. if proto == 'h3' and not env.have_h3():
  171. pytest.skip("h3 not supported")
  172. count = 5
  173. urln = f'https://{env.authority_for(env.domain1, proto)}/data-1m?[0-{count-1}]'
  174. curl = CurlClient(env=env)
  175. r = curl.http_download(urls=[urln], alpn_proto=proto)
  176. r.check_response(count=count, http_status=200)
  177. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  178. def test_02_09_1MB_parallel(self, env: Env,
  179. httpd, nghttpx, repeat, proto):
  180. if proto == 'h3' and not env.have_h3():
  181. pytest.skip("h3 not supported")
  182. count = 5
  183. urln = f'https://{env.authority_for(env.domain1, proto)}/data-1m?[0-{count-1}]'
  184. curl = CurlClient(env=env)
  185. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  186. '--parallel'
  187. ])
  188. r.check_response(count=count, http_status=200)
  189. @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
  190. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  191. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  192. def test_02_10_10MB_serial(self, env: Env,
  193. httpd, nghttpx, repeat, proto):
  194. if proto == 'h3' and not env.have_h3():
  195. pytest.skip("h3 not supported")
  196. count = 3
  197. urln = f'https://{env.authority_for(env.domain1, proto)}/data-10m?[0-{count-1}]'
  198. curl = CurlClient(env=env)
  199. r = curl.http_download(urls=[urln], alpn_proto=proto)
  200. r.check_response(count=count, http_status=200)
  201. @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
  202. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  203. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  204. def test_02_11_10MB_parallel(self, env: Env,
  205. httpd, nghttpx, repeat, proto):
  206. if proto == 'h3' and not env.have_h3():
  207. pytest.skip("h3 not supported")
  208. if proto == 'h3' and env.curl_uses_lib('msh3'):
  209. pytest.skip("msh3 stalls here")
  210. count = 3
  211. urln = f'https://{env.authority_for(env.domain1, proto)}/data-10m?[0-{count-1}]'
  212. curl = CurlClient(env=env)
  213. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  214. '--parallel'
  215. ])
  216. r.check_response(count=count, http_status=200)
  217. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  218. def test_02_12_head_serial_https(self, env: Env,
  219. httpd, nghttpx, repeat, proto):
  220. if proto == 'h3' and not env.have_h3():
  221. pytest.skip("h3 not supported")
  222. count = 5
  223. urln = f'https://{env.authority_for(env.domain1, proto)}/data-10m?[0-{count-1}]'
  224. curl = CurlClient(env=env)
  225. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  226. '--head'
  227. ])
  228. r.check_response(count=count, http_status=200)
  229. @pytest.mark.parametrize("proto", ['h2'])
  230. def test_02_13_head_serial_h2c(self, env: Env,
  231. httpd, nghttpx, repeat, proto):
  232. if proto == 'h3' and not env.have_h3():
  233. pytest.skip("h3 not supported")
  234. count = 5
  235. urln = f'http://{env.domain1}:{env.http_port}/data-10m?[0-{count-1}]'
  236. curl = CurlClient(env=env)
  237. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  238. '--head', '--http2-prior-knowledge', '--fail-early'
  239. ])
  240. r.check_response(count=count, http_status=200)
  241. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  242. def test_02_14_not_found(self, env: Env, httpd, nghttpx, repeat, proto):
  243. if proto == 'h3' and not env.have_h3():
  244. pytest.skip("h3 not supported")
  245. if proto == 'h3' and env.curl_uses_lib('msh3'):
  246. pytest.skip("msh3 stalls here")
  247. count = 5
  248. urln = f'https://{env.authority_for(env.domain1, proto)}/not-found?[0-{count-1}]'
  249. curl = CurlClient(env=env)
  250. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  251. '--parallel'
  252. ])
  253. r.check_stats(count=count, http_status=404, exitcode=0,
  254. remote_port=env.port_for(alpn_proto=proto),
  255. remote_ip='127.0.0.1')
  256. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  257. def test_02_15_fail_not_found(self, env: Env, httpd, nghttpx, repeat, proto):
  258. if proto == 'h3' and not env.have_h3():
  259. pytest.skip("h3 not supported")
  260. if proto == 'h3' and env.curl_uses_lib('msh3'):
  261. pytest.skip("msh3 stalls here")
  262. count = 5
  263. urln = f'https://{env.authority_for(env.domain1, proto)}/not-found?[0-{count-1}]'
  264. curl = CurlClient(env=env)
  265. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  266. '--fail'
  267. ])
  268. r.check_stats(count=count, http_status=404, exitcode=22,
  269. remote_port=env.port_for(alpn_proto=proto),
  270. remote_ip='127.0.0.1')
  271. @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
  272. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  273. def test_02_20_h2_small_frames(self, env: Env, httpd, repeat):
  274. # Test case to reproduce content corruption as observed in
  275. # https://github.com/curl/curl/issues/10525
  276. # To reliably reproduce, we need an Apache httpd that supports
  277. # setting smaller frame sizes. This is not released yet, we
  278. # test if it works and back out if not.
  279. httpd.set_extra_config(env.domain1, lines=[
  280. f'H2MaxDataFrameLen 1024',
  281. ])
  282. assert httpd.stop()
  283. if not httpd.start():
  284. # no, not supported, bail out
  285. httpd.set_extra_config(env.domain1, lines=None)
  286. assert httpd.start()
  287. pytest.skip(f'H2MaxDataFrameLen not supported')
  288. # ok, make 100 downloads with 2 parallel running and they
  289. # are expected to stumble into the issue when using `lib/http2.c`
  290. # from curl 7.88.0
  291. count = 5
  292. urln = f'https://{env.authority_for(env.domain1, "h2")}/data-1m?[0-{count-1}]'
  293. curl = CurlClient(env=env)
  294. r = curl.http_download(urls=[urln], alpn_proto="h2", extra_args=[
  295. '--parallel', '--parallel-max', '2'
  296. ])
  297. r.check_response(count=count, http_status=200)
  298. srcfile = os.path.join(httpd.docs_dir, 'data-1m')
  299. self.check_downloads(curl, srcfile, count)
  300. # restore httpd defaults
  301. httpd.set_extra_config(env.domain1, lines=None)
  302. assert httpd.stop()
  303. assert httpd.start()
  304. # download via lib client, 1 at a time, pause/resume at different offsets
  305. @pytest.mark.parametrize("pause_offset", [0, 10*1024, 100*1023, 640000])
  306. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  307. def test_02_21_lib_serial(self, env: Env, httpd, nghttpx, proto, pause_offset, repeat):
  308. if proto == 'h3' and not env.have_h3():
  309. pytest.skip("h3 not supported")
  310. count = 2
  311. docname = 'data-10m'
  312. url = f'https://localhost:{env.https_port}/{docname}'
  313. client = LocalClient(name='hx-download', env=env)
  314. if not client.exists():
  315. pytest.skip(f'example client not built: {client.name}')
  316. r = client.run(args=[
  317. '-n', f'{count}', '-P', f'{pause_offset}', '-V', proto, url
  318. ])
  319. r.check_exit_code(0)
  320. srcfile = os.path.join(httpd.docs_dir, docname)
  321. self.check_downloads(client, srcfile, count)
  322. # download via lib client, several at a time, pause/resume
  323. @pytest.mark.parametrize("pause_offset", [100*1023])
  324. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  325. def test_02_22_lib_parallel_resume(self, env: Env, httpd, nghttpx, proto, pause_offset, repeat):
  326. if proto == 'h3' and not env.have_h3():
  327. pytest.skip("h3 not supported")
  328. count = 2
  329. max_parallel = 5
  330. docname = 'data-10m'
  331. url = f'https://localhost:{env.https_port}/{docname}'
  332. client = LocalClient(name='hx-download', env=env)
  333. if not client.exists():
  334. pytest.skip(f'example client not built: {client.name}')
  335. r = client.run(args=[
  336. '-n', f'{count}', '-m', f'{max_parallel}',
  337. '-P', f'{pause_offset}', '-V', proto, url
  338. ])
  339. r.check_exit_code(0)
  340. srcfile = os.path.join(httpd.docs_dir, docname)
  341. self.check_downloads(client, srcfile, count)
  342. # download, several at a time, pause and abort paused
  343. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  344. def test_02_23a_lib_abort_paused(self, env: Env, httpd, nghttpx, proto, repeat):
  345. if proto == 'h3' and not env.have_h3():
  346. pytest.skip("h3 not supported")
  347. if proto == 'h3' and env.curl_uses_ossl_quic():
  348. pytest.skip('OpenSSL QUIC fails here')
  349. if proto == 'h3' and env.ci_run and env.curl_uses_lib('quiche'):
  350. pytest.skip("fails in CI, but works locally for unknown reasons")
  351. count = 10
  352. max_parallel = 5
  353. if proto in ['h2', 'h3']:
  354. pause_offset = 64 * 1024
  355. else:
  356. pause_offset = 12 * 1024
  357. docname = 'data-1m'
  358. url = f'https://localhost:{env.https_port}/{docname}'
  359. client = LocalClient(name='hx-download', env=env)
  360. if not client.exists():
  361. pytest.skip(f'example client not built: {client.name}')
  362. r = client.run(args=[
  363. '-n', f'{count}', '-m', f'{max_parallel}', '-a',
  364. '-P', f'{pause_offset}', '-V', proto, url
  365. ])
  366. r.check_exit_code(0)
  367. srcfile = os.path.join(httpd.docs_dir, docname)
  368. # downloads should be there, but not necessarily complete
  369. self.check_downloads(client, srcfile, count, complete=False)
  370. # download, several at a time, abort after n bytes
  371. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  372. def test_02_23b_lib_abort_offset(self, env: Env, httpd, nghttpx, proto, repeat):
  373. if proto == 'h3' and not env.have_h3():
  374. pytest.skip("h3 not supported")
  375. if proto == 'h3' and env.curl_uses_ossl_quic():
  376. pytest.skip('OpenSSL QUIC fails here')
  377. if proto == 'h3' and env.ci_run and env.curl_uses_lib('quiche'):
  378. pytest.skip("fails in CI, but works locally for unknown reasons")
  379. count = 10
  380. max_parallel = 5
  381. if proto in ['h2', 'h3']:
  382. abort_offset = 64 * 1024
  383. else:
  384. abort_offset = 12 * 1024
  385. docname = 'data-1m'
  386. url = f'https://localhost:{env.https_port}/{docname}'
  387. client = LocalClient(name='hx-download', env=env)
  388. if not client.exists():
  389. pytest.skip(f'example client not built: {client.name}')
  390. r = client.run(args=[
  391. '-n', f'{count}', '-m', f'{max_parallel}', '-a',
  392. '-A', f'{abort_offset}', '-V', proto, url
  393. ])
  394. r.check_exit_code(0)
  395. srcfile = os.path.join(httpd.docs_dir, docname)
  396. # downloads should be there, but not necessarily complete
  397. self.check_downloads(client, srcfile, count, complete=False)
  398. # download, several at a time, abort after n bytes
  399. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  400. def test_02_23c_lib_fail_offset(self, env: Env, httpd, nghttpx, proto, repeat):
  401. if proto == 'h3' and not env.have_h3():
  402. pytest.skip("h3 not supported")
  403. if proto == 'h3' and env.curl_uses_ossl_quic():
  404. pytest.skip('OpenSSL QUIC fails here')
  405. if proto == 'h3' and env.ci_run and env.curl_uses_lib('quiche'):
  406. pytest.skip("fails in CI, but works locally for unknown reasons")
  407. count = 10
  408. max_parallel = 5
  409. if proto in ['h2', 'h3']:
  410. fail_offset = 64 * 1024
  411. else:
  412. fail_offset = 12 * 1024
  413. docname = 'data-1m'
  414. url = f'https://localhost:{env.https_port}/{docname}'
  415. client = LocalClient(name='hx-download', env=env)
  416. if not client.exists():
  417. pytest.skip(f'example client not built: {client.name}')
  418. r = client.run(args=[
  419. '-n', f'{count}', '-m', f'{max_parallel}', '-a',
  420. '-F', f'{fail_offset}', '-V', proto, url
  421. ])
  422. r.check_exit_code(0)
  423. srcfile = os.path.join(httpd.docs_dir, docname)
  424. # downloads should be there, but not necessarily complete
  425. self.check_downloads(client, srcfile, count, complete=False)
  426. # speed limited download
  427. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  428. def test_02_24_speed_limit(self, env: Env, httpd, nghttpx, proto, repeat):
  429. if proto == 'h3' and not env.have_h3():
  430. pytest.skip("h3 not supported")
  431. count = 1
  432. url = f'https://{env.authority_for(env.domain1, proto)}/data-1m'
  433. curl = CurlClient(env=env)
  434. speed_limit = 384 * 1024
  435. min_duration = math.floor((1024 * 1024)/speed_limit)
  436. r = curl.http_download(urls=[url], alpn_proto=proto, extra_args=[
  437. '--limit-rate', f'{speed_limit}'
  438. ])
  439. r.check_response(count=count, http_status=200)
  440. assert r.duration > timedelta(seconds=min_duration), \
  441. f'rate limited transfer should take more than {min_duration}s, '\
  442. f'not {r.duration}'
  443. # make extreme parallel h2 upgrades, check invalid conn reuse
  444. # before protocol switch has happened
  445. def test_02_25_h2_upgrade_x(self, env: Env, httpd, repeat):
  446. # not locally reproducible timeouts with certain SSL libs
  447. # Since this test is about connection reuse handling, we skip
  448. # it on these builds. Although we would certainly like to understand
  449. # why this happens.
  450. if env.curl_uses_lib('bearssl'):
  451. pytest.skip('CI workflows timeout on bearssl build')
  452. url = f'http://localhost:{env.http_port}/data-100k'
  453. client = LocalClient(name='h2-upgrade-extreme', env=env, timeout=15)
  454. if not client.exists():
  455. pytest.skip(f'example client not built: {client.name}')
  456. r = client.run(args=[url])
  457. assert r.exit_code == 0, f'{client.dump_logs()}'
  458. # Special client that tests TLS session reuse in parallel transfers
  459. # TODO: just uses a single connection for h2/h3. Not sure how to prevent that
  460. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  461. def test_02_26_session_shared_reuse(self, env: Env, proto, httpd, nghttpx, repeat):
  462. url = f'https://{env.authority_for(env.domain1, proto)}/data-100k'
  463. client = LocalClient(name='tls-session-reuse', env=env)
  464. if not client.exists():
  465. pytest.skip(f'example client not built: {client.name}')
  466. r = client.run(args=[proto, url])
  467. r.check_exit_code(0)
  468. # test on paused transfers, based on issue #11982
  469. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  470. def test_02_27a_paused_no_cl(self, env: Env, httpd, nghttpx, proto, repeat):
  471. url = f'https://{env.authority_for(env.domain1, proto)}' \
  472. '/curltest/tweak/?&chunks=6&chunk_size=8000'
  473. client = LocalClient(env=env, name='h2-pausing')
  474. r = client.run(args=['-V', proto, url])
  475. r.check_exit_code(0)
  476. # test on paused transfers, based on issue #11982
  477. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  478. def test_02_27b_paused_no_cl(self, env: Env, httpd, nghttpx, proto, repeat):
  479. url = f'https://{env.authority_for(env.domain1, proto)}' \
  480. '/curltest/tweak/?error=502'
  481. client = LocalClient(env=env, name='h2-pausing')
  482. r = client.run(args=['-V', proto, url])
  483. r.check_exit_code(0)
  484. # test on paused transfers, based on issue #11982
  485. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  486. def test_02_27c_paused_no_cl(self, env: Env, httpd, nghttpx, proto, repeat):
  487. url = f'https://{env.authority_for(env.domain1, proto)}' \
  488. '/curltest/tweak/?status=200&chunks=1&chunk_size=100'
  489. client = LocalClient(env=env, name='h2-pausing')
  490. r = client.run(args=['-V', proto, url])
  491. r.check_exit_code(0)
  492. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  493. def test_02_28_get_compressed(self, env: Env, httpd, nghttpx, repeat, proto):
  494. if proto == 'h3' and not env.have_h3():
  495. pytest.skip("h3 not supported")
  496. count = 1
  497. urln = f'https://{env.authority_for(env.domain1brotli, proto)}/data-100k?[0-{count-1}]'
  498. curl = CurlClient(env=env)
  499. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  500. '--compressed'
  501. ])
  502. r.check_exit_code(code=0)
  503. r.check_response(count=count, http_status=200)
  504. def check_downloads(self, client, srcfile: str, count: int,
  505. complete: bool = True):
  506. for i in range(count):
  507. dfile = client.download_file(i)
  508. assert os.path.exists(dfile)
  509. if complete and not filecmp.cmp(srcfile, dfile, shallow=False):
  510. diff = "".join(difflib.unified_diff(a=open(srcfile).readlines(),
  511. b=open(dfile).readlines(),
  512. fromfile=srcfile,
  513. tofile=dfile,
  514. n=1))
  515. assert False, f'download {dfile} differs:\n{diff}'
  516. # download via lib client, 1 at a time, pause/resume at different offsets
  517. @pytest.mark.parametrize("pause_offset", [0, 10*1024, 100*1023, 640000])
  518. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  519. def test_02_29_h2_lib_serial(self, env: Env, httpd, nghttpx, proto, pause_offset, repeat):
  520. count = 2
  521. docname = 'data-10m'
  522. url = f'https://localhost:{env.https_port}/{docname}'
  523. client = LocalClient(name='hx-download', env=env)
  524. if not client.exists():
  525. pytest.skip(f'example client not built: {client.name}')
  526. r = client.run(args=[
  527. '-n', f'{count}', '-P', f'{pause_offset}', '-V', proto, url
  528. ])
  529. r.check_exit_code(0)
  530. srcfile = os.path.join(httpd.docs_dir, docname)
  531. self.check_downloads(client, srcfile, count)
  532. # download parallel with prior knowledge
  533. def test_02_30_parallel_prior_knowledge(self, env: Env, httpd):
  534. count = 3
  535. curl = CurlClient(env=env)
  536. urln = f'http://{env.domain1}:{env.http_port}/data.json?[0-{count-1}]'
  537. r = curl.http_download(urls=[urln], extra_args=[
  538. '--parallel', '--http2-prior-knowledge'
  539. ])
  540. r.check_response(http_status=200, count=count)
  541. assert r.total_connects == 1, r.dump_logs()
  542. # download parallel with h2 "Upgrade:"
  543. def test_02_31_parallel_upgrade(self, env: Env, httpd):
  544. count = 3
  545. curl = CurlClient(env=env)
  546. urln = f'http://{env.domain1}:{env.http_port}/data.json?[0-{count-1}]'
  547. r = curl.http_download(urls=[urln], extra_args=[
  548. '--parallel', '--http2'
  549. ])
  550. r.check_response(http_status=200, count=count)
  551. # we see 3 connections, because Apache only every serves a single
  552. # request via Upgrade: and then closed the connection.
  553. assert r.total_connects == 3, r.dump_logs()