<div dir="ltr">On Sun, Aug 4, 2013 at 7:55 PM, Itamar Turner-Trauring <span dir="ltr"><<a href="mailto:itamar@itamarst.org" target="_blank">itamar@itamarst.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On 08/04/2013 10:25 AM, Benjamin BERTRAND wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Hi,<br>
<br>
I'm trying to write a simple gateway to receive messages using a specific protocol and publish/store them using txredis.<br>
I wrote a small example that seems to work.<br>
But the small test I wrote fails:<br>
<br>
$ trial gateway/test<br>
gateway.test.test_example<br>
   GatewayServiceTestCase<br>
     test_messageReceived ...                                            [ERROR]<br>
<br>
==============================<u></u>==============================<u></u>===================<br>
[ERROR]<br>
Traceback (most recent call last):<br>
Failure: twisted.internet.error.<u></u>ConnectionDone: Connection was closed cleanly.<br>
<br>
gateway.test.test_example.<u></u>GatewayServiceTestCase.test_<u></u>messageReceived<br>
------------------------------<u></u>------------------------------<u></u>-------------------<br>
Ran 1 tests in 0.007s<br>
<br>
<br>
As I understand, the connection to the redis server is lost during the test.<br>
I actually managed to get the test to pass by adding some inlineCallbacks decorator to my messageReceived and lineReceived methods.<br>
But I don't really understand why that would be needed.<br>
Could someone explain what is happening?<br>
<br>
</blockquote></div>
I suspect the inlineCallbacks is irrelevant (and not the way to solve this).<br>
<br>
At a guess, what is happening is that something is logging the connection being lost (perhaps the redis library?). Logging errors in a unit test makes trial consider that test to have failed: logging an error suggests something has gone wrong. You can tell trial to expect a specific error to be logged in your test: <a href="https://twistedmatrix.com/documents/current/core/howto/trial.html#auto11" target="_blank">https://twistedmatrix.com/<u></u>documents/current/core/howto/<u></u>trial.html#auto11</a><br>
<br></blockquote><div><br></div><div>I think I understand what is happening.</div><div>In my publish method, I call the redis publish and zadd methods.</div><div>My test checks the message received by the subscriber and closes the connection just after. I don't wait for the deferred return by the zadd method to fire (and get an error).</div>
<div><br></div><div>That's why the inlineCallbacks solves the problem. When I yield on the self.server.dataReceived, I wait for the deferred in the publish methods to fire and everything is clean when I close the connection.</div>
<div><br></div><div>Is there another way to do that?</div><div><br></div></div></div></div>