Skip to content

Commit 1512e21

Browse files
committed
Merge r1898068 from trunk:
*) test: capture and parse output from nghttp more reliably. add repeat param to certain proxy tests. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1898069 13f79535-47bb-0310-9956-ffa450edef68
1 parent dd38dd7 commit 1512e21

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

test/modules/http2/test_500_proxy.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ class TestProxy:
1010

1111
@pytest.fixture(autouse=True, scope='class')
1212
def _class_scope(self, env):
13-
TestProxy._local_dir = os.path.dirname(inspect.getfile(TestProxy))
1413
H2Conf(env).add_vhost_cgi(proxy_self=True).install()
1514
assert env.apache_restart() == 0
1615

1716
def local_src(self, fname):
18-
return os.path.join(TestProxy._local_dir, fname)
17+
return os.path.join(os.path.dirname(inspect.getfile(TestProxy)), fname)
1918

2019
def setup_method(self, method):
2120
print("setup_method: %s" % method.__name__)
@@ -28,10 +27,10 @@ def test_h2_500_01(self, env):
2827
r = env.curl_get(url, 5)
2928
assert r.response["status"] == 200
3029
assert "HTTP/1.1" == r.response["json"]["protocol"]
31-
assert "" == r.response["json"]["https"]
32-
assert "" == r.response["json"]["ssl_protocol"]
33-
assert "" == r.response["json"]["h2"]
34-
assert "" == r.response["json"]["h2push"]
30+
assert r.response["json"]["https"] == ""
31+
assert r.response["json"]["ssl_protocol"] == ""
32+
assert r.response["json"]["h2"] == ""
33+
assert r.response["json"]["h2push"] == ""
3534

3635
# upload and GET again using curl, compare to original content
3736
def curl_upload_and_verify(self, env, fname, options=None):
@@ -47,9 +46,9 @@ def curl_upload_and_verify(self, env, fname, options=None):
4746
assert r2.response["status"] == 200
4847
with open(self.local_src(fpath), mode='rb') as file:
4948
src = file.read()
50-
assert src == r2.response["body"]
49+
assert r2.response["body"] == src
5150

52-
def test_h2_500_10(self, env):
51+
def test_h2_500_10(self, env, repeat):
5352
self.curl_upload_and_verify(env, "data-1k", ["--http2"])
5453
self.curl_upload_and_verify(env, "data-10k", ["--http2"])
5554
self.curl_upload_and_verify(env, "data-100k", ["--http2"])
@@ -64,15 +63,20 @@ def nghttp_post_and_verify(self, env, fname, options=None):
6463
assert 200 <= r.response["status"] < 300
6564
with open(self.local_src(fpath), mode='rb') as file:
6665
src = file.read()
67-
assert src == r.response["body"]
68-
69-
def test_h2_500_20(self, env):
66+
if r.response["body"] != src:
67+
with open(os.path.join(env.gen_dir, "nghttp.out"), 'w') as fd:
68+
fd.write(r.outraw)
69+
fd.write("\nstderr:\n")
70+
fd.write(r.stderr)
71+
assert r.response["body"] == src
72+
73+
def test_h2_500_20(self, env, repeat):
7074
self.nghttp_post_and_verify(env, "data-1k", [])
7175
self.nghttp_post_and_verify(env, "data-10k", [])
7276
self.nghttp_post_and_verify(env, "data-100k", [])
7377
self.nghttp_post_and_verify(env, "data-1m", [])
7478

75-
def test_h2_500_21(self, env):
79+
def test_h2_500_21(self, env, repeat):
7680
self.nghttp_post_and_verify(env, "data-1k", ["--no-content-length"])
7781
self.nghttp_post_and_verify(env, "data-10k", ["--no-content-length"])
7882
self.nghttp_post_and_verify(env, "data-100k", ["--no-content-length"])

test/pyhttpd/nghttp.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ def parse_output(self, btext) -> Dict:
8484
if len(l) == 0:
8585
body += '\n'
8686
continue
87-
m = re.match(r'\[.*] recv \(stream_id=(\d+)\) (\S+): (\S*)', l)
87+
m = re.match(r'(.*)\[.*] recv \(stream_id=(\d+)\) (\S+): (\S*)', l)
8888
if m:
89-
s = self.get_stream(streams, m.group(1))
90-
hname = m.group(2)
91-
hval = m.group(3)
89+
body += m.group(1)
90+
s = self.get_stream(streams, m.group(2))
91+
hname = m.group(3)
92+
hval = m.group(4)
9293
print("stream %d header %s: %s" % (s["id"], hname, hval))
9394
header = s["header"]
9495
if hname in header:
@@ -98,9 +99,10 @@ def parse_output(self, btext) -> Dict:
9899
body = ''
99100
continue
100101

101-
m = re.match(r'\[.*] recv HEADERS frame <.* stream_id=(\d+)>', l)
102+
m = re.match(r'(.*)\[.*] recv HEADERS frame <.* stream_id=(\d+)>', l)
102103
if m:
103-
s = self.get_stream(streams, m.group(1))
104+
body += m.group(1)
105+
s = self.get_stream(streams, m.group(2))
104106
if s:
105107
print("stream %d: recv %d header" % (s["id"], len(s["header"])))
106108
response = s["response"]
@@ -123,8 +125,8 @@ def parse_output(self, btext) -> Dict:
123125

124126
m = re.match(r'(.*)\[.*] recv DATA frame <length=(\d+), .*stream_id=(\d+)>', l)
125127
if m:
126-
s = self.get_stream(streams, m.group(3))
127128
body += m.group(1)
129+
s = self.get_stream(streams, m.group(3))
128130
blen = int(m.group(2))
129131
if s:
130132
print("stream %d: %d DATA bytes added" % (s["id"], blen))
@@ -140,9 +142,10 @@ def parse_output(self, btext) -> Dict:
140142
skip_indents = True
141143
continue
142144

143-
m = re.match(r'\[.*] recv PUSH_PROMISE frame <.* stream_id=(\d+)>', l)
145+
m = re.match(r'(.*)\[.*] recv PUSH_PROMISE frame <.* stream_id=(\d+)>', l)
144146
if m:
145-
s = self.get_stream(streams, m.group(1))
147+
body += m.group(1)
148+
s = self.get_stream(streams, m.group(2))
146149
if s:
147150
# headers we have are request headers for the PUSHed stream
148151
# these have been received on the originating stream, the promised
@@ -283,7 +286,7 @@ def upload_file(self, url, fpath, timeout=5, options=None):
283286
def _run(self, args) -> ExecResult:
284287
print(("execute: %s" % " ".join(args)))
285288
start = datetime.now()
286-
p = subprocess.run(args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
289+
p = subprocess.run(args, capture_output=True, text=False)
287290
return ExecResult(args=args, exit_code=p.returncode,
288291
stdout=p.stdout, stderr=p.stderr,
289292
duration=datetime.now() - start)

0 commit comments

Comments
 (0)