Skip to content

Commit 1fe89d3

Browse files
authored
gh-70765: fix an HTTP/0.9 flaky test post GH-139514 (#139610)
Fix a flaky test introduced in 13dc2fd. After a single HTTP/0.9 request, both client and server are expected to close the connection on their side. In particular, if a client sends two requests with the same connection, only the first one should be handled. In the tests, it might happen that checking for the second request to be ignored did not take into account that the server may have already closed the connection. This flaky behavior was first observed on macOS CI workers but could not be reproduced locally on a Linux machine.
1 parent 6edb2dd commit 1fe89d3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Lib/test/test_httpservers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,13 @@ def test_single_request(self):
391391
res = self.sock.recv(1024)
392392
self.assertEqual(res, b"OK: here is /foo.html\r\n")
393393

394-
self.sock.send(b'GET /bar.html\r\n')
395-
res = self.sock.recv(1024)
396-
# The server will not parse more input as it closed the connection.
397-
# Note that the socket connection itself is still opened since the
398-
# client is responsible for also closing it on their side.
399-
self.assertEqual(res, b'')
394+
# Ignore errors if the connection is already closed,
395+
# as this is the expected behavior of HTTP/0.9.
396+
with contextlib.suppress(OSError):
397+
self.sock.send(b'GET /bar.html\r\n')
398+
res = self.sock.recv(1024)
399+
# The server should not process our request.
400+
self.assertEqual(res, b'')
400401

401402

402403
def certdata_file(*path):

0 commit comments

Comments
 (0)