2
0

test_02_download.py 26 KB

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