[Twisted-Python] Re: [Twisted-commits] r15259 - Try again. Merge trial-deferred-logic
Jean-Paul Calderone
exarkun at divmod.com
Wed Nov 30 07:13:35 MST 2005
On Tue, 29 Nov 2005 23:43:31 -0700, Jonathan Lange <jml at wolfwood.twistedmatrix.com> wrote:
>Author: jml
>Date: Tue Nov 29 23:43:31 2005
>New Revision: 15259
>
>Modified:
> trunk/twisted/mail/test/test_mail.py
> trunk/twisted/test/test_ftp.py
> trunk/twisted/test/test_ssl.py
> trunk/twisted/test/test_tcp.py
> trunk/twisted/trial/reporter.py
> trunk/twisted/trial/runner.py
> trunk/twisted/trial/test/detests.py
> trunk/twisted/trial/test/test_deferred.py
> trunk/twisted/trial/test/test_failure_formatting.py
> trunk/twisted/trial/test/test_keyboard.py
> trunk/twisted/trial/test/timeouts.py
> trunk/twisted/trial/unittest.py
> trunk/twisted/trial/util.py
> trunk/twisted/web/test/test_webclient.py
>Log:
>Try again. Merge trial-deferred-logic
>
>@@ -907,17 +900,22 @@
> self.client.transport.loseConnection()
> return self.p.stopListening()
>
>+ def _delayDeferred(self, time, arg=None):
>+ from twisted.internet import reactor
>+ d = defer.Deferred()
>+ reactor.callLater(time, d.callback, arg)
>+ return d
>+
> def testNoNotification(self):
> client = self.client
> f = self.f
> client.transport.write("hello")
> w = client.transport.write
> client.transport.loseWriteConnection()
>- reactor.iterate()
>- reactor.iterate()
>- reactor.iterate()
>- self.assertEquals(f.protocol.data, "hello")
>- self.assertEquals(f.protocol.closed, True)
>+ d = self._delayDeferred(0.2, f.protocol)
>+ d.addCallback(lambda x : self.assertEqual(f.protocol.data, 'hello'))
>+ d.addCallback(lambda x : self.assertEqual(f.protocol.closed, True))
>+ return d
>
> def testShutdownException(self):
> client = self.client
The above hunk is pretty sketchy. The real solution is to give the protocol a Deferred which it fires at whatever point it would have set its closed attribute to True. As it stands, the test has a race and I can guarantee it will be going the wrong way quite frequently.
Jean-Paul
More information about the Twisted-Python
mailing list