From: ajmiller Date: Wed, 9 Sep 2015 21:38:41 +0000 (-0700) Subject: Reduce the chance of random check/gate test failures X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=4a8c2b875e4abb8e99d62f1530f209147faada2f;p=openstack-build%2Fneutron-build.git Reduce the chance of random check/gate test failures As previously implemented, the TestTrackedResource class is designed to inject random failures into the gate. It generates random numbers within the range of 0..10000, and will fail if it generates duplicate random numbers during its run. This patch creates UUIDs instead of random numbers, and makes the chance of an collision vanishingly small. Change-Id: I0cf535d1c5a3995a50b506aafce10e983872dcb7 Closes-bug: #1494021 --- diff --git a/neutron/tests/unit/quota/test_resource.py b/neutron/tests/unit/quota/test_resource.py index 7f6685398..e45ccc59e 100644 --- a/neutron/tests/unit/quota/test_resource.py +++ b/neutron/tests/unit/quota/test_resource.py @@ -12,9 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. -import random - import mock +import uuid + from oslo_config import cfg from neutron import context @@ -28,7 +28,6 @@ from neutron.tests.unit import testlib_api meh_quota_flag = 'quota_meh' meh_quota_opts = [cfg.IntOpt(meh_quota_flag, default=99)] -random.seed() class TestResource(base.DietTestCase): @@ -64,12 +63,10 @@ class TestTrackedResource(testlib_api.SqlTestCaseLight): session = db_api.get_session() with session.begin(): tenant_id = tenant_id or self.tenant_id - session.add(test_quota.MehModel( - meh='meh_%d' % random.randint(0, 10000), - tenant_id=tenant_id)) - session.add(test_quota.MehModel( - meh='meh_%d' % random.randint(0, 10000), - tenant_id=tenant_id)) + session.add(test_quota.MehModel(meh='meh_%s' % uuid.uuid4(), + tenant_id=tenant_id)) + session.add(test_quota.MehModel(meh='meh_%s' % uuid.uuid4(), + tenant_id=tenant_id)) def _delete_data(self): session = db_api.get_session() diff --git a/neutron/tests/unit/quota/test_resource_registry.py b/neutron/tests/unit/quota/test_resource_registry.py index 0fa06d5bf..fcf27c8f2 100644 --- a/neutron/tests/unit/quota/test_resource_registry.py +++ b/neutron/tests/unit/quota/test_resource_registry.py @@ -40,14 +40,14 @@ class TestResourceRegistry(base.DietTestCase): self.test_set_tracked_resource_new_resource() self.registry.set_tracked_resource('meh', test_quota.OtherMehModel, override=True) - # Overidde is set to True, the model class should change + # Override is set to True, the model class should change self.assertEqual(test_quota.OtherMehModel, self.registry._tracked_resource_mappings['meh']) def test_set_tracked_resource_existing_no_override(self): self.test_set_tracked_resource_new_resource() self.registry.set_tracked_resource('meh', test_quota.OtherMehModel) - # Overidde is set to false, the model class should not change + # Override is set to false, the model class should not change self.assertEqual(test_quota.MehModel, self.registry._tracked_resource_mappings['meh'])