Skip to content

Commit 3023661

Browse files
committed
fix test for oplock enabled
1 parent 2480363 commit 3023661

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

tests/units/test_state.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4398,21 +4398,24 @@ class MutableProxyState(BaseState):
43984398
async def test_rebind_mutable_proxy(mock_app: rx.App, token: str) -> None:
43994399
"""Test that previously bound MutableProxy instances can be rebound correctly."""
44004400
mock_app.state_manager.state = mock_app._state = MutableProxyState
4401-
state = await mock_app.state_manager.get_state(
4401+
async with mock_app.state_manager.modify_state(
44024402
_substate_key(token, MutableProxyState)
4403-
)
4404-
state.router = RouterData.from_router_data({
4405-
"query": {},
4406-
"token": token,
4407-
"sid": "test_sid",
4408-
})
4409-
state_proxy = StateProxy(state)
4410-
assert isinstance(state_proxy.data, MutableProxy)
4403+
) as state:
4404+
state.router = RouterData.from_router_data({
4405+
"query": {},
4406+
"token": token,
4407+
"sid": "test_sid",
4408+
})
4409+
state_proxy = StateProxy(state)
4410+
assert isinstance(state_proxy.data, MutableProxy)
44114411
async with state_proxy:
44124412
state_proxy.data["a"] = state_proxy.data["b"]
44134413
assert state_proxy.data["a"] is not state_proxy.data["b"]
44144414
assert state_proxy.data["a"].__wrapped__ is state_proxy.data["b"].__wrapped__
44154415

4416+
# Flush any oplock.
4417+
await mock_app.state_manager.close()
4418+
44164419
new_state_proxy = StateProxy(state)
44174420
assert state_proxy is not new_state_proxy
44184421
assert new_state_proxy.data["a"]._self_state is new_state_proxy
@@ -4421,13 +4424,13 @@ async def test_rebind_mutable_proxy(mock_app: rx.App, token: str) -> None:
44214424
async with state_proxy:
44224425
state_proxy.data["a"].append(3)
44234426

4424-
state = await mock_app.state_manager.get_state(
4427+
async with mock_app.state_manager.modify_state(
44254428
_substate_key(token, MutableProxyState)
4426-
)
4427-
assert state.data["a"] == [2, 3]
4428-
if isinstance(mock_app.state_manager, StateManagerRedis):
4429-
# In redis mode, the object identity does not persist across async with self calls.
4430-
assert state.data["b"] == [2]
4431-
else:
4432-
# In disk/memory mode, the fact that data["b"] was mutated via data["a"] persists.
4433-
assert state.data["b"] == [2, 3]
4429+
) as state:
4430+
assert state.data["a"] == [2, 3]
4431+
if isinstance(mock_app.state_manager, StateManagerRedis):
4432+
# In redis mode, the object identity does not persist across async with self calls.
4433+
assert state.data["b"] == [2]
4434+
else:
4435+
# In disk/memory mode, the fact that data["b"] was mutated via data["a"] persists.
4436+
assert state.data["b"] == [2, 3]

0 commit comments

Comments
 (0)