11453: Merge branch 'master' into 11453-federated-tokens
[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[:api_client_authorization] =
16       api_client_authorizations(:active)
17   end
18
19   teardown do
20     Thread.current[:api_client_authorization] = nil
21   end
22
23   # "crrud" == "create read render update delete", not a typo
24   slow_test "crrud cycle for a collection with a big manifest)" do
25     bigmanifest = time_block 'make example' do
26       make_manifest(streams: 100,
27                     files_per_stream: 100,
28                     blocks_per_file: 20,
29                     bytes_per_block: 2**26,
30                     api_token: api_token(:active))
31     end
32     act_as_user users(:active) do
33       c = time_block "new (manifest_text is #{bigmanifest.length>>20}MiB)" do
34         Collection.new manifest_text: bigmanifest.dup
35       end
36       time_block 'check signatures' do
37         c.check_signatures
38       end
39       time_block 'check signatures + save' do
40         c.instance_eval do @signatures_checked = false end
41         c.save!
42       end
43       c = time_block 'read' do
44         Collection.find_by_uuid(c.uuid)
45       end
46       time_block 'sign' do
47         c.signed_manifest_text
48       end
49       time_block 'sign + render' do
50         c.as_api_response(nil)
51       end
52       loc = Blob.sign_locator(Digest::MD5.hexdigest('foo') + '+3',
53                               api_token: api_token(:active))
54       # Note Collection's strip_manifest_text method has now removed
55       # the signatures from c.manifest_text, so we have to start from
56       # bigmanifest again here instead of just appending with "+=".
57       c.manifest_text = bigmanifest.dup + ". #{loc} 0:3:foo.txt\n"
58       time_block 'update' do
59         c.save!
60       end
61       time_block 'delete' do
62         c.destroy
63       end
64     end
65   end
66 end