From 8c0baaea5781ec59975786d9439a5c4c46d4a043 Mon Sep 17 00:00:00 2001
From: melanie witt <melwitt@yahoo-inc.com>
Date: Wed, 11 Mar 2015 18:22:28 +0000
Subject: [PATCH] Add a test for the TCPKeepAliveAdapter

Related-Bug: #1430935

Change-Id: Idfea26c8eb6448a4c6adc0f3a916515bd4655c1a
---
 novaclient/tests/unit/test_client.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/novaclient/tests/unit/test_client.py b/novaclient/tests/unit/test_client.py
index 983fa2f10..db4c87d09 100644
--- a/novaclient/tests/unit/test_client.py
+++ b/novaclient/tests/unit/test_client.py
@@ -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")