Shopify / pyoozie

Library for querying and scheduling with Apache Oozie
https://py-oozie.readthedocs.io
MIT License
11 stars 12 forks source link

Fix flaky XML comparison #48

Closed cfournie closed 7 years ago

cfournie commented 7 years ago

Problem

When testing https://github.com/Shopify/pyoozie/pull/46, sometimes XML comparisons would fail due to the ordering of lists of dicts (this happens maybe 10% of the time).

...
E             'fork': {'@name': 'fork-00000005',
E             -                            'path': [{'@start': 'action-00000000'},
E             ?                                                               ^
E             +                            'path': [{'@start': 'action-00000001'},
E             ?                                                               ^
E             -                                     {'@start': 'action-00000001'}]},
E             ?                                                               ^
E             +                                     {'@start': 'action-00000000'}]},
E             ?                                                               ^
...

Solution

This PR refactors xml_to_comparable_dict to convert collections.OrderedDict to a dict in _unorder, and if there's a list, it tries to predictably sort it by recursing through a value's contents and getting a hashable object for each type in _sort_key.

cc/ @Shopify/data-acceleration

prabcs commented 7 years ago

LGTM