RedisState's compare-and-swap watches through its pipeline, so a write between the compare and EXEC fails the swap; pause_intake waits out a claim already under way, so nothing dispatches after it returns
This commit is contained in:
@@ -38,3 +38,17 @@ def test_a_compare_and_swap_names_what_it_wrote(state):
|
||||
state.set("heat.a", 1)
|
||||
assert state.compare_and_swap_multi({"heat.a": 1}, {"heat.b": 2})
|
||||
assert "heat.b" in state.message_names()
|
||||
|
||||
|
||||
def test_a_compare_and_swap_loses_to_a_write_after_its_read(state, monkeypatch):
|
||||
state.set("heat.a", 1)
|
||||
note = RedisState._note
|
||||
|
||||
def racing_note(self, pipe, keys):
|
||||
# Another writer lands between the compare and EXEC.
|
||||
self._client.set(self._key("heat.a"), b"2")
|
||||
note(self, pipe, keys)
|
||||
|
||||
monkeypatch.setattr(RedisState, "_note", racing_note)
|
||||
assert not state.compare_and_swap_multi({"heat.a": 1}, {"heat.a": 3})
|
||||
assert state.get("heat.a") == 2
|
||||
|
||||
Reference in New Issue
Block a user