18004: Fixes a couple of race condition bugs related to caching remote users.
[arvados.git] / services / api / test / unit / group_pdhs_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6 require 'group_pdhs'
7
8 # NOTE: Migration 20190322174136_add_file_info_to_collection.rb
9 # relies on this test. Change with caution!
10 class GroupPdhsTest < ActiveSupport::TestCase
11   test "pdh_grouping_by_manifest_size" do
12     batch_size_max = 200
13     pdhs_in = ['x1+30', 'x2+30', 'x3+201', 'x4+100', 'x5+100']
14     pdh_lambda = lambda { |last_pdh, &block|
15       pdhs = pdhs_in.select{|pdh| pdh > last_pdh} 
16       pdhs.each do |p|
17         block.call(p)
18       end
19     }
20     batched_pdhs = []
21     GroupPdhs.group_pdhs_for_multiple_transactions(pdh_lambda, pdhs_in.size, batch_size_max, "") do |pdhs|
22       batched_pdhs << pdhs
23     end
24     expected = [['x1+30', 'x2+30'], ['x3+201'], ['x4+100', 'x5+100']]
25     assert_equal(batched_pdhs, expected)
26   end
27 end