File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed
Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,19 @@ def test_caches_will_delete_when_asked() -> None:
7474 assert "test" not in cache
7575
7676
77+ def test_caches_pop () -> None :
78+ with local_intermittent_storage ("test" ) as cache :
79+ cache .empty ()
80+
81+ with local_intermittent_storage ("test" ) as cache :
82+ cache ["A" ] = "1"
83+
84+ with local_intermittent_storage ("test" ) as cache :
85+ assert cache .pop ("A" ) == "1"
86+ assert cache .pop ("B" ) is None
87+ assert cache .pop ("C" , default = 3 ) == 3
88+
89+
7790def test_caches_can_have_tuple_or_singleton_keys () -> None :
7891 with local_persistent_storage ("test_caches_can_have_tuple_keys" ) as c :
7992 c [(1 , 2 )] = 1
Original file line number Diff line number Diff line change @@ -348,7 +348,7 @@ def __enter__(self):
348348 PRAGMA cache_size = -4000;
349349 """
350350 )
351- self .cursor .execute ("BEGIN" )
351+ self .cursor .execute ("BEGIN IMMEDIATE " )
352352 self ._initialize_table ()
353353 return self
354354
@@ -394,9 +394,8 @@ def iterkeys(self):
394394 return (self .convert_key (row [0 ]) for row in self .cursor .fetchall ())
395395
396396 def pop (self , key , default = None ):
397- self .cursor .execute (f"SELECT value FROM { self .table_name } WHERE key = ?" , (key ,))
397+ self .cursor .execute (f"DELETE FROM { self .table_name } WHERE key = ? RETURNING value " , (key ,))
398398 result = self .cursor .fetchone ()
399- self .cursor .execute (f"DELETE FROM { self .table_name } WHERE key = ?" , (key ,))
400399
401400 if result is None :
402401 return default
@@ -647,6 +646,7 @@ def __init__(self) -> None:
647646 )
648647 self .cursor = self .conn .cursor ()
649648 self ._create_tables ()
649+ self .cursor .execute ("BEGIN IMMEDIATE" )
650650
651651 def _create_tables (self ) -> None :
652652 # TODO: add a created_at, updated_at to pio_job_published_settings
Original file line number Diff line number Diff line change 11[pytest]
22testpaths =pioreactor/tests/
3- addopts = --random-order
3+ addopts = --random-order -s -vv
You can’t perform that action at this time.
0 commit comments