24 lines
626 B
Python
24 lines
626 B
Python
import asyncio
|
|
import threading
|
|
|
|
from k1link.fleet.events import FleetEvents
|
|
|
|
|
|
def test_registry_events_cross_thread_coalesce_and_unsubscribe():
|
|
async def check():
|
|
events = FleetEvents()
|
|
queue, close = events.subscribe()
|
|
thread = threading.Thread(target=lambda: [events.notify() for _ in range(20)])
|
|
thread.start()
|
|
thread.join()
|
|
await asyncio.sleep(0)
|
|
assert queue.qsize() == 1
|
|
await queue.get()
|
|
close()
|
|
events.notify()
|
|
await asyncio.sleep(0)
|
|
assert queue.empty()
|
|
assert not events.listeners
|
|
|
|
asyncio.run(check())
|