Skip to content

Commit

Permalink
Compare transactions by IDs, not timestamps
Browse files Browse the repository at this point in the history
Make Transaction method `__lt__` work in an expected way.
True if t1.tid < t2.tid, false when t1.tid > t2.tid.
This fixes the behavior of sort method (lowest/oldest first without
    using reverse flag).

Fixes random behavior in CI tests:
    rpm-software-management/ci-dnf-stack#248
  • Loading branch information
Eduard Čuba authored and j-mracek committed Oct 10, 2017
1 parent 5de9bd3 commit a7cd209
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
10 changes: 2 additions & 8 deletions dnf/yum/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,7 @@ def __init__(self, history, row):
def __lt__(self, other):
if other is None:
return False
if self.beg_timestamp == other.beg_timestamp:
if self.end_timestamp == other.end_timestamp:
return self.tid > other.tid
else:
return self.end_timestamp < other.end_timestamp
else:
return self.beg_timestamp > other.beg_timestamp
return self.tid < other.tid

def _getTransWith(self):
if self._loaded_TW is None:
Expand Down Expand Up @@ -713,7 +707,7 @@ def merge(self, obj):
self._merged_tids.add(obj.tid)
self._merged_objs.append(obj)
# Oldest first...
self._merged_objs.sort(reverse=True)
self._merged_objs.sort()

if self.beg_timestamp > obj.beg_timestamp:
self.beg_timestamp = obj.beg_timestamp
Expand Down
9 changes: 2 additions & 7 deletions tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,13 +615,8 @@ class ComparisonTests(TestCase):
def test_transaction(self):
a = dnf.yum.history.YumHistoryTransaction(None, [1, 5, 0, 5, 0, 0, 0])
b = dnf.yum.history.YumHistoryTransaction(None, [9, 5, 0, 5, 0, 0, 0])
self.assertGreater(a, b)
self.assertLess(b, a)

a2 = dnf.yum.history.YumHistoryTransaction(None, [0, 1, 0, 0, 0, 0, 0])
b2 = dnf.yum.history.YumHistoryTransaction(None, [0, 9, 0, 0, 0, 0, 0])
self.assertGreater(a2, b2)
self.assertLess(b2, a2)
self.assertLess(a, b)
self.assertGreater(b, a)

def test_rpmdb_problem(self):
a = dnf.yum.history.YumHistoryRpmdbProblem(None, 1, 5, None)
Expand Down

0 comments on commit a7cd209

Please sign in to comment.