Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 5704d26

Browse files
committed
Merge pull request #236 from tbetbetbe/development-test-bugfix
Correct a test that fails sporadically
2 parents 065b539 + 7422011 commit 5704d26

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

test/test_http11.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,15 +477,16 @@ def test_exception_raised_for_illegal_elements_in_iterable_body(self):
477477
c = HTTP11Connection('httpbin.org')
478478

479479
rogue_element = 123
480+
body = [b'legal1', b'legal2', rogue_element]
481+
body_size = sum(len(bytes(x)) for x in body)
480482
with pytest.raises(ValueError) as exc_info:
481483
# content-length set so body type is set to BODY_FLAT. value
482484
# doesn't matter
483-
body = ['legal1', 'legal2', rogue_element]
484485
c.request(
485486
'GET',
486487
'/get',
487488
body=body,
488-
headers={'content-length': str(len(map(str, body)))}
489+
headers={'content-length': str(body_size)}
489490
)
490491
assert 'Elements in iterable body must be bytestrings. Illegal ' \
491492
'element: {}'.format(rogue_element) \

test/test_integration.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ def socket_handler(listener):
361361
sock.send(f.serialize())
362362

363363
# Now, send a headers frame again, containing trailing headers.
364-
f = build_headers_frame([(':res', 'no'), ('trailing', 'sure')], e)
364+
f = build_headers_frame([
365+
('trialing', 'no'),
366+
('trailing', 'sure')], e)
365367
f.flags.add('END_STREAM')
366368
f.stream_id = 1
367369
sock.send(f.serialize())
@@ -385,9 +387,10 @@ def socket_handler(listener):
385387
# Confirm that we got the trailing headers, and that they don't contain
386388
# reserved headers.
387389
assert resp.trailers['trailing'] == [b'sure']
390+
assert resp.trailers['trialing'] == [b'no']
388391
assert resp.trailers.get(':res') is None
389392
assert len(resp.headers) == 1
390-
assert len(resp.trailers) == 1
393+
assert len(resp.trailers) == 2
391394

392395
# Awesome, we're done now.
393396
recv_event.wait(5)
@@ -429,7 +432,9 @@ def socket_handler(listener):
429432
time.sleep(0.5)
430433

431434
# Now, send a headers frame again, containing trailing headers.
432-
f = build_headers_frame([(':res', 'no'), ('trailing', 'sure')], e)
435+
f = build_headers_frame([
436+
('trialing', 'no'),
437+
('trailing', 'sure')], e)
433438
f.flags.add('END_STREAM')
434439
f.stream_id = 1
435440
sock.send(f.serialize())
@@ -453,9 +458,9 @@ def socket_handler(listener):
453458
# reserved headers. More importantly, check the trailers *first*,
454459
# before we read from the stream.
455460
assert resp.trailers['trailing'] == [b'sure']
456-
assert resp.trailers.get(':res') is None
461+
assert resp.trailers['trialing'] == [b'no']
457462
assert len(resp.headers) == 1
458-
assert len(resp.trailers) == 1
463+
assert len(resp.trailers) == 2
459464

460465
# Confirm that the stream is still readable.
461466
assert resp.read() == b'have some data'

0 commit comments

Comments
 (0)