17755: Merge branch 'main' into 17755-add-singularity-to-compute-image
[arvados.git] / services / api / test / unit / collection_performance_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 'helpers/manifest_examples'
7 require 'helpers/time_block'
8
9 class CollectionModelPerformanceTest < ActiveSupport::TestCase
10   include ManifestExamples
11
12   setup do
13     # The Collection model needs to have a current token, not just a
14     # current user, to sign & verify manifests:
15     Thread.current[:token] = api_client_authorizations(:active).token
16   end
17
18   teardown do
19     Thread.current[:token] = nil
20   end
21
22   # "crrud" == "create read render update delete", not a typo
23   slow_test "crrud cycle for a collection with a big manifest)" do
24     bigmanifest = time_block 'make example' do
25       make_manifest(streams: 100,
26                     files_per_stream: 100,
27                     blocks_per_file: 20,
28                     bytes_per_block: 2**26,
29                     api_token: api_client_authorizations(:active).token)
30     end
31     act_as_user users(:active) do
32       c = time_block "new (manifest_text is #{bigmanifest.length>>20}MiB)" do
33         Collection.new manifest_text: bigmanifest.dup
34       end
35       time_block 'check signatures' do
36         c.check_signatures
37       end
38       time_block 'check signatures + save' do
39         c.instance_eval do @signatures_checked = false end
40         c.save!
41       end
42       c = time_block 'read' do
43         Collection.find_by_uuid(c.uuid)
44       end
45       time_block 'sign' do
46         c.signed_manifest_text
47       end
48       time_block 'sign + render' do
49         c.as_api_response(nil)
50       end
51       loc = Blob.sign_locator(Digest::MD5.hexdigest('foo') + '+3',
52                               api_token: api_client_authorizations(:active).token)
53       # Note Collection's strip_manifest_text method has now removed
54       # the signatures from c.manifest_text, so we have to start from
55       # bigmanifest again here instead of just appending with "+=".
56       c.manifest_text = bigmanifest.dup + ". #{loc} 0:3:foo.txt\n"
57       time_block 'update' do
58         c.save!
59       end
60       time_block 'delete' do
61         c.destroy
62       end
63     end
64   end
65 end