Skip to content

Commit

Permalink
New test for emit_threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
gnzsnz committed Aug 20, 2024
1 parent b80e08c commit 0dd4ad4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/event_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,26 @@ def test_operator_connect(self):
ev1.emit(i)
self.assertEqual(result, list(range(10, 20)))

def test_emit_threadsafe(self):
async def coro(d):
result.append(d)
await asyncio.sleep(0)

result = []
event = Event("test")
event += coro

event.emit_threadsafe(4)
event.emit_threadsafe(2)
run(asyncio.sleep(0))
self.assertEqual(result, [4, 2])

result.clear()
event -= coro
event.emit_threadsafe(8)
run(asyncio.sleep(0))
self.assertEqual(result, [])


if __name__ == "__main__":
unittest.main()

0 comments on commit 0dd4ad4

Please sign in to comment.