659
659
vf.iter_lines_added_or_present_in_keys, keys)
660
660
self.assertEqual([2, 1, 1], reload_counter)
662
def test_get_record_stream_yields_disk_sorted_order(self):
663
# if we get 'unordered' pick a semi-optimal order for reading. The
664
# order should be grouped by pack file, and then by position in file
665
repo = self.make_repository('test', format='pack-0.92')
667
self.addCleanup(repo.unlock)
668
repo.start_write_group()
670
vf.add_lines(('f-id', 'rev-5'), [('f-id', 'rev-4')], ['lines\n'])
671
vf.add_lines(('f-id', 'rev-1'), [], ['lines\n'])
672
vf.add_lines(('f-id', 'rev-2'), [('f-id', 'rev-1')], ['lines\n'])
673
repo.commit_write_group()
674
# We inserted them as rev-5, rev-1, rev-2, we should get them back in
676
stream = vf.get_record_stream([('f-id', 'rev-1'), ('f-id', 'rev-5'),
677
('f-id', 'rev-2')], 'unordered', False)
678
keys = [r.key for r in stream]
679
self.assertEqual([('f-id', 'rev-5'), ('f-id', 'rev-1'),
680
('f-id', 'rev-2')], keys)
681
repo.start_write_group()
682
vf.add_lines(('f-id', 'rev-4'), [('f-id', 'rev-3')], ['lines\n'])
683
vf.add_lines(('f-id', 'rev-3'), [('f-id', 'rev-2')], ['lines\n'])
684
vf.add_lines(('f-id', 'rev-6'), [('f-id', 'rev-5')], ['lines\n'])
685
repo.commit_write_group()
686
# Request in random order, to make sure the output order isn't based on
688
request_keys = set(('f-id', 'rev-%d' % i) for i in range(1, 7))
689
stream = vf.get_record_stream(request_keys, 'unordered', False)
690
keys = [r.key for r in stream]
691
# We want to get the keys back in disk order, but it doesn't matter
692
# which pack we read from first. So this can come back in 2 orders
693
alt1 = [('f-id', 'rev-%d' % i) for i in [4, 3, 6, 5, 1, 2]]
694
alt2 = [('f-id', 'rev-%d' % i) for i in [5, 1, 2, 4, 3, 6]]
695
if keys != alt1 and keys != alt2:
696
self.fail('Returned key order did not match either expected order.'
697
' expected %s or %s, not %s'
698
% (alt1, alt2, keys))
663
701
class LowLevelKnitDataTests(TestCase):