[ARVADOS] updated: af03a10a8adc27a91f1483c2ee976b2023b14aa6

git at public.curoverse.com git at public.curoverse.com
Thu Aug 27 14:03:47 EDT 2015


Summary of changes:
 sdk/python/arvados/__init__.py       |  28 ++++++++--
 sdk/python/tests/test_init.py        | 105 +++++++++++++++++++++++++++++++++--
 sdk/python/tests/test_init_psuedo.py |  39 -------------
 3 files changed, 124 insertions(+), 48 deletions(-)
 delete mode 100644 sdk/python/tests/test_init_psuedo.py

       via  af03a10a8adc27a91f1483c2ee976b2023b14aa6 (commit)
      from  6ca562b6cf88f66bb4a36f357a55caacc0bc8be1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit af03a10a8adc27a91f1483c2ee976b2023b14aa6
Author: Bryan Cosca <bcosc at curoverse.com>
Date:   Thu Aug 27 14:03:39 2015 -0400

    flailing looking for mock_keep_responses

diff --git a/sdk/python/arvados/__init__.py b/sdk/python/arvados/__init__.py
index 02900dd..fc701c0 100644
--- a/sdk/python/arvados/__init__.py
+++ b/sdk/python/arvados/__init__.py
@@ -111,8 +111,11 @@ def current_task(api_client=None, num_retries=None):
     current_task_retry_loop = RetryLoop(num_retries=num_retries, backoff_start=0)
     for tries_left in current_task_retry_loop:
     	try:
+            print "Trying api call"
     	    result = api_client.job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
+            print result
     	except errors.ApiError as error:
+            print error
             if not retry.check_http_response_success(error.resp.status):
                 if retry.check_http_response_success(error.resp.status) == False:
                     print "Non-retryable ApiError raised, logging error: {}".format(error)
@@ -121,10 +124,27 @@ def current_task(api_client=None, num_retries=None):
                 else:
                     if tries_left > 0:
                         print "Retrying with {} tries left".format(tries_left)
+                    else:
+                        print "No more retries left (api)"
+                        raise
+        except errors.HttpError as error:
+            print "HttpError raised"
+            if not retry.check_http_response_success(error.status_code):
+                if retry.check_http_response_success(error.status_code) == False:
+                    print "False retry code"
+                    output_retry_loop.save_result(error)
+                else:
+                    if tries_left > 0:
+                        print "Retrying with {} tries left".format(tries_left+1)
+                    else:
+                        print "No more retries left (http)"
+                        raise
     	else:
+            print "Task_set_output saved?"
     	    current_task_retry_loop.save_result(result)
     if current_task_retry_loop.success():
-        result = UserDict.UserDict(result)
+        print "Current_task_retry_loop succeeded"
+        result = UserDict.UserDict(current_task_retry_loop.last_result())
         result.set_output = types.MethodType(task_set_output, result)
         result.tmpdir = os.environ['TASK_WORK']
         _current_task = result
@@ -147,9 +167,9 @@ def current_job(api_client=None, num_retries=None):
 
     current_job_retry_loop = RetryLoop(num_retries=num_retries, backoff_start=0)
     for tries_left in current_job_retry_loop:
-	try:
-	    result = api_client.jobs().get(uuid=os.environ['JOB_UUID']).execute()
-    except errors.ApiError as error:
+    	try:
+    	    result = api_client.jobs().get(uuid=os.environ['JOB_UUID']).execute()
+        except errors.ApiError as error:
             if not retry.check_http_response_success(error.resp.status):
                 if retry.check_http_response_success(error.resp.status) == False:
                     print "Non-retryable ApiError raised, logging error: {}".format(error)
diff --git a/sdk/python/tests/test_init.py b/sdk/python/tests/test_init.py
index 5d23915..6b5da77 100644
--- a/sdk/python/tests/test_init.py
+++ b/sdk/python/tests/test_init.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python   
+#!/usr/bin/env python
 
 import mock
 import os
@@ -14,7 +14,7 @@ from arvados_testutil import queue_with
 from arvados_testutil import mock_responses
 
 @tutil.skip_sleep
-class TaskSetOutputTestCase(unittest.TestCase, tutil.ApiClientMock):
+class TaskSetOutputTestCase():#unittest.TestCase, tutil.ApiClientMock):
     def mock_call_update(self, api_mock, code, body):
         self._mock_api_call(api_mock, code, body)
 
@@ -32,16 +32,16 @@ class TaskSetOutputTestCase(unittest.TestCase, tutil.ApiClientMock):
     def test_mock_retry_until_break(self,code=500):
         api_client = self.api_client_mock(code)
         with self.assertRaises(arvados.errors.ApiError) as err_check:
-            arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)
+            arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=1)
 
     def test_mock_success(self,code=200):
         api_client = self.api_client_mock(code)
-        arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)
+        arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=1)
 
     def test_mock_fail(self,code=400):
         api_client = self.api_client_mock(code)
         with self.assertRaises(arvados.errors.ApiError) as err_check:
-            arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)
+            arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=1)
 
     def test_mock_retry_success(self):
         api_client = mock.MagicMock()
@@ -100,3 +100,98 @@ class TaskSetOutputTestCase(unittest.TestCase, tutil.ApiClientMock):
         with self.assertRaises(arvados.errors.ApiError) as err_check:
             arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)
 
+
+ at tutil.skip_sleep
+class CurrentTaskTestCase(unittest.TestCase, tutil.ApiClientMock):
+
+    os.environ['TASK_UUID'] = 'zzzzz-zzzzz-zzzzzzzzzzzzzzz'
+    os.environ['TASK_WORK'] = '.'
+
+#    def mock_call_update(self, api_mock, code, body):
+#        self._mock_api_call(api_mock, code, body)
+
+#    def api_client_mock(self, status=200):
+#        api_client = super(CurrentTaskTestCase, self).api_client_mock()
+#        self.mock_call_update(api_client.job_tasks().get, status, 'foo_file')
+#        return api_client
+
+    def test_mock_lol_retry_until_break(self):
+        api_client = mock.MagicMock()
+        #api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
+        with tutil.mock_keep_responses('', 400), self.assertRaises(arvados.errors.ApiError) as err_check:
+            arvados.current_task(api_client=api_client,num_retries=0)
+
+    def test_mock_lol_success(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(200), "{}")]
+        arvados.current_task(api_client=api_client,num_retries=0)        
+
+    def test_mock_lol_fail(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(400), "{}")]
+        with self.assertRaises(arvados.errors.ApiError) as err_check:
+            arvados.current_task(api_client=api_client,num_retries=0)
+
+    def test_mock_lol_success(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(400), "{}")]
+        with self.assertRaises(arvados.errors.ApiError) as err_check:
+            arvados.current_task(api_client=api_client,num_retries=0)
+
+    def test_mock_retry_lol_success(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            tutil.fake_httplib2_response(200)]
+        arvados.current_task(api_client=api_client,num_retries=2)
+
+    def test_mock_retry_lol_fail(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(404), "{}")]
+        with self.assertRaises(arvados.errors.ApiError) as err_check:
+            arvados.current_task(api_client=api_client,num_retries=2)
+
+    def test_mock_retry_lol_retry(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
+        with self.assertRaises(arvados.errors.ApiError) as err_check:
+            arvados.current_task(api_client=api_client,num_retries=2)
+
+    def test_mock_retry_success_lol_retry(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            tutil.fake_httplib2_response(200),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
+        arvados.current_task(api_client=api_client,num_retries=2)
+
+    def test_mock_retry_fail_lol_retry(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(400), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
+        with self.assertRaises(arvados.errors.ApiError) as err_check:
+            arvados.current_task(api_client=api_client,num_retries=2)
+
+    def test_mock_success_retry_lol_retry(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().get().execute.side_effect = [tutil.fake_httplib2_response(200),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}")]
+        arvados.current_task(api_client=api_client,num_retries=2)
+
+    def test_mock_retry_retry_lol_success(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            tutil.fake_httplib2_response(200)]
+        arvados.current_task(api_client=api_client,num_retries=2)
+
+    def test_mock_retry_retry_lol_fail(self):
+        api_client = mock.MagicMock()
+        api_client.job_tasks().get().execute.side_effect = [arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(500), "{}"),
+                                                            arvados.errors.ApiError(tutil.fake_httplib2_response(400), "{}")]
+        with self.assertRaises(arvados.errors.ApiError) as err_check:
+            arvados.current_task(api_client=api_client,num_retries=2)
diff --git a/sdk/python/tests/test_init_psuedo.py b/sdk/python/tests/test_init_psuedo.py
deleted file mode 100644
index 8c989cf..0000000
--- a/sdk/python/tests/test_init_psuedo.py
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/usr/bin/env python   
-
-import mock
-import os
-import unittest
-import hashlib
-
-import arvados
-import arvados.collection
-import arvados_testutil as tutil
-import run_test_server
-from arvados_testutil import FakeCurl
-from arvados_testutil import queue_with
-from arvados_testutil import mock_responses
-
- at tutil.skip_sleep
-class SDKTestCase(unittest.TestCase, tutil.ApiClientMock):
-    def mock_call_update(self, api_mock, code, body):
-        self._mock_api_call(api_mock, code, body)
-
-    def api_client_mock(self, status=200):
-        api_client = super(SDKTestCase, self).api_client_mock()
-        self.mock_call_update(api_client.job_tasks().update, status, 'foo_file')
-        return api_client
-
-    def test_mock_500(self,code=500):
-        api_client = self.api_client_mock(code)
-        with self.assertRaises(arvados.errors.ApiError) as err_check:
-            arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)
-
-    def test_mock_200(self,code=200):
-        api_client = self.api_client_mock(code)
-        arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)
-
-    def test_mock_400(self,code=400):
-        api_client = self.api_client_mock(code)
-        with self.assertRaises(arvados.errors.ApiError) as err_check:
-            arvados.task_set_output({'uuid':'zzzzz-zzzzz-zzzzzzzzzzzzzzz'},s='d41d8cd98f00b204e9800998ecf8427e+0',api_client=api_client,num_retries=2)
-

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list