mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
a8fbf7c128
commit
fd6fbaa4ae
@ -184,7 +184,7 @@ puts "Populating Profile DB"
|
|||||||
run("bundle exec ruby script/profile_db_generator.rb")
|
run("bundle exec ruby script/profile_db_generator.rb")
|
||||||
|
|
||||||
puts "Getting api key"
|
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)
|
def bench(path, name)
|
||||||
puts "Running apache bench warmup"
|
puts "Running apache bench warmup"
|
||||||
@ -225,22 +225,32 @@ begin
|
|||||||
end
|
end
|
||||||
|
|
||||||
puts "Starting benchmark..."
|
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
|
# asset precompilation is a dog, wget to force it
|
||||||
run "wget http://127.0.0.1:#{@port}/ -o /dev/null -O /dev/null"
|
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 = [
|
tests = [
|
||||||
["categories", "/categories"],
|
["categories", "/categories"],
|
||||||
["home", "/"],
|
["home", "/"],
|
||||||
["topic", "/t/i-am-a-topic-used-for-perf-tests/179"]
|
["topic", topic_url]
|
||||||
# ["user", "/u/admin1/activity"],
|
# ["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|
|
tests.each do |_, path, headers_for_path|
|
||||||
if `curl -s -I "http://127.0.0.1:#{@port}#{path}"` !~ /200 OK/
|
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"
|
raise "#{path} returned non 200 response code"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -311,12 +321,12 @@ begin
|
|||||||
|
|
||||||
if @mem_stats
|
if @mem_stats
|
||||||
puts
|
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
|
end
|
||||||
|
|
||||||
if @dump_heap
|
if @dump_heap
|
||||||
puts
|
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
|
end
|
||||||
|
|
||||||
if @result_file
|
if @result_file
|
||||||
|
@ -65,7 +65,7 @@ unless Rails.env == "profile"
|
|||||||
end
|
end
|
||||||
|
|
||||||
def ensure_perf_test_topic_has_right_title!
|
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.title = "I am a topic used for perf tests"
|
||||||
t.save! if t.title_changed?
|
t.save! if t.title_changed?
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user