Add a test for the TCPKeepAliveAdapter

Related-Bug: #1430935

Change-Id: Idfea26c8eb6448a4c6adc0f3a916515bd4655c1a
This commit is contained in:
melanie witt 2015-03-11 18:22:28 +00:00
parent 689a884e18
commit 8c0baaea57
1 changed files with 19 additions and 0 deletions

View File

@ -16,6 +16,7 @@
import json
import logging
import socket
import fixtures
import mock
@ -27,6 +28,24 @@ from novaclient.tests.unit import utils
import novaclient.v2.client
class TCPKeepAliveAdapterTest(utils.TestCase):
@mock.patch.object(requests.adapters.HTTPAdapter, 'init_poolmanager')
def test_init_poolmanager(self, mock_init_poolmgr):
adapter = novaclient.client.TCPKeepAliveAdapter()
kwargs = {}
adapter.init_poolmanager(**kwargs)
if requests.__version__ >= '2.4.1':
kwargs.setdefault('socket_options', [
(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1),
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
])
# NOTE(melwitt): This is called twice because
# HTTPAdapter.__init__ calls it first.
self.assertEqual(2, mock_init_poolmgr.call_count)
mock_init_poolmgr.assert_called_with(**kwargs)
class ClientConnectionPoolTest(utils.TestCase):
@mock.patch("novaclient.client.TCPKeepAliveAdapter")