r46911 - test cases for starting while stopping and stopped
glyph-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org
| Newsgroups | gmane.comp.python.twisted.commits |
|---|---|
| Message-ID | <[email protected]> |
Author: glyph
Date: Fri Mar 4 18:15:18 2016
New Revision: 46911
Modified:
branches/persistent-client-service-4735-5/twisted/application/test/test_internet.py
Log:
test cases for starting while stopping and stopped
Modified: branches/persistent-client-service-4735-5/twisted/application/test/test_internet.py
==============================================================================
--- branches/persistent-client-service-4735-5/twisted/application/test/test_internet.py (original)
+++ branches/persistent-client-service-4735-5/twisted/application/test/test_internet.py Fri Mar 4 18:15:18 2016
@@ -602,6 +602,51 @@
self.successResultOf(d)
+ def test_startServiceWhileStopping(self):
+ """
+ When L{ClientService} is stopping - that is,
+ L{ClientService.stopService} has been called, but the L{Deferred} it
+ returns has not fired yet - calling L{startService} will cause a new
+ connection to be made, and new calls to L{whenConnected} to succeed.
+ """
+ cq, service = self.makeReconnector(fireImmediately=False)
+ cq.connectQueue[0].callback(None)
+ first = cq.constructedProtocols[0]
+ stopped = service.stopService()
+ self.assertNoResult(stopped)
+ nextProtocol = service.whenConnected()
+ self.assertNoResult(nextProtocol)
+ service.startService()
+ self.assertNoResult(nextProtocol)
+ self.assertNoResult(stopped)
+ self.assertEqual(first.transport.disconnecting, True)
+ cq.connectQueue[1].callback(None)
+ self.assertEqual(len(cq.constructedProtocols), 2)
+ self.assertIdentical(self.successResultOf(nextProtocol),
+ cq.applicationProtocols[1])
+ secondStopped = service.stopService()
+ first.connectionLost(Failure(Exception()))
+ self.successResultOf(stopped)
+ self.assertNoResult(secondStopped)
+
+
+ def test_startServiceWhileStopped(self):
+ """
+ When L{ClientService} is stopped - that is,
+ L{ClientService.stopService} has been called and the L{Deferred} it
+ returns has fired - calling L{startService} will cause a new connection
+ to be made, and new calls to L{whenConnected} to succeed.
+ """
+ cq, service = self.makeReconnector(fireImmediately=False)
+ stopped = service.stopService()
+ self.successResultOf(stopped)
+ self.failureResultOf(service.whenConnected(), CancelledError)
+ service.startService()
+ cq.connectQueue[-1].callback(None)
+ self.assertIdentical(cq.applicationProtocols[-1],
+ self.successResultOf(service.whenConnected()))
+
+
def test_interfacesForTransport(self):
"""
If the protocol objects returned by the factory given to