From ecddac571c28c7fb3c2cffbe3da1441e993472a3 Mon Sep 17 00:00:00 2001
From: Nikolay Sobolevskiy <nsobolevsky@mirantis.com>
Date: Mon, 19 Aug 2013 11:48:03 +0400
Subject: [PATCH] Use FakeLoopingCall instead of the real one

Decrease the execution time in brick's tests.

Change-Id: Idef19e91f593c2c276015d5bf9f9cc85cd6094ad
---
 cinder/tests/brick/test_brick_connector.py | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/cinder/tests/brick/test_brick_connector.py b/cinder/tests/brick/test_brick_connector.py
index 5ec9e657e..fe8d44b3d 100644
--- a/cinder/tests/brick/test_brick_connector.py
+++ b/cinder/tests/brick/test_brick_connector.py
@@ -26,6 +26,7 @@ from cinder.brick.initiator import host_driver
 from cinder.brick.initiator import linuxfc
 from cinder.brick.initiator import linuxscsi
 from cinder.openstack.common import log as logging
+from cinder.openstack.common import loopingcall
 from cinder.openstack.common import processutils as putils
 from cinder import test
 
@@ -330,6 +331,30 @@ class FibreChannelConnectorTestCase(ConnectorTestCase):
                           connection_info['data'])
 
 
+class FakeFixedIntervalLoopingCall(object):
+    def __init__(self, f=None, *args, **kw):
+        self.args = args
+        self.kw = kw
+        self.f = f
+        self._stop = False
+
+    def stop(self):
+        self._stop = True
+
+    def wait(self):
+        return self
+
+    def start(self, interval, initial_delay=None):
+        while not self._stop:
+            try:
+                self.f(*self.args, **self.kw)
+            except loopingcall.LoopingCallDone:
+                return self
+            except Exception:
+                LOG.exception(_('in fixed duration looping call'))
+                raise
+
+
 class AoEConnectorTestCase(ConnectorTestCase):
     """Test cases for AoE initiator class."""
     def setUp(self):
@@ -338,6 +363,9 @@ class AoEConnectorTestCase(ConnectorTestCase):
         self.connector = connector.AoEConnector()
         self.connection_properties = {'target_shelf': 'fake_shelf',
                                       'target_lun': 'fake_lun'}
+        self.stubs.Set(loopingcall,
+                       'FixedIntervalLoopingCall',
+                       FakeFixedIntervalLoopingCall)
 
     def tearDown(self):
         self.mox.VerifyAll()
-- 
2.45.2