Permalink
Browse files

Errback on the deferred from startConnection if connection fails

e.g. with connection refused type errors. Also add unit test for this.
  • Loading branch information...
sporsh committed Nov 9, 2012
1 parent 37480eb commit e56dfa7e21581fc7dff70302ee60dfdf6a095fba
Showing with 16 additions and 2 deletions.
  1. +5 −1 carnifex/sshprocess.py
  2. +11 −1 test/integration/test_inductor.py
View
@@ -109,7 +109,11 @@ def connectionLost(reason):
serviceStartedDeferred.called or serviceStartedDeferred.errback(reason)
self._connections[user] = None
- self.endpoint.connect(sshClientFactory)
+ connectionMadeDeferred = self.endpoint.connect(sshClientFactory)
+ @connectionMadeDeferred.addErrback
+ def connectionFailed(failure):
+ serviceStartedDeferred.called or serviceStartedDeferred.callback(failure)
+
return serviceStartedDeferred
def disconnectAll(self):
@@ -2,7 +2,8 @@
from twisted.trial.unittest import TestCase
from carnifex.sshprocess import SSHProcessInductor
from twisted.internet.protocol import ProcessProtocol
-from twisted.internet.error import ProcessTerminated, ProcessDone
+from twisted.internet.error import ProcessTerminated, ProcessDone,\
+ ConnectionRefusedError
from carnifex.localprocess import LocalProcessInductor
from getpass import getpass
from carnifex.ssh.client import TooManyAuthFailures
@@ -107,6 +108,15 @@ def test_authentication_failure(self):
uid=WRONG_USER)
return self.assertFailure(processDeferred, TooManyAuthFailures)
+ def test_connection_refused(self):
+ """Check that connection refused errors are handeled correctly.
+ """
+ from twisted.internet import reactor
+ host, port = 'localhost', 1 # Use a port that is not open for connection
+ self.inductor = SSHProcessInductor(reactor, host, port)
+ deferred = self.inductor.getConnection()
+ return self.assertFailure(deferred, ConnectionRefusedError)
+
def tearDown(self):
inductor = self.inductor
self.inductor = None

0 comments on commit e56dfa7

Please sign in to comment.