Fixed nondeterministicness of extra_data test
I guess I reused classes a little too much when testing the fingerprint generation, because the fingerprint being generated out of the used class was nondeterministic because something else was changing on the class before/during the fingerprint generation. So now there is a class created only for the test, and the fingerprint is generated on that object (with only extra data to correctly isolate what's being tested). Change-Id: I6ba68fa0a03546b93f0f983f86fde886976b7569
This commit is contained in:
parent
193dd3032f
commit
4bf749510c
@ -378,26 +378,29 @@ class TestObjectVersionChecker(test.TestCase):
|
||||
def test_get_fingerprint_with_extra_data(self):
|
||||
# Make sure _get_fingerprint() uses extra_data_func when it is
|
||||
# supplied
|
||||
class ExtraDataObj(base.VersionedObject):
|
||||
pass
|
||||
|
||||
def get_data(obj_class):
|
||||
return (obj_class,)
|
||||
|
||||
MyObject.VERSION = '1.1'
|
||||
ExtraDataObj.VERSION = '1.1'
|
||||
argspec = 'cubone'
|
||||
self._add_class(self.obj_classes, ExtraDataObj)
|
||||
|
||||
with mock.patch('inspect.getargspec') as mock_gas:
|
||||
mock_gas.return_value = argspec
|
||||
fp = self.ovc._get_fingerprint(MyObject.__name__,
|
||||
fp = self.ovc._get_fingerprint(ExtraDataObj.__name__,
|
||||
extra_data_func=get_data)
|
||||
|
||||
exp_fields = sorted(list(MyObject.fields.items()))
|
||||
exp_methods = sorted([('remotable_method', argspec),
|
||||
('remotable_classmethod', argspec)])
|
||||
exp_extra_data = MyObject
|
||||
exp_fields = []
|
||||
exp_methods = []
|
||||
exp_extra_data = ExtraDataObj
|
||||
exp_relevant_data = (exp_fields, exp_methods, exp_extra_data)
|
||||
|
||||
expected_hash = hashlib.md5(six.binary_type(repr(
|
||||
exp_relevant_data).encode())).hexdigest()
|
||||
expected_fp = '%s-%s' % (MyObject.VERSION, expected_hash)
|
||||
expected_fp = '%s-%s' % (ExtraDataObj.VERSION, expected_hash)
|
||||
|
||||
self.assertEqual(expected_fp, fp, "_get_fingerprint() did not "
|
||||
"generate a correct fingerprint.")
|
||||
|
Loading…
x
Reference in New Issue
Block a user