Fix assertion in test_instance_fault_get_by_instance

The instance_fault_get_by_instance_uuids DB API method returns
results sorted by created_at in descending order, so the newest
fault should be at the front of the list for a given instance
uuid in the resulting dict.

However, the way the test for this was written the 'expected'
list actually had the faults in order from oldest to newest. The
reason this didn't fail the test was because it was using
_assertEqualListsOfObjects to compare the results, which sorts
the lists before comparing them, which is exactly NOT what we want
when we care about the sort order of the results.

The test is fixed by using _assertEqualOrderedListOfObjects which
leaves the original sort order of the lists to compare and fixes
the 'expected' list by inserting the newest faults at the front
of the list.

Change-Id: I58990194016447b05b42df76141a193595cdcb9c
Related-Bug: #1632247
This commit is contained in:
Matt Riedemann
2016-12-29 12:17:10 -05:00
parent a74d3ae4e8
commit dc911b8026
+5 -2
View File
@@ -4214,13 +4214,16 @@ class InstanceFaultTestCase(test.TestCase, ModelsObjectComparatorMixin):
for code in fault_codes:
fault_values = self._create_fault_values(uuid, code)
fault = db.instance_fault_create(self.ctxt, fault_values)
expected[uuid].append(fault)
# We expect the faults to be returned ordered by created_at in
# descending order, so insert the newly created fault at the
# front of our list.
expected[uuid].insert(0, fault)
# Ensure faults are saved
faults = db.instance_fault_get_by_instance_uuids(self.ctxt, uuids)
self.assertEqual(len(expected), len(faults))
for uuid in uuids:
self._assertEqualListsOfObjects(expected[uuid], faults[uuid])
self._assertEqualOrderedListOfObjects(expected[uuid], faults[uuid])
def test_instance_faults_get_by_instance_uuids_no_faults(self):
uuid = uuidsentinel.uuid1