def test_wb_connect_after_timeout(self): """ Test an odd error scenario. If the zookeeper client succeeds in connecting after a timeout, the connection should be closed, as the connect deferred has already fired. """ mock_client = self.mocker.patch(self.client) mock_client.close() def close_state(): # Ensure the client state variable is correct after the close call. self.client.connected = False self.mocker.call(close_state) self.mocker.replay() task = DelayedCall(1, lambda: 1, None, None, None, None) task.called = True d = Deferred() d.errback(ConnectionTimeoutException()) self.client._cb_connected( task, d, None, zookeeper.CONNECTED_STATE, "/") self.failUnlessFailure(d, ConnectionTimeoutException) return d
def test_wb_reconnect_after_timeout_and_close(self): """ Another odd error scenario, if a client instance has has connect and closed methods invoked in succession multiple times, and a previous callback connect timeouts, the callback of a previous connect can be invoked by a subsequent connect, with a CONNECTING_STATE. Verify this does not attempt to invoke the connect deferred again. """ d = Deferred() d.callback(True) task = DelayedCall(1, lambda: 1, None, None, None, None) task.called = True self.assertEqual( self.client._cb_connected( task, d, None, zookeeper.CONNECTING_STATE, ""), None)