-
Notifications
You must be signed in to change notification settings - Fork 22
/
benchmark.rb
32 lines (26 loc) · 1.06 KB
/
benchmark.rb
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
require 'harness'
# Before we load ActiveRecord, let's make sure the
# database exists and is up to date.
# Note: db:migrate will create the DB if it doesn't exist,
# and this app's db/seeds.rb will delete and repopulate
# the database, so rows shouldn't accumulate.
Dir.chdir __dir__
use_gemfile extra_setup_cmd: "bin/rails db:migrate db:seed"
ENV['RAILS_ENV'] ||= 'production'
require_relative 'config/environment'
app = Rails.application
possible_routes = ['/posts', '/posts.json']
possible_routes.concat((1..100).map { |i| "/posts/#{i}"})
visit_count = 2000
rng = Random.new(0x1be52551fc152997)
visiting_routes = Array.new(visit_count) { possible_routes.sample(random: rng) }
run_benchmark(10) do
visiting_routes.each do |path|
# The app mutates `env`, so we need to create one every time.
env = Rack::MockRequest::env_for("http://localhost#{path}")
response_array = app.call(env)
unless response_array.first == 200
raise "HTTP response is #{response_array.first} instead of 200. Is the benchmark app properly set up? See README.md."
end
end
end