Skip to content

Commit

Permalink
iotests: Make 055 less flaky
Browse files Browse the repository at this point in the history
First of all, test 055 does a valiant job of invoking pause_drive()
sometimes, but that is worth nothing without blkdebug.  So the first
thing to do is to sprinkle a couple of "blkdebug::" in there -- with the
exception of the transaction tests, because the blkdebug break points
make the transaction QMP command hang (which is bad).  In that case, we
can get away with throttling the block job that it effectively is
paused.

Then, 055 usually does not pause the drive before starting a block job
that should be cancelled.  This means that the backup job might be
completed already before block-job-cancel is invoked; thus making the
test either fail (currently) or moot if cancel_and_wait() ignored this
condition.  Fix this by pausing the drive before starting the job.

Signed-off-by: Max Reitz <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
Message-id: [email protected]
Signed-off-by: Max Reitz <[email protected]>
  • Loading branch information
XanClic committed Nov 14, 2017
1 parent 51c493c commit bc11aee
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions tests/qemu-iotests/055
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TestSingleDrive(iotests.QMPTestCase):
def setUp(self):
qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, str(image_len))

self.vm = iotests.VM().add_drive(test_img)
self.vm = iotests.VM().add_drive('blkdebug::' + test_img)
self.vm.add_drive(blockdev_target_img, interface="none")
if iotests.qemu_default_machine == 'pc':
self.vm.add_drive(None, 'media=cdrom', 'ide')
Expand All @@ -65,10 +65,11 @@ class TestSingleDrive(iotests.QMPTestCase):
def do_test_cancel(self, cmd, target):
self.assert_no_active_block_jobs()

self.vm.pause_drive('drive0')
result = self.vm.qmp(cmd, device='drive0', target=target, sync='full')
self.assert_qmp(result, 'return', {})

event = self.cancel_and_wait()
event = self.cancel_and_wait(resume=True)
self.assert_qmp(event, 'data/type', 'backup')

def test_cancel_drive_backup(self):
Expand Down Expand Up @@ -166,7 +167,7 @@ class TestSetSpeed(iotests.QMPTestCase):
def setUp(self):
qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, str(image_len))

self.vm = iotests.VM().add_drive(test_img)
self.vm = iotests.VM().add_drive('blkdebug::' + test_img)
self.vm.add_drive(blockdev_target_img, interface="none")
self.vm.launch()

Expand Down Expand Up @@ -246,6 +247,8 @@ class TestSetSpeed(iotests.QMPTestCase):
def test_set_speed_invalid_blockdev_backup(self):
self.do_test_set_speed_invalid('blockdev-backup', 'drive1')

# Note: We cannot use pause_drive() here, or the transaction command
# would stall. Instead, we limit the block job speed here.
class TestSingleTransaction(iotests.QMPTestCase):
def setUp(self):
qemu_img('create', '-f', iotests.imgfmt, blockdev_target_img, str(image_len))
Expand All @@ -271,7 +274,8 @@ class TestSingleTransaction(iotests.QMPTestCase):
'type': cmd,
'data': { 'device': 'drive0',
'target': target,
'sync': 'full' },
'sync': 'full',
'speed': 64 * 1024 },
}
])

Expand All @@ -289,20 +293,22 @@ class TestSingleTransaction(iotests.QMPTestCase):
def do_test_pause(self, cmd, target, image):
self.assert_no_active_block_jobs()

self.vm.pause_drive('drive0')
result = self.vm.qmp('transaction', actions=[{
'type': cmd,
'data': { 'device': 'drive0',
'target': target,
'sync': 'full' },
'sync': 'full',
'speed': 64 * 1024 },
}
])
self.assert_qmp(result, 'return', {})

result = self.vm.qmp('block-job-pause', device='drive0')
self.assert_qmp(result, 'return', {})

self.vm.resume_drive('drive0')
result = self.vm.qmp('block-job-set-speed', device='drive0', speed=0)
self.assert_qmp(result, 'return', {})

self.pause_job('drive0')

result = self.vm.qmp('query-block-jobs')
Expand Down Expand Up @@ -461,7 +467,7 @@ class TestDriveCompression(iotests.QMPTestCase):
pass

def do_prepare_drives(self, fmt, args, attach_target):
self.vm = iotests.VM().add_drive(test_img)
self.vm = iotests.VM().add_drive('blkdebug::' + test_img)

qemu_img('create', '-f', fmt, blockdev_target_img,
str(TestDriveCompression.image_len), *args)
Expand Down Expand Up @@ -500,10 +506,11 @@ class TestDriveCompression(iotests.QMPTestCase):

self.assert_no_active_block_jobs()

self.vm.pause_drive('drive0')
result = self.vm.qmp(cmd, device='drive0', sync='full', compress=True, **args)
self.assert_qmp(result, 'return', {})

event = self.cancel_and_wait()
event = self.cancel_and_wait(resume=True)
self.assert_qmp(event, 'data/type', 'backup')

self.vm.shutdown()
Expand Down

0 comments on commit bc11aee

Please sign in to comment.