Skip to content

Commit

Permalink
Adjust some test logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tdg5 committed Aug 15, 2024
1 parent 6eeee2d commit df6c45e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions reqless/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,20 @@ def __init__(self, database: Redis):

def listen(self) -> None:
"""Listen for events"""
print("pre for", flush=True)
for message in self._listener.listen():
print("start iteration", flush=True)
logger.debug("Message: %s", message)
print("pre channel", flush=True)
# Strip off the 'namespace' from the channel
channel = message["channel"][len(self.namespace) :]
print("post channel", flush=True)
func = self._callbacks.get(channel)
print("post func", flush=True)
if func:
print("pre func call", flush=True)
func(message["data"])
print("post func call", flush=True)

def on(self, evt: str, func: Optional[Callable]) -> None:
"""Set a callback handler for a pubsub event"""
Expand All @@ -89,5 +96,8 @@ def thread(self) -> Generator["Events", None, None]:
try:
yield self
finally:
print("pre unlisten", flush=True)
self.unlisten()
print("pre join", flush=True)
thread.join()
print("post join", flush=True)
5 changes: 5 additions & 0 deletions reqless_test/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ def func(event: Dict) -> None:
count += 1

self.client.events.on("popped", func)
print("pre thread", flush=True)
with self.client.events.thread():
print("pre pop", flush=True)
self.client.queues["foo"].pop()
print("post pop", flush=True)
print("post thread", flush=True)
self.assertEqual(count, 1)
print("post assert", flush=True)

def test_off(self) -> None:
"""Ensure we can turn off callbacks"""
Expand Down

0 comments on commit df6c45e

Please sign in to comment.