Skip to content

Commit e36f8f4

Browse files
committed
tests(ext-curl): fix HTTP/2 Server Push tests
1 parent da3ce60 commit e36f8f4

File tree

6 files changed

+102
-8
lines changed

6 files changed

+102
-8
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Setup Caddy server
2+
runs:
3+
using: composite
4+
steps:
5+
- shell: bash
6+
run: |
7+
sudo apt-get install -y debian-keyring debian-archive-keyring apt-transport-https
8+
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
9+
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
10+
sudo apt-get update
11+
sudo apt-get install -y caddy
12+
13+
sudo caddy start --config ext/curl/tests/Caddyfile

.github/workflows/push.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
uses: ./.github/actions/setup-mssql
4040
- name: Create Oracle container
4141
uses: ./.github/actions/setup-oracle
42+
- name: Setup Caddy server
43+
uses: ./.github/actions/setup-caddy
4244
- name: apt
4345
uses: ./.github/actions/apt-x64
4446
- name: ccache
@@ -63,13 +65,17 @@ jobs:
6365
uses: ./.github/actions/setup-x64
6466
- name: Test
6567
uses: ./.github/actions/test-linux
68+
env:
69+
RUN_CADDY_TESTS: "1"
6670
- name: Test Tracing JIT
6771
uses: ./.github/actions/test-linux
6872
with:
6973
runTestsParameters: >-
7074
-d zend_extension=opcache.so
7175
-d opcache.enable_cli=1
7276
-d opcache.jit_buffer_size=16M
77+
env:
78+
RUN_CADDY_TESTS: "1"
7379
- name: Verify generated files are up to date
7480
uses: ./.github/actions/verify-generated-files
7581
LINUX_X32:

ext/curl/tests/Caddyfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
admin off
3+
auto_https disable_redirects
4+
}
5+
6+
localhost
7+
8+
# HTTP/2 Server Push
9+
respond /serverpush "main response"
10+
respond /serverpush/pushed "pushed response"
11+
push /serverpush /serverpush/pushed

ext/curl/tests/bug76675.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
Bug #76675 (Segfault with H2 server push write/writeheader handlers)
33
--EXTENSIONS--
44
curl
5-
--XFAIL--
6-
http2.golang.org/serverpush is gone
75
--SKIPIF--
86
<?php
7+
if (!getenv("RUN_CADDY_TESTS")) {
8+
die("skip test needing Caddy");
9+
}
910
if (getenv("SKIP_ONLINE_TESTS")) {
1011
die("skip online test");
1112
}
1213
$curl_version = curl_version();
1314
if ($curl_version['version_number'] < 0x073d00) {
1415
exit("skip: test may crash with curl < 7.61.0");
1516
}
16-
die("skip test is slow due to timeout, and XFAILs anyway");
1717
?>
1818
--FILE--
1919
<?php
@@ -30,7 +30,7 @@ $mh = curl_multi_init();
3030
curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
3131
curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, $callback);
3232
$ch = curl_init();
33-
curl_setopt($ch, CURLOPT_URL, 'https://http2.golang.org/serverpush');
33+
curl_setopt($ch, CURLOPT_URL, 'https://localhost/serverpush');
3434
curl_setopt($ch, CURLOPT_HTTP_VERSION, 3);
3535
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
3636
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

ext/curl/tests/bug77535.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
Bug #77535 (Invalid callback, h2 server push)
33
--EXTENSIONS--
44
curl
5-
--XFAIL--
6-
http2.golang.org/serverpush is gone
75
--SKIPIF--
86
<?php
7+
if (!getenv("RUN_CADDY_TESTS")) {
8+
die("skip test needing Caddy");
9+
}
910
if (getenv("SKIP_ONLINE_TESTS")) {
1011
die("skip online test");
1112
}
1213
$curl_version = curl_version();
1314
if ($curl_version['version_number'] < 0x073d00) {
1415
exit("skip: test may crash with curl < 7.61.0");
1516
}
16-
die("skip test is slow due to timeout, and XFAILs anyway");
1717
?>
1818
--FILE--
1919
<?php
@@ -36,7 +36,7 @@ class MyHttpClient
3636
curl_setopt($this->curl, CURLOPT_HEADER, false);
3737
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, false);
3838
curl_setopt($this->curl, CURLOPT_FAILONERROR, false);
39-
curl_setopt($this->curl, CURLOPT_URL, 'https://http2.golang.org/serverpush');
39+
curl_setopt($this->curl, CURLOPT_URL, 'https://localhost/serverpush');
4040
curl_setopt($this->curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
4141
curl_setopt($this->curl, CURLOPT_HEADERFUNCTION, function ($ch, $data) {
4242
return \strlen($data);

ext/curl/tests/curl_pushfunction.phpt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--TEST--
2+
Test CURLMOPT_PUSHFUNCTION
3+
--EXTENSIONS--
4+
curl
5+
--SKIPIF--
6+
<?php
7+
if (!getenv("RUN_CADDY_TESTS")) {
8+
die("skip test needing Caddy");
9+
}
10+
if (getenv("SKIP_ONLINE_TESTS")) {
11+
die("skip online test");
12+
}
13+
$curl_version = curl_version();
14+
if ($curl_version['version_number'] < 0x073d00) {
15+
exit("skip: test may crash with curl < 7.61.0");
16+
}
17+
?>
18+
--FILE--
19+
<?php
20+
$callback = function($parent_ch, $pushed_ch, array $headers) use (&$transfers) {
21+
return CURL_PUSH_OK;
22+
};
23+
24+
$mh = curl_multi_init();
25+
26+
curl_multi_setopt($mh, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
27+
curl_multi_setopt($mh, CURLMOPT_PUSHFUNCTION, $callback);
28+
29+
$ch = curl_init();
30+
curl_setopt($ch, CURLOPT_URL, "https://localhost/serverpush");
31+
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
32+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
33+
34+
curl_multi_add_handle($mh, $ch);
35+
36+
$responses = [];
37+
$active = null;
38+
do {
39+
$status = curl_multi_exec($mh, $active);
40+
41+
do {
42+
$info = curl_multi_info_read($mh);
43+
if (false !== $info && $info['msg'] == CURLMSG_DONE) {
44+
$handle = $info['handle'];
45+
if ($handle !== null) {
46+
$transfers--;
47+
$responses[] = curl_multi_getcontent($info['handle']);
48+
curl_multi_remove_handle($mh, $handle);
49+
curl_close($handle);
50+
}
51+
}
52+
} while ($info);
53+
} while (count($responses) !== 2);
54+
55+
curl_multi_close($mh);
56+
57+
sort($responses);
58+
print_r($responses);
59+
--EXPECT--
60+
Array
61+
(
62+
[0] => main response
63+
[1] => pushed response
64+
)

0 commit comments

Comments
 (0)