From ca576ac6d24aa4bafa43c247e99ccbff482bc098 Mon Sep 17 00:00:00 2001 From: Sushil Kumar Date: Fri, 4 Sep 2015 08:48:38 +0000 Subject: [PATCH] Fixes the mgmt.test_datastores errors The test in mgmt.test_datastores.TestDatastoreVersion.test_version_index is failing because of concurrency race problems. Executing in sequence the delete method would delete one of the datastore versions and while executing another test for index method, the setup method would recreate the deleted object so that queries work correctly. But because of delete and index methods running concurrently on different threads, the delete is deleting the object during the execution of setup/index method on another thread because of which the object query is failing. As a fix, did two things, 1. Since 'test_vr1' is only used by delete method, shifted the query of test_vr1 to delete method. 2. Updated the mocked method used in test_version_index from models.Datastore.load to models.DatastoreVersion.load_by_uuid the former is not needed in test_version_index, the not-useful mock got left, probably, while the code for index method was updated. Change-Id: I816b602579892588d3179a0dc08b9fc5668f1e5b Closes-Bug: #1492130 --- trove/tests/unittests/mgmt/test_datastores.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/trove/tests/unittests/mgmt/test_datastores.py b/trove/tests/unittests/mgmt/test_datastores.py index 790f7f14e9..ea1dee40a1 100644 --- a/trove/tests/unittests/mgmt/test_datastores.py +++ b/trove/tests/unittests/mgmt/test_datastores.py @@ -36,7 +36,6 @@ class TestDatastoreVersion(trove_testtools.TestCase): 'test_ds', 'test_vr2', 'mysql', '154b350d-4d86-4214-9067-9c54b230c0da', 'pkg-1', '1') self.ds = models.Datastore.load('test_ds') - self.ds_version1 = models.DatastoreVersion.load(self.ds, 'test_vr1') self.ds_version2 = models.DatastoreVersion.load(self.ds, 'test_vr2') self.context = Mock() @@ -100,18 +99,20 @@ class TestDatastoreVersion(trove_testtools.TestCase): self.version_controller.create, self.req, body, self.tenant_id) def test_version_delete(self): + ds_version1 = models.DatastoreVersion.load(self.ds, 'test_vr1') + output = self.version_controller.delete(self.req, self.tenant_id, - self.ds_version1.id) + ds_version1.id) err_msg = ("Datastore version '%s' cannot be found." % - self.ds_version1.id) + ds_version1.id) self.assertEqual(202, output.status) # Try to find deleted version, this should raise exception. self.assertRaisesRegexp( exception.DatastoreVersionNotFound, - err_msg, models.DatastoreVersion.load_by_uuid, self.ds_version1.id) + err_msg, models.DatastoreVersion.load_by_uuid, ds_version1.id) @patch.object(remote, 'create_nova_client') def test_version_update(self, mock_client): @@ -140,7 +141,7 @@ class TestDatastoreVersion(trove_testtools.TestCase): self.version_controller.edit, self.req, body, self.tenant_id, self.ds_version2.id) - @patch.object(models.Datastore, 'load') + @patch.object(models.DatastoreVersion, 'load_by_uuid') def test_version_index(self, mock_load): output = self.version_controller.index( self.req, self.tenant_id)