1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-08 21:18:16 +03:00

python:tests: Ensure we clean up callbacks in pymessaging tests

Not calling ‘deregister()’ results in memory getting leaked.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>

Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Wed Nov 15 23:11:13 UTC 2023 on atb-devel-224
This commit is contained in:
Joseph Sutton 2023-11-14 12:45:35 +13:00 committed by Andrew Bartlett
parent beff3e6d77
commit 7c1e3f0d82

View File

@ -41,8 +41,8 @@ class MessagingTests(TestCase):
pass
callback_and_context = (callback, None)
msg_type = x.register(callback_and_context)
self.addCleanup(x.deregister, callback_and_context, msg_type)
self.assertTrue(isinstance(msg_type, int))
x.deregister(callback_and_context, msg_type)
def test_all_servers(self):
x = self.get_context()
@ -88,13 +88,21 @@ class MessagingTests(TestCase):
got_ping["count"] += 1
server_ctx.send(src, msg_pong, data)
msg_ping = server_ctx.register((ping_callback, got_ping))
ping_callback_and_context = (ping_callback, got_ping)
msg_ping = server_ctx.register(ping_callback_and_context)
self.addCleanup(server_ctx.deregister,
ping_callback_and_context,
msg_ping)
def pong_callback(got_pong, msg_type, src, data):
got_pong["count"] += 1
client_ctx = self.get_context((0, 2))
msg_pong = client_ctx.register((pong_callback, got_pong))
pong_callback_and_context = (pong_callback, got_pong)
msg_pong = client_ctx.register(pong_callback_and_context)
self.addCleanup(client_ctx.deregister,
pong_callback_and_context,
msg_pong)
# Try both server_id forms (structure and tuple)
client_ctx.send((0, 1), msg_ping, "testing")
@ -130,13 +138,21 @@ class MessagingTests(TestCase):
got_ping["count"] += 1
server_ctx.send(src, msg_pong, data)
msg_ping = server_ctx.register((ping_callback, got_ping))
ping_callback_and_context = (ping_callback, got_ping)
msg_ping = server_ctx.register(ping_callback_and_context)
self.addCleanup(server_ctx.deregister,
ping_callback_and_context,
msg_ping)
def pong_callback(got_pong, msg_type, src, data):
got_pong["count"] += 1
client_ctx = self.get_context((2,))
msg_pong = client_ctx.register((pong_callback, got_pong))
pong_callback_and_context = (pong_callback, got_pong)
msg_pong = client_ctx.register(pong_callback_and_context)
self.addCleanup(client_ctx.deregister,
pong_callback_and_context,
msg_pong)
# Try one and two element tuple forms
client_ctx.send((pid, 1), msg_ping, "testing")