'Ensure retrived action events are in order.'

def test_instance_action_events_get_are_in_order(self):

    uuid1 = uuidsentinel.uuid1
    action = db.action_start(self.ctxt, self._create_action_values(uuid1))
    extra1 = {'created_at': timeutils.utcnow()}
    extra2 = {'created_at': (timeutils.utcnow() + datetime.timedelta(seconds=5))}
    event_val1 = self._create_event_values(uuid1, 'schedule', extra=extra1)
    event_val2 = self._create_event_values(uuid1, 'run', extra=extra1)
    event_val3 = self._create_event_values(uuid1, 'stop', extra=extra2)
    event1 = db.action_event_start(self.ctxt, event_val1)
    event2 = db.action_event_start(self.ctxt, event_val2)
    event3 = db.action_event_start(self.ctxt, event_val3)
    events = db.action_events_get(self.ctxt, action['id'])
    self.assertEqual(3, len(events))
    self._assertEqualOrderedListOfObjects([event3, event2, event1], events, ['instance_uuid', 'request_id'])
