Merge branch '14196-api-v2-tokens' refs #14196
[arvados.git] / services / api / test / performance / permission_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 'benchmark'
7
8
9 def create_eight parent
10   uuids = []
11   values = []
12   (0..8).each do
13     uuid = Group.generate_uuid
14     values.push "('#{uuid}', '#{parent}', now(), now(), '#{uuid}')"
15     uuids.push uuid
16   end
17   ActiveRecord::Base.connection.execute("INSERT INTO groups (uuid, owner_uuid, created_at, updated_at, name) VALUES #{values.join ','}")
18   uuids
19 end
20
21 class PermissionPerfTest < ActionDispatch::IntegrationTest
22   def test_groups_index
23     n = 0
24     act_as_system_user do
25       puts("Time spent creating records:", Benchmark.measure do
26              ActiveRecord::Base.transaction do
27                root = Group.create!(owner_uuid: users(:permission_perftest).uuid)
28                n += 1
29                a = create_eight root.uuid
30                n += 8
31                a.each do |p1|
32                  b = create_eight p1
33                  n += 8
34                  b.each do |p2|
35                    c = create_eight p2
36                    n += 8
37                    c.each do |p3|
38                      d = create_eight p3
39                      n += 8
40                    end
41                  end
42                end
43              end
44            end)
45     end
46     puts "created #{n}"
47     puts "Time spent getting group index:"
48     (0..4).each do
49       puts(Benchmark.measure do
50              get '/arvados/v1/groups', {format: :json, limit: 1000}, auth(:permission_perftest)
51              assert json_response['items_available'] >= n
52            end)
53     end
54   end
55 end