StateManagerDisk now acts much more like StateManagerMemory
Treat StateManagerDisk like StateManagerMemory for AppHarness
This commit is contained in:
parent
eebcbc1054
commit
ae24d72201
@ -292,8 +292,6 @@ class AppHarness:
|
|||||||
if isinstance(self.app_instance._state_manager, StateManagerRedis):
|
if isinstance(self.app_instance._state_manager, StateManagerRedis):
|
||||||
# Create our own redis connection for testing.
|
# Create our own redis connection for testing.
|
||||||
self.state_manager = StateManagerRedis.create(self.app_instance.state)
|
self.state_manager = StateManagerRedis.create(self.app_instance.state)
|
||||||
elif isinstance(self.app_instance._state_manager, StateManagerDisk):
|
|
||||||
self.state_manager = StateManagerDisk.create(self.app_instance.state)
|
|
||||||
else:
|
else:
|
||||||
self.state_manager = self.app_instance._state_manager
|
self.state_manager = self.app_instance._state_manager
|
||||||
|
|
||||||
|
@ -1884,11 +1884,11 @@ async def test_state_proxy(grandchild_state: GrandchildState, mock_app: rx.App):
|
|||||||
async with sp:
|
async with sp:
|
||||||
assert sp._self_actx is not None
|
assert sp._self_actx is not None
|
||||||
assert sp._self_mutable # proxy is mutable inside context
|
assert sp._self_mutable # proxy is mutable inside context
|
||||||
if isinstance(mock_app.state_manager, StateManagerMemory):
|
if isinstance(mock_app.state_manager, (StateManagerMemory, StateManagerDisk)):
|
||||||
# For in-process store, only one instance of the state exists
|
# For in-process store, only one instance of the state exists
|
||||||
assert sp.__wrapped__ is grandchild_state
|
assert sp.__wrapped__ is grandchild_state
|
||||||
else:
|
else:
|
||||||
# When redis or disk is used, a new+updated instance is assigned to the proxy
|
# When redis is used, a new+updated instance is assigned to the proxy
|
||||||
assert sp.__wrapped__ is not grandchild_state
|
assert sp.__wrapped__ is not grandchild_state
|
||||||
sp.value2 = "42"
|
sp.value2 = "42"
|
||||||
assert not sp._self_mutable # proxy is not mutable after exiting context
|
assert not sp._self_mutable # proxy is not mutable after exiting context
|
||||||
@ -1899,7 +1899,7 @@ async def test_state_proxy(grandchild_state: GrandchildState, mock_app: rx.App):
|
|||||||
gotten_state = await mock_app.state_manager.get_state(
|
gotten_state = await mock_app.state_manager.get_state(
|
||||||
_substate_key(grandchild_state.router.session.client_token, grandchild_state)
|
_substate_key(grandchild_state.router.session.client_token, grandchild_state)
|
||||||
)
|
)
|
||||||
if isinstance(mock_app.state_manager, StateManagerMemory):
|
if isinstance(mock_app.state_manager, (StateManagerMemory, StateManagerDisk)):
|
||||||
# For in-process store, only one instance of the state exists
|
# For in-process store, only one instance of the state exists
|
||||||
assert gotten_state is parent_state
|
assert gotten_state is parent_state
|
||||||
else:
|
else:
|
||||||
@ -2922,7 +2922,7 @@ async def test_get_state(mock_app: rx.App, token: str):
|
|||||||
_substate_key(token, ChildState2)
|
_substate_key(token, ChildState2)
|
||||||
)
|
)
|
||||||
assert isinstance(new_test_state, TestState)
|
assert isinstance(new_test_state, TestState)
|
||||||
if isinstance(mock_app.state_manager, StateManagerMemory):
|
if isinstance(mock_app.state_manager, (StateManagerMemory, StateManagerDisk)):
|
||||||
# In memory, it's the same instance
|
# In memory, it's the same instance
|
||||||
assert new_test_state is test_state
|
assert new_test_state is test_state
|
||||||
test_state._clean()
|
test_state._clean()
|
||||||
@ -2932,15 +2932,6 @@ async def test_get_state(mock_app: rx.App, token: str):
|
|||||||
ChildState2.get_name(),
|
ChildState2.get_name(),
|
||||||
ChildState3.get_name(),
|
ChildState3.get_name(),
|
||||||
)
|
)
|
||||||
elif isinstance(mock_app.state_manager, StateManagerDisk):
|
|
||||||
# On disk, it's a new instance
|
|
||||||
assert new_test_state is not test_state
|
|
||||||
# All substates are available
|
|
||||||
assert tuple(sorted(new_test_state.substates)) == (
|
|
||||||
ChildState.get_name(),
|
|
||||||
ChildState2.get_name(),
|
|
||||||
ChildState3.get_name(),
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
# With redis, we get a whole new instance
|
# With redis, we get a whole new instance
|
||||||
assert new_test_state is not test_state
|
assert new_test_state is not test_state
|
||||||
|
Loading…
Reference in New Issue
Block a user