File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -120,3 +120,30 @@ async def consume_addrs():
120
120
nursery .cancel_scope .cancel ()
121
121
122
122
assert collected == [addr1 , addr2 ]
123
+
124
+
125
+ @pytest .mark .trio
126
+ async def test_cleanup_task_remove_expired_data ():
127
+ store = PeerStore ()
128
+ peer_id = ID (b"peer123" )
129
+ addr = Multiaddr ("/ip4/127.0.0.1/tcp/4040" )
130
+
131
+ # Insert addrs with short TTL (0.01s)
132
+ store .add_addr (peer_id , addr , 1 )
133
+
134
+ assert store .addrs (peer_id ) == [addr ]
135
+ assert peer_id in store .peer_data_map
136
+
137
+ # Start cleanup task in a nursery
138
+ async with trio .open_nursery () as nursery :
139
+ # Run the cleanup task with a short interval so it runs soon
140
+ nursery .start_soon (store .start_cleanup_task , 1 )
141
+
142
+ # Sleep long enough for TTL to expire and cleanup to run
143
+ await trio .sleep (3 )
144
+
145
+ # Cancel the nursery to stop background tasks
146
+ nursery .cancel_scope .cancel ()
147
+
148
+ # Confirm the peer data is gone from the peer_data_map
149
+ assert peer_id not in store .peer_data_map
You can’t perform that action at this time.
0 commit comments