Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/modules/proxy/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def _process(self):
# capture request to backend
self._request = data
c.sendall(self._make_response(data))
# Half-close for an orderly FIN instead of letting the
# OS tear the socket down under us. An abrupt close()
# right after sendall() can, depending on the platform's
# TCP stack and buffering, surface to the peer as a
# reset rather than a clean end of the response, which
# httpd's proxy and cache code treat as an aborted
# connection and a reason to discard the cache entry.
try:
c.shutdown(socket.SHUT_WR)
except OSError:
pass
finally:
c.close()
except socket.timeout:
Expand Down
10 changes: 10 additions & 0 deletions test/modules/proxy/test_07_cache_control.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time
import uuid

import pytest
Expand Down Expand Up @@ -131,6 +132,12 @@ def test_proxy_07_001(self, env, index):
def test_proxy_07_002(self, env, index):
cc = ", ".join(CASES[index][0])
r1 = self.get(env, index)
# The cache entry for r1 is committed by the CACHE_SAVE filter on
# the EOS-only pass that follows the body, which can still be
# running server side for an instant after the body itself has
# already reached this process. Give it room to land before relying
# on it, instead of risking a spurious backend hit on r2.
time.sleep(0.1)
r2 = self.get(env, index)
assert self.backend_hits(index) == 1, f"Cache-Control: {cc} not cached"
assert r2["header"]["x-cache"].startswith("HIT")
Expand All @@ -145,6 +152,9 @@ def test_proxy_07_003(self, env, index):
r1 = self.get(env, index)
assert r1["header"]["x-secret"] == "s"
assert r1["header"]["set-cookie"] == "a=b"
# See test_proxy_07_002: give the CACHE_SAVE filter's commit time
# to land before asserting on it.
time.sleep(0.1)
r2 = self.get(env, index)
assert self.backend_hits(index) == 1, f"Cache-Control: {cc} not cached"
assert r2["header"]["x-cache"].startswith("HIT")
Expand Down
Loading