Skip to content

Instantly share code, notes, and snippets.

@bneutra
Created September 13, 2019 16:34
Show Gist options
  • Save bneutra/c035ea9495c6a3f71faac303ceccf1a4 to your computer and use it in GitHub Desktop.
Save bneutra/c035ea9495c6a3f71faac303ceccf1a4 to your computer and use it in GitHub Desktop.
require 'ruby-jmeter'
# flush stdout immediately
$stdout.sync = true
# default to Dockerfile jmeter location
jmeter_path = ENV['JMETER_BIN'] ? ENV['JMETER_BIN'] : '/opt/jmeter/bin/'
json_path = File.dirname(__FILE__) + '/claim.json'
gui = false # only true for non docker testing
claim_url = ARGV[0] # e.g. https://your/api
throughput = ARGV[1].to_f # rpm
duration = ARGV[2] # seconds
rampup = ARGV[3] # seconds
threads = (throughput / 120).to_i # enough threads, as long as latency is < 500ms
testplan = test do
threads count: threads, duration: duration, rampup: rampup do
constant_throughput_timer throughput: throughput / threads
if gui
view_results_tree
aggregate_report
end
# irf claim request
counter('CounterConfig.name': 'YEAR',
'CounterConfig.start': 2015,
'CounterConfig.incr': 1,
'CounterConfig.end': 2017,
'CounterConfig.per_user': false
)
default_headers = [
{ name: 'Content-Type', value: 'application/json' },
]
post(name: 'Do claim', url: claim_url, raw_body: IO.read(json_path)) do
header(default_headers)
end
end
end
if __FILE__ == $0
testplan.run(
path: jmeter_path,
gui: gui,
debug: true
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment