lib/stella/adapter/siege.rb in stella-0.5.3 vs lib/stella/adapter/siege.rb in stella-0.5.4

- old
+ new

@@ -30,31 +30,41 @@ # to simulate human activity. Default value is 3 # -H, --header="text" Add a header to request (can be many) # -A, --user-agent="text" Sets User-Agent in request class Siege < Stella::Adapter::Base + attr_writer :reps, :concurrent, :version + attr_reader :user_agent + attr_accessor :help, :config, :verbose, :get, :log, :mark, :delay, :header + attr_accessor :rc, :file, :time, :benchmark, :internet - attr_accessor :version, :help, :config, :verbose, :get, :log, :mark, :delay, :header, :user_agent - attr_accessor :reps, :concurrent, :rc, :file, :time, :benchmark, :internet - def initialize(options={}, arguments=[]) super(options, arguments) @name = 'siege' @reps = 1 @concurrent = 1 - @rc = File.join(ENV['HOME'], '.siegerc') @private_variables = ['private_variables', 'name', 'arguments', 'load_factor', 'working_directory', 'orig_logfile'] @load_factor = 1 + + @rc = File.join(ENV['HOME'] || ENV['USERPROFILE'], '.siegerc') + + # Siege won't run unless there's a siegerc file. If the default one doesn't exist + # we need to call siege.config to create it. This should only happen once. + # We use capture_output here so STDOUT and STDERR don't print to the screen. + Stella::Util.capture_output("#{@name}.config") do 'nothing' end unless File.exists? @rc end + + def error + (File.exists? stderr_path) ? FileUtil.read_file(stderr_path) : "Unknown error" + end + def version vsn = 0 - text = "" - Open3.popen3("#{@name} --version") do |stdin, stdout, stderr| - text = stderr.readlines.join - text.scan(/SIEGE (\d+?\.\d+)/) { |v| vsn = v[0] } + Stella::Util.capture_output("#{@name} --version") do |stdout, stderr| + stderr.join.scan(/SIEGE (\d+?\.\d+)/) { |v| vsn = v[0] } end vsn end # loadtest @@ -135,12 +145,19 @@ opts.on('-t S', '--time=S', String) do |v| @time = v end opts.on('-b', '--benchmark') do |v| @benchmark = true; end opts.on('-i', '--internet') do |v| @internet = true; end opts.on('-A S', '--user-agent=S', String) do |v| @user_agent ||= []; @user_agent << v end - raise "You cannot select both --internet and --benchmark" if options.internet && options.benchmark - + unless options.benchmark + Stella::LOGGER.warn('--benchmark (or -b) is not selected. Siege will include "think-time" for all requests.') + end + + opts.on('-n N',Integer) do |v| + Stella::LOGGER.error("-n is not a Siege parameter. You probably want -r.") + exit 1 + end + # parse! removes the options it finds. # It also fails when it finds unknown switches (i.e. -X) # Which should leave only the remaining arguments (URIs in this case) opts.parse!(arguments) options @@ -255,10 +272,10 @@ end end # Siege writes the summary to STDERR def stats_file - File.new(stderr_path) + File.new(stderr_path) if File.exists?(stderr_path) end def rc_file File.join(@working_directory, "siegerc") end \ No newline at end of file