def test_connectionLost_clientClose(self):
'''If connectionLost is called because the client closed the
connection, then this connection has disappeared suddenly.
Consequently, the protocol's terminationDeferred errbacks with
the provided reason, the timeout clock is stopped, and the
session machine learns about the lost connection.
'''
erroredDeferred = self.protocol.terminationDeferred
def trapConnectionDone(failure):
failure.trap(error.ConnectionDone)
erroredDeferred.addErrback(trapConnectionDone)
self.protocol.connectionLost(connectionDone)
self.assertEqual(self.timeoutClockRecorder.stopCalls, 1)
self.assertEqual(self.sessionMachineRecorder.connectionsLostReasons,
[connectionDone])
self.assertIsNone(self.protocol.sessionMachine)
return erroredDeferred
python类connectionDone()的实例源码
def connectionLost(self, reason=connectionDone):
self.log.failure('SSE connection lost', reason, LogLevel.warn)
self.setTimeout(None) # Cancel the timeout
for d in list(self._waiting):
d.callback(None)
self._waiting = []
def loseConnection(self):
self.proto.connectionLost(protocol.connectionDone)
def connectionLost(self, reason=protocol.connectionDone):
"""We are no longer connected"""
self.setTimeout(None)
self.mailFile = None
def connectionLost(self, reason=protocol.connectionDone):
self.factory.remove_cb(self)
def connectionLost(self, reason=protocol.connectionDone):
self.factory.remove_cb(self)
def connectionLost(self, reason=connectionDone):
reactor.stop()
def loseConnection(self):
self.proto.connectionLost(protocol.connectionDone)
def connectionLost(self, reason=protocol.connectionDone):
"""We are no longer connected"""
self.setTimeout(None)
self.mailFile = None
def connectionLost(self, reason=connectionDone):
"""
Overridden function that is called when the connected port is disconnected. Simply sets the
self.is_port_attached flag to False so that we know we have been disconnected from the target embedded
board.
:param reason: Reason for disconnection. Of Twisted failure type.
:return:
"""
self.is_port_attached = False
LineReceiver.connectionLost(self, reason)
def connectionLost(self, reason=connectionDone):
log.info("Lost stream for user {user} room {room}",
user=self.user.github_username, room=self.gitter_room_name)
self.stream_response = None
if not self.destroyed:
gitter_stream_limit.schedule(self.start_stream)
def connectionLost(self, reason=connectionDone):
if not self.finished.called:
self.finished.callback(self.content.getvalue())
def connectionLost(self, reason=protocol.connectionDone):
if self.wrapper.on_disconnect:
reactor.callLater(0.0, self.wrapper.on_disconnect, self.wrapper)
return irc.IRCClient.connectionLost(self, reason)
def connectionLost(self, reason=protocol.connectionDone):
"""Callback invoked on connection lost."""
_LOGGER.info('connection lost')
def loseConnection(self):
self.proto.connectionLost(protocol.connectionDone)
def connectionLost(self, reason=protocol.connectionDone):
"""
We are no longer connected
"""
self.setTimeout(None)
self.mailFile = None
def test_beginRequest_finishedNotifier_forwards_failures(self):
'''Beginning a request retrieves a Deferred from that request that
forwards failures to the protocol's connectionLost.
'''
self.protocol.request = self.request
self.protocol.beginRequest()
reason = connectionDone
def assertConnectionLostCalled(ignored):
recordedExceptions = [
reason.value for reason in
self.sessionMachineRecorder.connectionsLostReasons]
self.assertEqual(recordedExceptions, [reason.value])
finishedNotifier = self.protocol.finishedNotifier
finishedNotifier.addCallback(assertConnectionLostCalled)
def trapConnectionDone(failure):
failure.trap(error.ConnectionDone)
terminationDeferred = self.protocol.terminationDeferred
terminationDeferred.addErrback(trapConnectionDone)
self.request.processingFailed(reason)
return DeferredList([finishedNotifier, terminationDeferred])
def test_completeConnectionLost(self):
'''Completing a lost connection calls the wrapped protocol's
connectionLost.
'''
self.request.transport = StringTransport()
self.protocol.establishConnection(self.request)
self.protocol.completeConnectionLost(connectionDone)
self.assertEqual(self.connectionsLost, [connectionDone])
def test_timedOutCallback(self):
'''The termination deferred's callback sets disconnecting and calls
connectionLost. Setting disconnecting avoids errbacking the
deferred that's just been fired!
'''
terminationDeferred = self.protocol.terminationDeferred
def assertConnectionLostCalled(ignored):
self.assertTrue(self.protocol.disconnecting)
self.assertEqual(self.sessionMachineRecorder.connectionsLost,
connectionDone)
terminationDeferred.callback(P.TimeoutClock.EXPIRED)
return terminationDeferred
def test_sessionClosed_on_errback(self):
'''Errbacking the protocol's terminationDeferred removes the session
from the house.
'''
self.test_attachToSession_new_session()
self.protocol.terminationDeferred.errback(connectionDone)
self.assertNotIn(self.sessionID, self.sessions.sessions)
return self.protocol.terminationDeferred
def connectionLost(self, reason=protocol.connectionDone):
'''The connection has been lost; clean up any request and clean up the
protocol.
'''
def _dropRequest(self, reason=protocol.connectionDone):
self.requestSession.request = None
def _closeProtocol(self, reason=protocol.connectionDone):
self.requestSession.completeConnectionLost(reason)
self.requestSession = None
def _timedOut(self, reason=protocol.connectionDone):
if isinstance(reason.value, error.ConnectionDone):
reason = failure.Failure(SessionTimeout())
self.requestSession.completeConnectionLost(reason=reason)
self.requestSession = None
def connectionLost(self, reason=protocol.connectionDone):
if not self.disconnecting:
self.terminationDeferred.errback(reason)
self.timeoutClock.stop()
self.sessionMachine.connectionLost(reason)
self.sessionMachine = None
def connectionLost(self, reason=protocol.connectionDone):
self.stdOut.seek(0)
self.stdErr.seek(0)
if reason.type is error.ConnectionDone:
# Success
code = 0
else:
code = reason.value.exitCode
self.factory.done.callback((self.stdOut, self.stdErr, code))
def connectionLost(self, reason=connectionDone):
self.session.commit()
self.session.close()
self.update_tick(dot='-')
def test_onConnectionLost_fires_when_connection_is_lost(self):
protocol = common.RPCProtocol()
protocol.makeConnection(StringTransport())
protocol.connectionLost(connectionDone)
self.assertThat(protocol.onConnectionLost, IsFiredDeferred())
def connectionLost(self, reason=connectionDone):
logger.info('%s disconnected. remainder connected: %s',
self.transport.getPeer().host,
str(self.factory.connections)) # , reason
try:
self.factory.peer_connections.remove(self)
if self.factory.connections == 0:
reactor.callLater(60, self.factory.connect_peers)
# FIXME: unsafe access to synced_peers
if self in self.factory.synced_peers:
self.factory.synced_peers.remove(self)
except Exception:
pass