Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/test_cancellation_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
# Contributors:
# ZettaScale Zenoh Team, <zenoh@zettascale.tech>
#
import gc
import time
import weakref

import zenoh
from zenoh import CancellationToken, Reply
Expand Down Expand Up @@ -55,7 +57,11 @@ def on_reply(reply: zenoh.Reply):
nonlocal n
n += 10

on_reply.session = session2
callback_ref = weakref.ref(on_reply)
session2.get(keyexpr, on_reply, cancellation_token=cancellation_token)
del on_reply
assert callback_ref() is not None
q = queryable.recv()
q.reply(keyexpr, "ok")
q.drop()
Expand All @@ -65,6 +71,8 @@ def on_reply(reply: zenoh.Reply):
cancellation_token.cancel()
assert n == 10
assert cancellation_token.is_cancelled
gc.collect()
assert callback_ref() is None, "Reply callback retained after cancellation"

print("Test that cancelled token cancels operation automatically")
try:
Expand Down Expand Up @@ -105,7 +113,11 @@ def on_reply(reply: zenoh.Reply):
nonlocal n
n += 10

on_reply.resources = (session2, querier)
callback_ref = weakref.ref(on_reply)
querier.get(on_reply, cancellation_token=cancellation_token)
del on_reply
assert callback_ref() is not None
q = queryable.recv()
q.reply(keyexpr, "ok")
q.drop()
Expand All @@ -115,6 +127,8 @@ def on_reply(reply: zenoh.Reply):
cancellation_token.cancel()
assert n == 10
assert cancellation_token.is_cancelled
gc.collect()
assert callback_ref() is None, "Querier callback retained after cancellation"

print("Test that cancelled token cancels operation automatically")
try:
Expand All @@ -140,13 +154,19 @@ def on_reply(reply: zenoh.Reply):
nonlocal n
n += 10

on_reply.session = session2
callback_ref = weakref.ref(on_reply)
session2.liveliness().get(keyexpr, on_reply, cancellation_token=cancellation_token)
del on_reply
assert callback_ref() is not None
time.sleep(1)

assert not cancellation_token.is_cancelled
cancellation_token.cancel()
assert n == 10
assert cancellation_token.is_cancelled
gc.collect()
assert callback_ref() is None, "Liveliness callback retained after cancellation"

print("Test that cancelled token cancels operation automatically")
try:
Expand Down
Loading
Loading