-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep sessions marked as deleted for an hour before purging them from the Redis store. This change is to allow the client to recover from a session deletion when the user navigates back to the page.
- Loading branch information
Showing
4 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from livecomponents.types import StateAddress | ||
|
||
|
||
def test_save_state_sets_ttl(redis_state_store): | ||
state_addr = StateAddress(session_id="session_id", component_id="|root:0") | ||
state = b"state" | ||
redis_state_store.save_state(state_addr, state) | ||
|
||
# A bit less than ttl | ||
state_key = get_state_key(redis_state_store, state_addr) | ||
assert ( | ||
redis_state_store.client.ttl(state_key) | ||
> redis_state_store.ttl.total_seconds() - 10 | ||
) | ||
|
||
|
||
def test_clear_session_sets_ttl_gc(redis_state_store): | ||
session_id = "session_id" | ||
state_addr = StateAddress(session_id=session_id, component_id="|root:0") | ||
state = b"state" | ||
redis_state_store.save_state(state_addr, state) | ||
|
||
# A bit less than ttl_gc | ||
redis_state_store.clear_session(session_id) | ||
state_key = get_state_key(redis_state_store, state_addr) | ||
assert ( | ||
redis_state_store.client.ttl(state_key) | ||
<= redis_state_store.ttl_gc.total_seconds() | ||
) | ||
|
||
|
||
def test_clear_session_and_then_save_state_recovers_ttl(redis_state_store): | ||
session_id = "session_id" | ||
state_addr = StateAddress(session_id=session_id, component_id="|root:0") | ||
state = b"state" | ||
redis_state_store.save_state(state_addr, state) | ||
redis_state_store.clear_session(session_id) | ||
redis_state_store.save_state(state_addr, state) | ||
|
||
# A bit less than ttl again | ||
state_key = get_state_key(redis_state_store, state_addr) | ||
assert ( | ||
redis_state_store.client.ttl(state_key) | ||
> redis_state_store.ttl.total_seconds() - 10 | ||
) | ||
|
||
|
||
def get_state_key(redis_state_store, state_addr): | ||
return redis_state_store._get_key_name( | ||
redis_state_store.key_prefix, state_addr.session_id | ||
) |