The bleeding edge branch is now called 'main'.
[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, group_class: "project")
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                refresh_permissions
44              end
45            end)
46     end
47     puts "created #{n}"
48     puts "Time spent getting group index:"
49     (0..1).each do
50       puts(Benchmark.measure do
51              get '/arvados/v1/groups', params: {format: :json}, headers: auth(:permission_perftest)
52              assert json_response['items_available'] >= n
53            end)
54     end
55   end
56 end