1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
# frozen_string_literal: true
require 'test_helper'
require 'shellwords'
class TasksTest < ActiveSupport::TestCase
def setup
FileUtils.mkdir_p(rails_app_path('tmp'))
end
def teardown
FileUtils.remove_entry_secure(rails_app_path('tmp'))
end
def run!(cmd)
puts "Running: #{cmd}"
out = `#{cmd}`
raise "Could not run #{cmd}, output: #{out}" unless $?.success?
out
end
def rake(cmd, options = {})
assert_success = options.key?(:assert_success) ? options[:assert_success] : true
env = options[:env] || {}
env_string = env.map {|key, value| "#{key.shellescape}=#{value.to_s.shellescape}" }.join(" ")
cmd = "env #{env_string} bundle exec rake -f perf.rake #{cmd} --trace"
puts "Running: #{cmd}"
result = Bundler.with_original_env { `cd '#{rails_app_path}' && #{cmd}` }
if assert_success
assert $?.success?, "Expected '#{cmd}' to return a success status.\nOutput: #{result}"
end
result
end
test 'library_branches' do
skip unless ENV['USING_RAILS_GIT']
env = { "TEST_COUNT" => 10, "DERAILED_SCRIPT_COUNT" => 2, "SHAS_TO_TEST" => "3054e1d584e7eca110c69a1f8423f2e0866abbf9,80f989aecece1a2b1830e9c953e5887421b52d3c"}
puts rake "perf:library", { env: env }
end
test 'hitting authenticated devise apps' do
env = { "PATH_TO_HIT" => "authenticated", "USE_AUTH" => "true", "TEST_COUNT" => "2" }
result = rake 'perf:test', env: env
assert_match 'Auth: true', result
env["USE_SERVER"] = "webrick"
result = rake 'perf:test', env: env
assert_match 'Auth: true', result
assert_match 'Server: "webrick"', result
end
test 'authenticate with a custom user' do
env = { "AUTH_CUSTOM_USER" => "true", "PATH_TO_HIT" => "authenticated", "USE_AUTH" => "true", "TEST_COUNT" => "2" }
result = rake 'perf:test', env: env
assert_match 'Auth: true', result
end
test 'test' do
rake "perf:test"
end
test 'app' do
skip unless ENV['USING_RAILS_GIT']
run!("cd #{rails_app_path} && git init . && git add . && git commit -m first && git commit --allow-empty -m second")
env = { "TEST_COUNT" => 10, "DERAILED_SCRIPT_COUNT" => 2 }
puts rake "perf:app", { env: env }
end
test 'TEST_COUNT' do
result = rake "perf:test", env: { "TEST_COUNT" => 1 }
assert_match "1 derailed requests", result
end
test 'WARM_COUNT' do
result = rake "perf:test", env: { "WARM_COUNT" => 1 }
assert_match "Warming up app:", result
end
test 'PATH_TO_HIT' do
env = { "PATH_TO_HIT" => 'foo', "TEST_COUNT" => "2" }
result = rake "perf:test", env: env
assert_match 'Endpoint: "foo"', result
env["USE_SERVER"] = "webrick"
result = rake "perf:test", env: env
assert_match 'Endpoint: "foo"', result
assert_match 'Server: "webrick"', result
end
test 'HTTP headers' do
env = {
"PATH_TO_HIT" => 'foo_secret',
"TEST_COUNT" => "2",
"HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("admin:secret")}",
"HTTP_CACHE_CONTROL" => "no-cache"
}
result = rake "perf:test", env: env
assert_match 'Endpoint: "foo_secret"', result
assert_match 'HTTP headers: {"Authorization"=>"Basic YWRtaW46c2VjcmV0\n", "Cache-Control"=>"no-cache"}', result
env["USE_SERVER"] = "webrick"
result = rake "perf:test", env: env
assert_match 'HTTP headers: {"Authorization"=>"Basic YWRtaW46c2VjcmV0\n", "Cache-Control"=>"no-cache"}', result
end
test 'USE_SERVER' do
result = rake "perf:test", env: { "USE_SERVER" => 'webrick', "TEST_COUNT" => "2" }
assert_match 'Server: "webrick"', result
end
test '' do
end
test 'objects' do
rake "perf:objects"
end
test 'mem' do
rake "perf:mem"
end
test 'mem_over_time' do
rake "perf:mem_over_time"
end
test 'ips' do
rake "perf:mem_over_time"
end
end
|