[Twisted-Python] How to best log server/client interactions from a test?
dan at wingu.com
Mon Jul 16 09:40:51 EDT 2012
To be clear: my current interest is really just doing this during unit tests/ongoing development (e.g. not diagnosing prod issues, where Wireshark would make plenty of sense). So something integrated into Twisted feels natural.
That said, is the unit test pattern I'm seeing in the mail/test/test_imap.py module atypical? Most of the doc'd examples for trial don't seem to be using loopbackTCP, so much as directly writing to lineReceived or something similar. It's only because these tests are doing end-to-end things, by way of constructing both an IMAP server and client, and hooking them up, that I'm in this situation.
On Jul 13, 2012, at 6:21 PM, Glyph wrote:
> On Jul 12, 2012, at 1:31 PM, Dan Milstein <dan at wingu.com> wrote:
>> 'lo all,
>> I've been doing some work with the twisted.mail.imap4 module, and its associated unit tests (in order to learn the code more, I'm tackling a few of the outstanding tickets).
>> When running those tests, I'd often like to log all the server/client interaction. I managed to do so by way of hacking the code in twisted.protocols.loopback, but that feels pretty wrong. What's a good way to get all the interaction logged?
>> To be more specific, the tests in question (e.g. test_imap.NewFetchTestCase), do a lot of:
>> d = loopback.loopbackTCP(self.server, self.client, noisy=False)
>> d.addCallback(lambda x : self.assertEqual(self.result, self.expected))
>> return d
>> What's a Good Way to get all the traffic going over that loopback logged? Setting noisy to True merely gets it to log some protocol startup/teardown-type messages.
>> Or: given that I've figured out how to hack loopback.lookupbackTCP, if there's general utility, I can certainly add a keyword arg to trigger logging of all messages, e.g. logAll=False (I'm trying to find something which feels meaningfully different from 'noisy', because it would seem Very Wrong Indeed to make noisy suddenly produce vastly more log output). Is that something people might be interested in?
> If you're interested in logging at the TCP connection level, have you considered moving this out of your Twisted process entirely and using some tool like Wireshark? You could build something yourself by interposing transport objects that dump their data, but you'd have to build your own toolchain (command line tools, GUIs, etc) for actually examining the output, whereas existing protocol analysis tools would just do that for you.
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python