qemu-iotests: Avoid unnecessary sleeps

Test cases 030, 041 and 055 used to sleep for a second after calling
block-job-pause to make sure that the block job had time to actually
get into paused state. We can instead poll its status and use that one
second only as a timeout.

The tests also slept a second for checking that the block jobs don't
make progress while being paused. Half a second is more than enough for
this.

These changes reduce the total time for the three tests by 25 seconds on
my laptop (from 155 seconds to 130).

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Kevin Wolf 2017-07-21 16:41:21 +02:00
parent d3c8c67469
commit 2c93c5cb43
4 changed files with 44 additions and 17 deletions

View File

@ -89,18 +89,19 @@ class TestSingleDrive(iotests.QMPTestCase):
result = self.vm.qmp('block-job-pause', device='drive0') result = self.vm.qmp('block-job-pause', device='drive0')
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
time.sleep(1) self.vm.resume_drive('drive0')
self.pause_job('drive0')
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
offset = self.dictpath(result, 'return[0]/offset') offset = self.dictpath(result, 'return[0]/offset')
time.sleep(1) time.sleep(0.5)
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
self.assert_qmp(result, 'return[0]/offset', offset) self.assert_qmp(result, 'return[0]/offset', offset)
result = self.vm.qmp('block-job-resume', device='drive0') result = self.vm.qmp('block-job-resume', device='drive0')
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
self.vm.resume_drive('drive0')
self.wait_until_completed() self.wait_until_completed()
self.assert_no_active_block_jobs() self.assert_no_active_block_jobs()

View File

@ -103,14 +103,12 @@ class TestSingleDrive(iotests.QMPTestCase):
target=self.qmp_target) target=self.qmp_target)
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
result = self.vm.qmp('block-job-pause', device='drive0') self.pause_job('drive0')
self.assert_qmp(result, 'return', {})
time.sleep(1)
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
offset = self.dictpath(result, 'return[0]/offset') offset = self.dictpath(result, 'return[0]/offset')
time.sleep(1) time.sleep(0.5)
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
self.assert_qmp(result, 'return[0]/offset', offset) self.assert_qmp(result, 'return[0]/offset', offset)
@ -896,14 +894,12 @@ class TestRepairQuorum(iotests.QMPTestCase):
target=quorum_repair_img, format=iotests.imgfmt) target=quorum_repair_img, format=iotests.imgfmt)
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
result = self.vm.qmp('block-job-pause', device='job0') self.pause_job('job0')
self.assert_qmp(result, 'return', {})
time.sleep(1)
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
offset = self.dictpath(result, 'return[0]/offset') offset = self.dictpath(result, 'return[0]/offset')
time.sleep(1) time.sleep(0.5)
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
self.assert_qmp(result, 'return[0]/offset', offset) self.assert_qmp(result, 'return[0]/offset', offset)

View File

@ -89,11 +89,12 @@ class TestSingleDrive(iotests.QMPTestCase):
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
self.vm.resume_drive('drive0') self.vm.resume_drive('drive0')
time.sleep(1) self.pause_job('drive0')
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
offset = self.dictpath(result, 'return[0]/offset') offset = self.dictpath(result, 'return[0]/offset')
time.sleep(1) time.sleep(0.5)
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
self.assert_qmp(result, 'return[0]/offset', offset) self.assert_qmp(result, 'return[0]/offset', offset)
@ -302,11 +303,12 @@ class TestSingleTransaction(iotests.QMPTestCase):
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
self.vm.resume_drive('drive0') self.vm.resume_drive('drive0')
time.sleep(1) self.pause_job('drive0')
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
offset = self.dictpath(result, 'return[0]/offset') offset = self.dictpath(result, 'return[0]/offset')
time.sleep(1) time.sleep(0.5)
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
self.assert_qmp(result, 'return[0]/offset', offset) self.assert_qmp(result, 'return[0]/offset', offset)
@ -529,11 +531,12 @@ class TestDriveCompression(iotests.QMPTestCase):
self.assert_qmp(result, 'return', {}) self.assert_qmp(result, 'return', {})
self.vm.resume_drive('drive0') self.vm.resume_drive('drive0')
time.sleep(1) self.pause_job('drive0')
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
offset = self.dictpath(result, 'return[0]/offset') offset = self.dictpath(result, 'return[0]/offset')
time.sleep(1) time.sleep(0.5)
result = self.vm.qmp('query-block-jobs') result = self.vm.qmp('query-block-jobs')
self.assert_qmp(result, 'return[0]/offset', offset) self.assert_qmp(result, 'return[0]/offset', offset)

View File

@ -27,6 +27,7 @@
import qtest import qtest
import struct import struct
import json import json
import signal
# This will not work if arguments contain spaces but is necessary if we # This will not work if arguments contain spaces but is necessary if we
@ -137,6 +138,20 @@ def log(msg, filters=[]):
msg = flt(msg) msg = flt(msg)
print msg print msg
class Timeout:
def __init__(self, seconds, errmsg = "Timeout"):
self.seconds = seconds
self.errmsg = errmsg
def __enter__(self):
signal.signal(signal.SIGALRM, self.timeout)
signal.setitimer(signal.ITIMER_REAL, self.seconds)
return self
def __exit__(self, type, value, traceback):
signal.setitimer(signal.ITIMER_REAL, 0)
return False
def timeout(self, signum, frame):
raise Exception(self.errmsg)
class VM(qtest.QEMUQtestMachine): class VM(qtest.QEMUQtestMachine):
'''A QEMU VM''' '''A QEMU VM'''
@ -346,6 +361,18 @@ def complete_and_wait(self, drive='drive0', wait_ready=True):
event = self.wait_until_completed(drive=drive) event = self.wait_until_completed(drive=drive)
self.assert_qmp(event, 'data/type', 'mirror') self.assert_qmp(event, 'data/type', 'mirror')
def pause_job(self, job_id='job0'):
result = self.vm.qmp('block-job-pause', device=job_id)
self.assert_qmp(result, 'return', {})
with Timeout(1, "Timeout waiting for job to pause"):
while True:
result = self.vm.qmp('query-block-jobs')
for job in result['return']:
if job['device'] == job_id and job['paused'] == True and job['busy'] == False:
return job
def notrun(reason): def notrun(reason):
'''Skip this test suite''' '''Skip this test suite'''
# Each test in qemu-iotests has a number ("seq") # Each test in qemu-iotests has a number ("seq")