DEV: Update bench.rb for core changes (#8670)

- Use new api key rake task
- Switch to header-based API auth
- Stop hard-coding topic id
This commit is contained in:
David Taylor 2020-01-08 05:23:29 +00:00 committed by Sam
parent a8fbf7c128
commit fd6fbaa4ae
2 changed files with 19 additions and 9 deletions

View File

@ -184,7 +184,7 @@ puts "Populating Profile DB"
run("bundle exec ruby script/profile_db_generator.rb")
puts "Getting api key"
api_key = `bundle exec rake api_key:get_or_create_master[bench]`.split("\n")[-1]
api_key = `bundle exec rake api_key:create_master[bench]`.split("\n")[-1]
def bench(path, name)
puts "Running apache bench warmup"
@ -225,22 +225,32 @@ begin
end
puts "Starting benchmark..."
append = "?api_key=#{api_key}&api_username=admin1"
headers = { 'Api-Key' => api_key,
'Api-Username' => "admin1" }
# asset precompilation is a dog, wget to force it
run "wget http://127.0.0.1:#{@port}/ -o /dev/null -O /dev/null"
redirect_response = `curl -s -I "http://127.0.0.1:#{@port}/t/i-am-a-topic-used-for-perf-tests"`
if redirect_response !~ /301 Moved Permanently/
raise "Unable to locate topic for perf tests"
end
topic_url = redirect_response.match(/^location: .+(\/t\/i-am-a-topic-used-for-perf-tests\/.+)$/i)[1].strip
tests = [
["categories", "/categories"],
["home", "/"],
["topic", "/t/i-am-a-topic-used-for-perf-tests/179"]
["topic", topic_url]
# ["user", "/u/admin1/activity"],
]
tests.concat(tests.map { |k, url| ["#{k}_admin", "#{url}#{append}"] })
tests.concat(tests.map { |k, url| ["#{k}_admin", "#{url}", headers] })
tests.each do |_, path|
if `curl -s -I "http://127.0.0.1:#{@port}#{path}"` !~ /200 OK/
tests.each do |_, path, headers_for_path|
header_string = headers_for_path&.map { |k, v| "-H \"#{k}: #{v}\"" }&.join(" ")
if `curl -s -I "http://127.0.0.1:#{@port}#{path}" #{header_string}` !~ /200 OK/
raise "#{path} returned non 200 response code"
end
end
@ -311,12 +321,12 @@ begin
if @mem_stats
puts
puts open("http://127.0.0.1:#{@port}/admin/memory_stats#{append}").read
puts open("http://127.0.0.1:#{@port}/admin/memory_stats", headers).read
end
if @dump_heap
puts
puts open("http://127.0.0.1:#{@port}/admin/dump_heap#{append}").read
puts open("http://127.0.0.1:#{@port}/admin/dump_heap", headers).read
end
if @result_file

View File

@ -65,7 +65,7 @@ unless Rails.env == "profile"
end
def ensure_perf_test_topic_has_right_title!
t = Topic.find(179)
t = Topic.where(archetype: :regular).last
t.title = "I am a topic used for perf tests"
t.save! if t.title_changed?
end