浏览代码

HUE-2436 [desktop] Protect tests from falling into an infinite loop

The mako test runner doesn't handle one template calling another.
This can happen if when rendering one template we call a function
that throws an exception, triggering the rendering of the error
page. This results in an infinite loop and obscures the original
failure. This patch instead builds a stack of template render calls
so that the original error can be discovered.
Erick Tryzelaar 10 年之前
父节点
当前提交
fc20566
共有 1 个文件被更改,包括 7 次插入4 次删除
  1. 7 4
      desktop/core/src/desktop/lib/test_runners.py

+ 7 - 4
desktop/core/src/desktop/lib/test_runners.py

@@ -36,13 +36,16 @@ def _instrumented_test_render(self, *args, **data):
     """
     def mako_callable_(context, *args, **kwargs):
       template_rendered.send(sender=self, template=self, context=context)
-      return self.original_callable_(context, *args, **kwargs)
-    self.original_callable_ = self.callable_
+      return self.original_callable_[-1](context, *args, **kwargs)
+    if hasattr(self, 'original_callable_'):
+      self.original_callable_.append(self.callable_)
+    else:
+      self.original_callable_ = [self.callable_]
     self.callable_ = mako_callable_
     try:
-      response = runtime._render(self, self.original_callable_, args, data)
+      response = runtime._render(self, self.original_callable_[-1], args, data)
     finally:
-      self.callable_ = self.original_callable_
+      self.callable_ = self.original_callable_.pop()
     return response