@@ -495,6 +495,46 @@ def callback(n: str) -> None:
495
495
await session .close ()
496
496
497
497
498
+ # noinspection PyShadowingNames,DuplicatedCode
499
+ @pytest .mark .asyncio (loop_scope = "function" )
500
+ async def test_cache_destroy_event () -> None :
501
+ session : Session = await tests .get_session ()
502
+ cache : NamedCache [str , str ] = await session .get_cache ("test-" + str (int (time () * 1000 )))
503
+ name : str = "UNSET"
504
+ destroy_event : Event = Event ()
505
+ release_event : Event = Event ()
506
+
507
+ def destroy_callback (n : str ) -> None :
508
+ nonlocal name
509
+ name = n
510
+ destroy_event .set ()
511
+
512
+ cache .on (MapLifecycleEvent .DESTROYED , destroy_callback )
513
+
514
+ def release_callback (n : str ) -> None :
515
+ nonlocal name
516
+ name = n
517
+ release_event .set ()
518
+
519
+ cache .on (MapLifecycleEvent .RELEASED , release_callback )
520
+
521
+ try :
522
+ await cache .put ("A" , "B" )
523
+ await cache .put ("C" , "D" )
524
+ assert await cache .size () == 2
525
+
526
+ await cache .destroy ()
527
+ await tests .wait_for (destroy_event , EVENT_TIMEOUT )
528
+ await tests .wait_for (release_event , EVENT_TIMEOUT )
529
+
530
+ assert name == cache .name
531
+ assert cache .destroyed
532
+ assert cache .released
533
+ assert not cache .active
534
+ finally :
535
+ await session .close ()
536
+
537
+
498
538
# noinspection PyShadowingNames,DuplicatedCode,PyUnresolvedReferences
499
539
@pytest .mark .asyncio
500
540
async def test_add_remove_index (person_cache : NamedCache [str , Person ]) -> None :
@@ -603,7 +643,7 @@ async def test_ttl_configuration(test_session: Session) -> None:
603
643
604
644
@pytest .mark .asyncio
605
645
async def test_unary_error (test_session : Session ) -> None :
606
- cache : NamedCache [str , str ] = await test_session .get_cache ("unary_error" )
646
+ cache : NamedCache [str , dict ] = await test_session .get_cache ("unary_error" )
607
647
608
648
d = dict ()
609
649
d ["@class" ] = "com.foo.Bar"
0 commit comments