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