r46877 - re #4735 review feedback

glyph-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org
Newsgroups gmane.comp.python.twisted.commits
Message-ID <[email protected]>
Author: glyph
Date: Mon Feb 29 21:11:49 2016
New Revision: 46877

Modified:
   branches/persistent-client-service-4735-5/twisted/application/test/test_internet.py

Log:
re #4735 review feedback

"`_DisconnectFactory.__getattr__` is uncovered" - fixed.

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	Mon Feb 29 21:11:49 2016
@@ -432,11 +432,14 @@
         will trigger building a factory.
 
     @ivar constructedProtocols: a L{list} of protocols constructed.
+
+    @ivar passedFactories: a L{list} of L{IProtocolFactory}; the ones actually
+        passed to the underlying endpoint / i.e. the reactor.
     """
     def __init__(self):
         self.connectQueue = []
         self.constructedProtocols = []
-        self.applicationProtocols = []
+        self.passedFactories = []
 
 
 
@@ -455,6 +458,7 @@
     class ClientTestEndpoint(object):
         def connect(self, factory):
             result = Deferred()
+            info.passedFactories.append(factory)
             @result.addCallback
             def createProtocol(ignored):
                 protocol = factory.buildProtocol(None)
@@ -521,13 +525,24 @@
         nkw.update(clock=Clock())
         nkw.update(kw)
         cq, endpoint = endpointForTesting(fireImmediately=fireImmediately)
+
+        # endpointForTesting is totally generic to any LLPI client that uses
+        # endpoints, and maintains all its state internally; however,
+        # applicationProtocols and applicationFactory are bonus attributes that
+        # are only specifically interesitng to tests that use wrapper
+        # protocols.  For now, set them here, externally.
+
+        applicationProtocols = cq.applicationProtocols = []
+
         class RememberingFactory(Factory, object):
             protocol = protocolType
             def buildProtocol(self, addr):
                 result = super(RememberingFactory, self).buildProtocol(addr)
-                cq.applicationProtocols.append(result)
+                applicationProtocols.append(result)
                 return result
-        factory = RememberingFactory()
+
+        cq.applicationFactory = factory = RememberingFactory()
+
         service = ClientService(endpoint, factory, **nkw)
         def stop():
             service._protocol = None
@@ -550,6 +565,21 @@
         self.assertEqual(len(cq.connectQueue), 1)
 
 
+    def test_startStopFactory(self):
+        """
+        Although somewhat obscure, L{IProtocolFactory} includes both C{doStart}
+        and C{doStop} methods; ensure that when these methods are called on the
+        factory that was passed to the reactor, the factory that was passed
+        from the application receives them.
+        """
+        cq, service = self.makeReconnector()
+        firstAppFactory = cq.applicationFactory
+        self.assertEqual(firstAppFactory.numPorts, 0)
+        firstPassedFactory = cq.passedFactories[0]
+        firstPassedFactory.doStart()
+        self.assertEqual(firstAppFactory.numPorts, 1)
+
+
     def test_stopServiceWhileConnected(self):
         """
         When the service is stopped, no further connect attempts are made.  The
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.