[Bugfix][KV Offload] Ignore stale async lookup results (#54872)
Signed-off-by: Alex <jihui.huang@daocloud.io> Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
co-authored by
OpenAI Codex
parent
ffe3bb3c72
commit
35faf957d6
@@ -104,6 +104,28 @@ class TestAsyncLookupManager:
|
||||
assert _key(1) not in mgr._lookup_state
|
||||
mgr.shutdown()
|
||||
|
||||
def test_stale_result_ignored_after_cleanup_and_key_reuse(self):
|
||||
key = _key(1)
|
||||
mgr = InMemoryLookupManager()
|
||||
ctx_a = _ctx("req_a")
|
||||
ctx_b = _ctx("req_b")
|
||||
assert mgr.lookup(key, ctx_a) is None
|
||||
stale_generation = mgr._lookup_state[key].generation
|
||||
mgr.cleanup("req_a")
|
||||
|
||||
assert mgr.lookup(key, ctx_b) is None
|
||||
generation = mgr._lookup_state[key].generation
|
||||
assert generation != stale_generation
|
||||
|
||||
mgr._pending_results.put([(key, stale_generation, True)])
|
||||
mgr.drain_results()
|
||||
assert mgr.lookup(key, ctx_b) is None
|
||||
|
||||
mgr._pending_results.put([(key, generation, False)])
|
||||
mgr.drain_results()
|
||||
assert mgr.lookup(key, ctx_b) is False
|
||||
mgr.shutdown()
|
||||
|
||||
def test_flush_no_queue_post_when_empty(self):
|
||||
mgr = InMemoryLookupManager()
|
||||
mgr.flush()
|
||||
@@ -220,7 +242,8 @@ class TestAsyncLookupManager:
|
||||
|
||||
# (b) A stray/duplicate result for the now-decided key violates the
|
||||
# enqueue-once invariant and must trip the assert.
|
||||
mgr._pending_results.put([(_key(1), True)])
|
||||
generation = mgr._lookup_state[_key(1)].generation
|
||||
mgr._pending_results.put([(_key(1), generation, True)])
|
||||
with pytest.raises(AssertionError):
|
||||
mgr.drain_results()
|
||||
mgr.shutdown()
|
||||
|
||||
Reference in New Issue
Block a user