]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Reduce the chance of random check/gate test failures
authorajmiller <al.miller@ajmiller.net>
Wed, 9 Sep 2015 21:38:41 +0000 (14:38 -0700)
committerajmiller <al.miller@ajmiller.net>
Wed, 9 Sep 2015 21:45:16 +0000 (14:45 -0700)
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

neutron/tests/unit/quota/test_resource.py
neutron/tests/unit/quota/test_resource_registry.py

index 7f668539807395afd9d41b5f979d568c4256cdca..e45ccc59e8999344ef15b610d4dd3d3a272b5a45 100644 (file)
@@ -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()
index 0fa06d5bfab2e273873211f3cb68dd75fbd9dcf4..fcf27c8f2901d53ae8dcbb09ba701ce31d6f2584 100644 (file)
@@ -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'])