Creating local method call+reply pair, causes assertion failures

Daniel P. Berrange dan at berrange.com
Mon Nov 28 02:12:28 PST 2005


I'm doing some work on the Perl APIs to make it much easier to write
unit tests for exported objects / services. The basic problem I'm
aiming to solve, is to make it possible to test a service without 
having to connect it to a real live bus. Using a live bus exposes
tests to a whole host of external variables & complexity which are 
very undesirable in a unit-testing scenario. 

To achieve this goal I've created an object (MockConnection) which is 
basically a very simple in-memory loopback connection. This lets one 
connect a instance of Net::DBus::RemoteObject directly to a local 
instance of Net::DBus::Object and vica-verca. This all works really
rather well & has significantly simplified the existing test cases
I've got & made it much simpler to create more tests for some of the
more complex object/service interactions.

The problem is that when run against a version of libdbus which has 
assertion checking enabled, the code fails when creating method reply 
messages, violating the check on reply serial:

  3522: arguments to dbus_message_set_reply_serial() were incorrect, assertion "reply_serial != 0" failed in file dbus-message.c line 405.
  This is normally a bug in some application using the D-BUS library.

The sequence is that a 'method call' message is created, body filled
in per the app being tested, it is then sent through the 'in memory' 
loopback, the test stub then creates a 'method reply' message & this
sent back through the loppback connection. 

So obviously, since the message never actually gets serialized onto 
the real DBus connection transport, the method call never gets a
non-zero serial number allocated, and thus creating the method reply
causes the assertion failure. The only API for setting the serial is 
'_dbus_message_set_serial' in dbus-message-internal.h, which isn't 
available to application code. 

I've puzzled over this problem for a while now & can't find a decent
solution yet. The only way I can trigger the code to set the message
serial, is to actually send the message over the connection, but as
noted earlier, the whole point of this exercise is to avoid creating
a real connection. I really don't want to have to create a abstract 
layer around the dbus_message object, just to avoid this assertion 
check, but I'm running out of options. Has anyone got any thoughts ?

Regards,
Dan.
-- 
|=-            GPG key: http://www.berrange.com/~dan/gpgkey.txt       -=|
|=-       Perl modules: http://search.cpan.org/~danberr/              -=|
|=-           Projects: http://freshmeat.net/~danielpb/               -=|
|=-   berrange at redhat.com  -  Daniel Berrange  -  dan at berrange.com    -=|
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/dbus/attachments/20051128/69c5f060/attachment.pgp


More information about the dbus mailing list