]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa: tear down oeqa decorators if one of them raises an exception in setup
authorAlexander Kanavin <alex.kanavin@gmail.com>
Tue, 20 Apr 2021 17:32:58 +0000 (19:32 +0200)
committerAnuj Mittal <anuj.mittal@intel.com>
Mon, 26 Apr 2021 00:59:21 +0000 (08:59 +0800)
Some of the decorators need proper cleanup, such as OETimeout
which sets a signal handler that needs to be cleared via teardown.
If this is not done then the signal gets called later with unpredictable effects.

This can be seen if there's a test that is skipped via a decorator and sets a timeout
at the same time: the timeout isn't cleared, and is invoked later in a
completely unrelated context. The test case for this is added in the
next commit.

Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit f42a08e1aabf1ca57e0c09d69fb69cc717c7f156)
Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
meta/lib/oeqa/core/case.py
meta/lib/oeqa/core/decorator/oetimeout.py

index aae451fef2b46c986e92e356126a37c981d7fff6..bc4446a938ec31eef0d3012bbfd44802ab63980b 100644 (file)
@@ -43,8 +43,13 @@ class OETestCase(unittest.TestCase):
         clss.tearDownClassMethod()
 
     def _oeSetUp(self):
-        for d in self.decorators:
-            d.setUpDecorator()
+        try:
+            for d in self.decorators:
+                d.setUpDecorator()
+        except:
+            for d in self.decorators:
+                d.tearDownDecorator()
+            raise
         self.setUpMethod()
 
     def _oeTearDown(self):
index df90d1c7987497b8a262cfcf337394968763634d..5e6873ad48be57dd03f8ec62ed74e8512c519771 100644 (file)
@@ -24,5 +24,6 @@ class OETimeout(OETestDecorator):
 
     def tearDownDecorator(self):
         signal.alarm(0)
-        signal.signal(signal.SIGALRM, self.alarmSignal)
-        self.logger.debug("Removed SIGALRM handler")
+        if hasattr(self, 'alarmSignal'):
+            signal.signal(signal.SIGALRM, self.alarmSignal)
+            self.logger.debug("Removed SIGALRM handler")