ae23c9
From 6839f724393417ae25f3b5ab8bd85bf067925cc2 Mon Sep 17 00:00:00 2001
ae23c9
From: Kevin Wolf <kwolf@redhat.com>
ae23c9
Date: Tue, 26 Jun 2018 09:48:55 +0200
ae23c9
Subject: [PATCH 147/268] iotests: Fix 219's timing
ae23c9
ae23c9
RH-Author: Kevin Wolf <kwolf@redhat.com>
ae23c9
Message-id: <20180626094856.6924-73-kwolf@redhat.com>
ae23c9
Patchwork-id: 81111
ae23c9
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH v2 72/73] iotests: Fix 219's timing
ae23c9
Bugzilla: 1513543
ae23c9
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
ae23c9
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ae23c9
RH-Acked-by: Fam Zheng <famz@redhat.com>
ae23c9
ae23c9
From: Max Reitz <mreitz@redhat.com>
ae23c9
ae23c9
219 has two issues that may lead to sporadic failure, both of which are
ae23c9
the result of issuing query-jobs too early after a job has been
ae23c9
modified.  This can then lead to different results based on whether the
ae23c9
modification has taken effect already or not.
ae23c9
ae23c9
First, query-jobs is issued right after the job has been created.
ae23c9
Besides its current progress possibly being in any random state (which
ae23c9
has already been taken care of), its total progress too is basically
ae23c9
arbitrary, because the job may not yet have been able to determine it.
ae23c9
This patch addresses this by just filtering the total progress, like
ae23c9
what has been done for the current progress already.  However, for more
ae23c9
clarity, the filtering is changed to replace the values by a string
ae23c9
'FILTERED' instead of deleting them.
ae23c9
ae23c9
Secondly, query-jobs is issued right after a job has been resumed.  The
ae23c9
job may or may not yet have had the time to actually perform any I/O,
ae23c9
and thus its current progress may or may not have advanced.  To make
ae23c9
sure it has indeed advanced (which is what the reference output already
ae23c9
assumes), keep querying it until it has.
ae23c9
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
Message-id: 20180606190628.8170-1-mreitz@redhat.com
ae23c9
Reviewed-by: Eric Blake <eblake@redhat.com>
ae23c9
Signed-off-by: Max Reitz <mreitz@redhat.com>
ae23c9
(cherry picked from commit 83f90b535a0d5e64056c087aa4022ea35c59bcd0)
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 tests/qemu-iotests/219     | 26 ++++++++++++++++++++------
ae23c9
 tests/qemu-iotests/219.out | 10 +++++-----
ae23c9
 2 files changed, 25 insertions(+), 11 deletions(-)
ae23c9
ae23c9
diff --git a/tests/qemu-iotests/219 b/tests/qemu-iotests/219
ae23c9
index 898a26e..c03bbdb 100755
ae23c9
--- a/tests/qemu-iotests/219
ae23c9
+++ b/tests/qemu-iotests/219
ae23c9
@@ -42,11 +42,24 @@ def test_pause_resume(vm):
ae23c9
             iotests.log(vm.qmp(pause_cmd, **{pause_arg: 'job0'}))
ae23c9
             pause_wait(vm, 'job0')
ae23c9
             iotests.log(iotests.filter_qmp_event(vm.event_wait('JOB_STATUS_CHANGE')))
ae23c9
-            iotests.log(vm.qmp('query-jobs'))
ae23c9
+            result = vm.qmp('query-jobs')
ae23c9
+            iotests.log(result)
ae23c9
+
ae23c9
+            old_progress = result['return'][0]['current-progress']
ae23c9
+            total_progress = result['return'][0]['total-progress']
ae23c9
 
ae23c9
             iotests.log(vm.qmp(resume_cmd, **{resume_arg: 'job0'}))
ae23c9
             iotests.log(iotests.filter_qmp_event(vm.event_wait('JOB_STATUS_CHANGE')))
ae23c9
-            iotests.log(vm.qmp('query-jobs'))
ae23c9
+            if old_progress < total_progress:
ae23c9
+                # Wait for the job to advance
ae23c9
+                while result['return'][0]['current-progress'] == old_progress:
ae23c9
+                    result = vm.qmp('query-jobs')
ae23c9
+                iotests.log(result)
ae23c9
+            else:
ae23c9
+                # Already reached the end, so the job cannot advance
ae23c9
+                # any further; therefore, the query-jobs result can be
ae23c9
+                # logged immediately
ae23c9
+                iotests.log(vm.qmp('query-jobs'))
ae23c9
 
ae23c9
 def test_job_lifecycle(vm, job, job_args, has_ready=False):
ae23c9
     iotests.log('')
ae23c9
@@ -58,12 +71,13 @@ def test_job_lifecycle(vm, job, job_args, has_ready=False):
ae23c9
     iotests.log(vm.qmp(job, job_id='job0', **job_args))
ae23c9
 
ae23c9
     # Depending on the storage, the first request may or may not have completed
ae23c9
-    # yet, so filter out the progress. Later query-job calls don't need the
ae23c9
-    # filtering because the progress is made deterministic by the block job
ae23c9
-    # speed
ae23c9
+    # yet (and the total progress may not have been fully determined yet), so
ae23c9
+    # filter out the progress. Later query-job calls don't need the filtering
ae23c9
+    # because the progress is made deterministic by the block job speed
ae23c9
     result = vm.qmp('query-jobs')
ae23c9
     for j in result['return']:
ae23c9
-        del j['current-progress']
ae23c9
+        j['current-progress'] = 'FILTERED'
ae23c9
+        j['total-progress'] = 'FILTERED'
ae23c9
     iotests.log(result)
ae23c9
 
ae23c9
     # undefined -> created -> running
ae23c9
diff --git a/tests/qemu-iotests/219.out b/tests/qemu-iotests/219.out
ae23c9
index 346801b..6dc07bc 100644
ae23c9
--- a/tests/qemu-iotests/219.out
ae23c9
+++ b/tests/qemu-iotests/219.out
ae23c9
@@ -3,7 +3,7 @@ Launching VM...
ae23c9
 
ae23c9
 Starting block job: drive-mirror (auto-finalize: True; auto-dismiss: True)
ae23c9
 {u'return': {}}
ae23c9
-{u'return': [{u'status': u'running', u'total-progress': 4194304, u'id': u'job0', u'type': u'mirror'}]}
ae23c9
+{u'return': [{u'status': u'running', u'current-progress': 'FILTERED', u'total-progress': 'FILTERED', u'id': u'job0', u'type': u'mirror'}]}
ae23c9
 {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'created', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'}
ae23c9
 {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'running', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'}
ae23c9
 
ae23c9
@@ -93,7 +93,7 @@ Waiting for PENDING state...
ae23c9
 
ae23c9
 Starting block job: drive-backup (auto-finalize: True; auto-dismiss: True)
ae23c9
 {u'return': {}}
ae23c9
-{u'return': [{u'status': u'running', u'total-progress': 4194304, u'id': u'job0', u'type': u'backup'}]}
ae23c9
+{u'return': [{u'status': u'running', u'current-progress': 'FILTERED', u'total-progress': 'FILTERED', u'id': u'job0', u'type': u'backup'}]}
ae23c9
 {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'created', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'}
ae23c9
 {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'running', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'}
ae23c9
 
ae23c9
@@ -144,7 +144,7 @@ Waiting for PENDING state...
ae23c9
 
ae23c9
 Starting block job: drive-backup (auto-finalize: True; auto-dismiss: False)
ae23c9
 {u'return': {}}
ae23c9
-{u'return': [{u'status': u'running', u'total-progress': 4194304, u'id': u'job0', u'type': u'backup'}]}
ae23c9
+{u'return': [{u'status': u'running', u'current-progress': 'FILTERED', u'total-progress': 'FILTERED', u'id': u'job0', u'type': u'backup'}]}
ae23c9
 {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'created', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'}
ae23c9
 {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'running', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'}
ae23c9
 
ae23c9
@@ -203,7 +203,7 @@ Waiting for PENDING state...
ae23c9
 
ae23c9
 Starting block job: drive-backup (auto-finalize: False; auto-dismiss: True)
ae23c9
 {u'return': {}}
ae23c9
-{u'return': [{u'status': u'running', u'total-progress': 4194304, u'id': u'job0', u'type': u'backup'}]}
ae23c9
+{u'return': [{u'status': u'running', u'current-progress': 'FILTERED', u'total-progress': 'FILTERED', u'id': u'job0', u'type': u'backup'}]}
ae23c9
 {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'created', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'}
ae23c9
 {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'running', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'}
ae23c9
 
ae23c9
@@ -262,7 +262,7 @@ Waiting for PENDING state...
ae23c9
 
ae23c9
 Starting block job: drive-backup (auto-finalize: False; auto-dismiss: False)
ae23c9
 {u'return': {}}
ae23c9
-{u'return': [{u'status': u'running', u'total-progress': 4194304, u'id': u'job0', u'type': u'backup'}]}
ae23c9
+{u'return': [{u'status': u'running', u'current-progress': 'FILTERED', u'total-progress': 'FILTERED', u'id': u'job0', u'type': u'backup'}]}
ae23c9
 {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'created', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'}
ae23c9
 {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u'status': u'running', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'}
ae23c9
 
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9