[oe-commits] [openembedded-core] 14/14: oeqa/tinfoil: Improve test_wait_event for race issues

git at git.openembedded.org git at git.openembedded.org
Fri Jul 7 22:58:33 UTC 2017


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit 76e750ba44caca6770c783939da21dd4e890b25e
Author: Richard Purdie <richard.purdie at linuxfoundation.org>
AuthorDate: Fri Jul 7 13:55:06 2017 +0100

    oeqa/tinfoil: Improve test_wait_event for race issues
    
    The test could break in a variety of ways:
    
    a) If BB_HEARTBEAT_EVENT was less than ~0.25 it would hang indefinitely
    b) The mask is set after draining the event queue meaning a heartbeat event
       could have happened
    c) The test exits once it sees the events it wants, it doesn't check for
       spurious events such as heartbeats which shouldn't have occured.
    d) The hardcoded delay of 0.25 is nasty and shouldn't be needed.
    
    I found a bitbake bug and fixed that meaning we don't need the delay any
    more which fixes d). That means a) is no longer an issue either.
    
    We now set the mask, then drain the queue meaning no spurious events should
    be able to sneak in. The test is also tweaked to wait for 5s in total to
    ensure spurious events don't occur such as heartbeat events we shouldn't see.
    
    [YOCTO #11045]
    
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 meta/lib/oeqa/selftest/cases/tinfoil.py | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/meta/lib/oeqa/selftest/cases/tinfoil.py b/meta/lib/oeqa/selftest/cases/tinfoil.py
index 3a58761..aa1af7e 100644
--- a/meta/lib/oeqa/selftest/cases/tinfoil.py
+++ b/meta/lib/oeqa/selftest/cases/tinfoil.py
@@ -1,5 +1,6 @@
 import os
 import re
+import time
 import bb.tinfoil
 
 from oeqa.selftest.case import OESelftestTestCase
@@ -102,21 +103,26 @@ class TinfoilTests(OESelftestTestCase):
     def test_wait_event(self):
         with bb.tinfoil.Tinfoil() as tinfoil:
             tinfoil.prepare(config_only=True)
-            # Need to drain events otherwise events that will be masked will still be in the queue
-            while tinfoil.wait_event(0.25):
-                pass
+
             tinfoil.set_event_mask(['bb.event.FilesMatchingFound', 'bb.command.CommandCompleted'])
+
+            # Need to drain events otherwise events that were masked may still be in the queue
+            while tinfoil.wait_event():
+                pass
+
             pattern = 'conf'
             res = tinfoil.run_command('findFilesMatchingInDir', pattern, 'conf/machine')
             self.assertTrue(res)
 
             eventreceived = False
-            waitcount = 5
-            while waitcount > 0:
+            commandcomplete = False
+            start = time.time()
+            # Wait for 5s in total so we'd detect spurious heartbeat events for example
+            while time.time() - start < 5:
                 event = tinfoil.wait_event(1)
                 if event:
                     if isinstance(event, bb.command.CommandCompleted):
-                        break
+                        commandcomplete = True
                     elif isinstance(event, bb.event.FilesMatchingFound):
                         self.assertEqual(pattern, event._pattern)
                         self.assertIn('qemuarm.conf', event._matches)
@@ -124,9 +130,7 @@ class TinfoilTests(OESelftestTestCase):
                     else:
                         self.fail('Unexpected event: %s' % event)
 
-                waitcount = waitcount - 1
-
-            self.assertNotEqual(waitcount, 0, 'Timed out waiting for CommandCompleted event from bitbake server')
+            self.assertTrue(commandcomplete, 'Timed out waiting for CommandCompleted event from bitbake server')
             self.assertTrue(eventreceived, 'Did not receive FilesMatchingFound event from bitbake server')
 
     @OETestID(1576)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list