Skip to content

Instantly share code, notes, and snippets.

@sudara
Created May 6, 2018 11:36
Show Gist options
  • Save sudara/9cb031dffc04b7a39b3cd6303cd299e1 to your computer and use it in GitHub Desktop.
Save sudara/9cb031dffc04b7a39b3cd6303cd299e1 to your computer and use it in GitHub Desktop.
config/perf_check.rb
# Place this at config/perf_check.rb in your app it will be included by bundle exec perf_check
# See https://github.com/rubytune/perf_check/blob/2988bcdfc1430ab6f83d526cc87c660719fe4144/lib/perf_check.rb#L47-L54
require 'shellwords'
options = perf_check.options
# Add a new option to perf_check that allows us to pass in a user
# You could also hardcode the actual user to allow --admin or --moderator
perf_check.option_parser.on('--user USER', '-u', 'Login as user') do |user|
options.login_user = user
end
perf_check.before_start do |perf_check, test_case|
resource = Shellwords.shellescape(test_case.resource)
if user = options.login_user
user = Shellwords.shellescape(user)
session_id = SecureRandom.hex(16)
user_id = User.find_by!(login: user).id
# This assumes sessions live in memcache
cache = Dalli::Client.new(ENV.fetch("MEMCACHED_SERVER", "127.0.0.1:11211"), compress: true)
cache.set("rack:session:#{session_id}",
user_id: user_id,
peek: false
)
options.cookie = "_session_id=#{session_id.strip}"
# options.headers['Authorization'] = %(Token token="#{api_token.strip}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment