qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] iotests: fix wait_until_completed()
@ 2018-03-26  6:11 Peter Xu
  2018-03-26 10:47 ` Kevin Wolf
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Xu @ 2018-03-26  6:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Max Reitz, peterx

If there are more than one events, wait_until_completed() might return
the 2nd event even if the 1st event is JOB_COMPLETED, since the for loop
will continue to run even if completed is set to True.

It never happened before, but it can be triggered when OOB is enabled
due to the RESUME startup message. Fix that up by removing the boolean
and make sure we return the correct event.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 tests/qemu-iotests/iotests.py | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index b5d7945af8..11704e6583 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -470,18 +470,14 @@ class QMPTestCase(unittest.TestCase):
 
     def wait_until_completed(self, drive='drive0', check_offset=True):
         '''Wait for a block job to finish, returning the event'''
-        completed = False
-        while not completed:
-            for event in self.vm.get_qmp_events(wait=True):
-                if event['event'] == 'BLOCK_JOB_COMPLETED':
-                    self.assert_qmp(event, 'data/device', drive)
-                    self.assert_qmp_absent(event, 'data/error')
-                    if check_offset:
-                        self.assert_qmp(event, 'data/offset', event['data']['len'])
-                    completed = True
-
-        self.assert_no_active_block_jobs()
-        return event
+        for event in self.vm.get_qmp_events(wait=True):
+            if event['event'] == 'BLOCK_JOB_COMPLETED':
+                self.assert_qmp(event, 'data/device', drive)
+                self.assert_qmp_absent(event, 'data/error')
+                if check_offset:
+                    self.assert_qmp(event, 'data/offset', event['data']['len'])
+                self.assert_no_active_block_jobs()
+                return event
 
     def wait_ready(self, drive='drive0'):
         '''Wait until a block job BLOCK_JOB_READY event'''
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-04-04 14:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-26  6:11 [Qemu-devel] [PATCH] iotests: fix wait_until_completed() Peter Xu
2018-03-26 10:47 ` Kevin Wolf
2018-03-27  2:21   ` Peter Xu
2018-04-03 12:59     ` Stefan Hajnoczi
2018-04-04  1:42       ` Peter Xu
2018-04-04 14:24         ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).