You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/08/28 16:35:01 UTC

[20/50] git commit: [#3154] don't hide task errors when run in tests

[#3154] don't hide task errors when run in tests


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

Branch: refs/heads/tv/6526
Commit: 07d4de958db20c65cae6c4bfedba93575bfff8cc
Parents: a779ed7
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Wed Aug 21 15:19:43 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Aug 22 20:49:28 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/monq_model.py | 17 +++++++++++------
 Allura/allura/tests/test_tasks.py |  3 ++-
 Allura/test.ini                   |  3 +++
 3 files changed, 16 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/07d4de95/Allura/allura/model/monq_model.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/monq_model.py b/Allura/allura/model/monq_model.py
index 3163ea5..faac14b 100644
--- a/Allura/allura/model/monq_model.py
+++ b/Allura/allura/model/monq_model.py
@@ -23,6 +23,8 @@ from datetime import datetime, timedelta
 
 import pymongo
 from pylons import tmpl_context as c, app_globals as g
+from tg import config
+from paste.deploy.converters import asbool
 
 import ming
 from ming.utils import LazyProperty
@@ -257,13 +259,16 @@ class MonQTask(MappedClass):
             self.state = 'complete'
             return self.result
         except Exception, exc:
-            log.exception('Error "%s" on job %s', exc, self)
-            self.state = 'error'
-            if hasattr(exc, 'format_error'):
-                self.result = exc.format_error()
-                log.error(self.result)
+            if asbool(config.get('monq.raise_errors')):
+                raise
             else:
-                self.result = traceback.format_exc()
+                log.exception('Error "%s" on job %s', exc, self)
+                self.state = 'error'
+                if hasattr(exc, 'format_error'):
+                    self.result = exc.format_error()
+                    log.error(self.result)
+                else:
+                    self.result = traceback.format_exc()
         finally:
             self.time_stop = datetime.utcnow()
             session(self).flush(self)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/07d4de95/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 9f307ee..26bcb36 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -81,7 +81,8 @@ class TestEventTasks(unittest.TestCase):
         setup_basic_test()
         setup_global_objects()
         t = raise_exc.post()
-        with LogCapture(level=logging.ERROR) as l:
+        with LogCapture(level=logging.ERROR) as l, \
+             mock.patch.dict(tg.config, {'monq.raise_errors': False}):  # match normal non-test behavior
             t()
         # l.check() would be nice, but string is too detailed to check
         assert_equal(l.records[0].name, 'allura.model.monq_model')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/07d4de95/Allura/test.ini
----------------------------------------------------------------------
diff --git a/Allura/test.ini b/Allura/test.ini
index 2546149..9892e3c 100644
--- a/Allura/test.ini
+++ b/Allura/test.ini
@@ -68,6 +68,9 @@ load_test_data = true
 cache_test_data = false
 site_admin_project = test
 
+# useful primarily for test suites, where we want to see the error right away
+monq.raise_errors = true
+
 # Set the locations of some static resources
 #  script_name is the path that is handled by the application
 #  url_base is the prefix that references to the static resources should have