1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

pymessaging: add single element tupple form of the server_id

This avoids the python code needing to call getpid() internally,
while declaring a stable task_id.

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
This commit is contained in:
Gary Lockyer 2017-03-16 16:26:01 +13:00 committed by Andrew Bartlett
parent 8c75d9fc73
commit 16e9448174
2 changed files with 50 additions and 1 deletions

View File

@ -25,6 +25,7 @@ import time
from samba.ndr import ndr_print
from samba.dcerpc import server_id
import random
import os
class MessagingTests(TestCase):
@ -109,3 +110,44 @@ class MessagingTests(TestCase):
self.assertEqual(got_ping["count"], 2)
self.assertEqual(got_pong["count"], 2)
def test_pid_defaulting(self):
got_ping = {"count": 0}
got_pong = {"count": 0}
timeout = False
msg_pong = 0
msg_ping = 0
pid = os.getpid()
server_ctx = self.get_context((pid, 1))
def ping_callback(got_ping, msg_type, src, data):
got_ping["count"] += 1
server_ctx.send(src, msg_pong, data)
msg_ping = server_ctx.register((ping_callback, got_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))
# Try one and two element tuple forms
client_ctx.send((pid, 1), msg_ping, "testing")
client_ctx.send((1,), msg_ping, "testing2")
start_time = time.time()
# NOTE WELL: If debugging this with GDB, then the timeout will
# fire while you are trying to understand it.
while (got_ping["count"] < 2 or got_pong["count"] < 2) and not timeout:
client_ctx.loop_once(0.1)
server_ctx.loop_once(0.1)
if time.time() - start_time > 1:
timeout = True
self.assertEqual(got_ping["count"], 2)
self.assertEqual(got_pong["count"], 2)

View File

@ -62,13 +62,20 @@ static bool server_id_from_py(PyObject *object, struct server_id *server_id)
server_id->task_id = task_id;
server_id->vnn = vnn;
return true;
} else {
} else if (PyTuple_Size(object) == 2) {
unsigned long long pid;
int task_id;
if (!PyArg_ParseTuple(object, "KI", &pid, &task_id))
return false;
*server_id = cluster_id(pid, task_id);
return true;
} else {
unsigned long long pid = getpid();
int task_id;
if (!PyArg_ParseTuple(object, "I", &task_id))
return false;
*server_id = cluster_id(pid, task_id);
return true;
}
}