]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa/tinfoil: Improve test_wait_event for race issues
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 7 Jul 2017 12:55:06 +0000 (13:55 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 8 Jul 2017 12:34:00 +0000 (13:34 +0100)
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@linuxfoundation.org>
meta/lib/oeqa/selftest/cases/tinfoil.py

index 3a58761c00222f9b5f221ee11777d1230695cf37..aa1af7e0423fe3977bf8f27c0302c2f17e17c734 100644 (file)
@@ -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)