aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kevi...@apache.org
Subject git commit: Add a test to catch regressions in scheduler_client connect_scheduler.
Date Wed, 21 May 2014 22:29:26 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master b20708852 -> d2ab18213


Add a test to catch regressions in scheduler_client connect_scheduler.

Tested with the previous diff found in https://reviews.apache.org/r/21735/

Bugs closed: AURORA-453

Reviewed at https://reviews.apache.org/r/21739/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/d2ab1821
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/d2ab1821
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/d2ab1821

Branch: refs/heads/master
Commit: d2ab182132fc0c3aa7cd9d0b68774fa660a91da7
Parents: b207088
Author: Joe Smith <yasumoto7@gmail.com>
Authored: Wed May 21 14:34:41 2014 -0700
Committer: Kevin Sweeney <kevints@apache.org>
Committed: Wed May 21 15:29:10 2014 -0700

----------------------------------------------------------------------
 .../python/apache/aurora/client/api/scheduler_client.py |  4 ++--
 src/test/python/apache/aurora/client/api/BUILD          |  1 +
 .../apache/aurora/client/api/test_scheduler_client.py   | 12 ++++++++++++
 3 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d2ab1821/src/main/python/apache/aurora/client/api/scheduler_client.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/api/scheduler_client.py b/src/main/python/apache/aurora/client/api/scheduler_client.py
index c0089f6..df9d7e0 100644
--- a/src/main/python/apache/aurora/client/api/scheduler_client.py
+++ b/src/main/python/apache/aurora/client/api/scheduler_client.py
@@ -84,7 +84,7 @@ class SchedulerClient(object):
     return None
 
   @staticmethod
-  def _connect_scheduler(host, port):
+  def _connect_scheduler(host, port, clock=time):
     transport = THttpClient.THttpClient('http://%s:%s/api' % (host, port))
     protocol = TJSONProtocol.TJSONProtocol(transport)
     schedulerClient = AuroraAdmin.Client(protocol)
@@ -93,7 +93,7 @@ class SchedulerClient(object):
         transport.open()
         return schedulerClient
       except TTransport.TTransportException:
-        time.sleep(SchedulerClient.RETRY_TIMEOUT.as_(Time.SECONDS))
+        clock.sleep(SchedulerClient.RETRY_TIMEOUT.as_(Time.SECONDS))
         continue
       except Exception as e:
         # Monkey-patched proxies, like socks, can generate a proxy error here.

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d2ab1821/src/test/python/apache/aurora/client/api/BUILD
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/BUILD b/src/test/python/apache/aurora/client/api/BUILD
index f0fa58f..56d4093 100644
--- a/src/test/python/apache/aurora/client/api/BUILD
+++ b/src/test/python/apache/aurora/client/api/BUILD
@@ -62,6 +62,7 @@ python_tests(name = 'restarter',
 python_tests(name = 'scheduler_client',
   sources = ['test_scheduler_client.py'],
   dependencies = [
+    pants('3rdparty/python:mock'),
     pants('3rdparty/python:mox'),
     pants('src/main/python/apache/aurora/client/api:scheduler_client'),
     pants('src/main/thrift/org/apache/aurora/gen:py-thrift'),

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d2ab1821/src/test/python/apache/aurora/client/api/test_scheduler_client.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/api/test_scheduler_client.py b/src/test/python/apache/aurora/client/api/test_scheduler_client.py
index e29bae9..e59248f 100644
--- a/src/test/python/apache/aurora/client/api/test_scheduler_client.py
+++ b/src/test/python/apache/aurora/client/api/test_scheduler_client.py
@@ -15,9 +15,12 @@
 #
 
 import inspect
+import time
 import unittest
 
+import mock
 from mox import IgnoreArg, IsA, Mox
+from thrift.transport import THttpClient, TTransport
 from twitter.common.quantity import Amount, Time
 from twitter.common.zookeeper.kazoo_client import TwitterKazooClient
 from twitter.common.zookeeper.serverset.endpoint import ServiceInstance
@@ -339,3 +342,12 @@ class TestZookeeperSchedulerClient(unittest.TestCase):
       assert zk_scheduler_client.url == 'http://%s:%d' % (host, port)
     finally:
       TestZookeeperSchedulerClient.get_scheduler_serverset = original_method
+
+class TestSchedulerClient(unittest.TestCase):
+  @mock.patch('thrift.transport.THttpClient.THttpClient', spec=THttpClient.THttpClient)
+  def test_connect_scheduler(self, MockTHttpClient):
+    MockTHttpClient.return_value.open.side_effect = [TTransport.TTransportException, True]
+    mock_time = mock.Mock(spec=time)
+    scheduler_client.SchedulerClient._connect_scheduler('scheduler.example.com', 1337, mock_time)
+    assert MockTHttpClient.return_value.open.call_count is 2
+    mock_time.sleep.assert_called_once_with(scheduler_client.SchedulerClient.RETRY_TIMEOUT.as_(Time.SECONDS))


Mime
View raw message