From aabca4d746368846b05f47590a99c1c03b4469a9 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Mon, 22 Aug 2016 14:20:08 -0400 Subject: [PATCH] Tests: Fix racy volume unit test This test sends an async delete request which is racy -- if the volume_api.delete path is slow enough, the volume will still be 'available' when the test asserts that it should be in 'deleting'. Change-Id: I57165c15efeef56e679d1b2cc02fa4cad87504a7 --- cinder/tests/unit/test_volume.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index 3955ab8846f..de034907f3e 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -1126,7 +1126,13 @@ class VolumeTestCase(BaseVolumeTestCase): db.volume_update(self.context, volume['id'], {'status': 'available'}) self.volume_api.delete(self.context, volume) - volume = db.volume_get(self.context, volume['id']) + volume = objects.Volume.get_by_id(self.context, volume.id) + while volume.status == 'available': + # Must wait for volume_api delete request to process enough to + # change the volume status. + time.sleep(0.5) + volume.refresh() + self.assertEqual('deleting', volume['status']) db.volume_destroy(self.context, volume['id'])