ϪfbdZddlZddlmZmZddlmZddlmZGddZ Gdd eZ y) z& Test code for basic Factory classes. N)ProtocolReconnectingClientFactory)Clock)TestCaseceZdZdZdZdZy) FakeConnectorzP A fake connector class, to be used to mock connections failed or lost. cyNselfs =/usr/lib/python3/dist-packages/twisted/test/test_factories.pystopConnectingzFakeConnector.stopConnecting cyr r r s rconnectzFakeConnector.connectrrN)__name__ __module__ __qualname____doc__rrr rrrrs  rrc4eZdZdZdZdZdZdZdZdZ y) ReconnectingFactoryTestsz1 Tests for L{ReconnectingClientFactory}. cGdd}t}t|_|jd|j |j |d|j |jy)z If a L{ReconnectingClientFactory} has C{stopTrying} called while it is connected, it does not subsequently attempt to reconnect if the connection is later lost. ceZdZdZdZy)QReconnectingFactoryTests.test_stopTryingWhenConnected..NoConnectConnectorctd)Nz%Shouldn't be called, we're connected. RuntimeErrorr s rrz`ReconnectingFactoryTests.test_stopTryingWhenConnected..NoConnectConnector.stopConnecting)s"#JKKrctd)NzShouldn't be reconnecting.rr s rrzYReconnectingFactoryTests.test_stopTryingWhenConnected..NoConnectConnector.connect,s"#?@@rN)rrrrrr rrNoConnectConnectorr(s L Arr!N)rrprotocol buildProtocol stopTryingclientConnectionLost assertFalsecontinueTrying)r r!cs rtest_stopTryingWhenConnectedz5ReconnectingFactoryTests.test_stopTryingWhenConnected!s\ A A & '    13T: ))*rc.Gfddt}tt_|_j |j jj|j jjy)z Calling stopTrying on a L{ReconnectingClientFactory} doesn't attempt a retry on any active connector. c"eZdZdZfdZdZy)[ReconnectingFactoryTests.test_stopTryingDoesNotReconnect..FactoryAwareFakeConnectorFc*j|dy)z Behave as though an ongoing connection attempt has now failed, and notify the factory of this. N)clientConnectionFailed)r fs rrzjReconnectingFactoryTests.test_stopTryingDoesNotReconnect..FactoryAwareFakeConnector.stopConnectingAs ((t4rcd|_y)z| Record an attempt to reconnect, since this is what we are trying to avoid. TN)attemptedRetryr s rrzcReconnectingFactoryTests.test_stopTryingDoesNotReconnect..FactoryAwareFakeConnector.connectHs '+#rN)rrrr1rr)r/srFactoryAwareFakeConnectorr,>s"N 5 +rr2N) rrrclock connectorr$r&r1getDelayedCalls)r r2r/s @rtest_stopTryingDoesNotReconnectz8ReconnectingFactoryTests.test_stopTryingDoesNotReconnect8sl  +  +" & ''01   334 0023rct}tjtj|}|j |j |j y)z A L{ReconnectingClientFactory} which hasn't been used for anything can be pickled and unpickled and end up with the same state. N)rpickleloadsdumps assertEqual__dict__)r original reconstituteds rtest_serializeUnusedz-ReconnectingFactoryTests.test_serializeUnused[s? -. V\\(%;<  **M,B,BCrct}t}||_tjtj |}|j |jy)z The clock attribute of L{ReconnectingClientFactory} is not serialized, and the restored value sets it to the default value, the reactor. N)rrr3r8r9r: assertIsNone)r r3r=r>s rtest_serializeWithClockz0ReconnectingFactoryTests.test_serializeWithClockdsE ,. V\\(%;<  ---.rct}|jtd|j|jt j |}t j|}|j|j|j|j|j|jd|j|j|j|j|j y)z A L{ReconnectingClientFactory} which is unpickled does not have an L{IConnector} and has its reconnecting timing parameters reset to their initial values. Nr)rr.r addCleanupr$r8r:r9rAr4_callIDr;retriesdelay initialDelay assertTruer')r factory serialized unserializeds r$test_deserializationResetsParametersz=ReconnectingFactoryTests.test_deserializationResetsParametersos ,-&&}= **+\\'* ||J/  ,001 ,../ --q1 ++W-A-AB  334rct}t}||_|jt d|j t |jdy)z The clock used by L{ReconnectingClientFactory} can be parametrized, so that one can cleanly test reconnections. N)rrr3r%rr;lencalls)r r3rJs rtest_parametrizedClockz/ReconnectingFactoryTests.test_parametrizedClocksE +- $$]_d; U[[)1-rN) rrrrr)r6r?rBrMrRr rrrrs'+.!4FD /5$ .rr) rr8twisted.internet.protocolrrtwisted.internet.taskrtwisted.trial.unittestrrrr rrrVs0 I'+   o.xo.r