#!/usr/bin/ruby # = Stella # # === Your friend in web app performance testing # # Config (default paths): # # ./.stella/config (current directory) # ~/.stella/config (your home directory) # # Usage: # # $ stella -h # $ stella verify -p plans/basic.rb http://test.example.com/ # $ stella load -u 10 -t 60 http://test.example.com/ # $ stella load -u 10 -r 40 -p plans/basic.rb http://test.example.com/ # #-- STELLA_LIB_HOME = File.expand_path File.join(File.dirname(__FILE__), '..', 'lib') $:.unshift STELLA_LIB_HOME # Put our local lib in first place require 'drydock' require 'stella' require 'stella/cli' # Command-line interface for bin/stella class Stella::CLI::Definition extend Drydock debug :off default :verify # when no command is provided # ---------------------------------------- STELLA GLOBALS -------- # ------------------------------------------------------------------ global :A, :apikey, String, "API Key" global :S, :secret, String, "Secret Key" global :q, :quiet, "Be quiet!" do Stella.enable_quiet end global :D, :debug, "Enable debug mode" do Drydock.debug true Stella.enable_debug end global :v, :verbose, "Increase verbosity of output (e.g. -v or -vv or -vvv)" do Stella.loglev += 1 end global :V, :version, "Display version number" do puts "Stella version: #{Stella::VERSION} (#{Stella::VERSION::PATCH})" exit 0 end # ------------------------------------------------ STELLA -------- # ------------------------------------------------------------------ about "Run a functional test" usage "stella verify http://stellaaahhhh.com/" usage "stella verify -p path/2/testplan.rb http://stellaaahhhh.com/" option :b, :benchmark, "Benchmark mode (ignore wait times)" option :p, :testplan, String, "Path to testplan" do |v| raise Stella::InvalidOption, "Bad path: #{v}" unless File.exists?(v) v end command :verify => Stella::CLI about "Run a load test" usage "stella load http://stellaaahhhh.com/" usage "stella load -p path/2/testplan.rb http://stellaaahhhh.com/" option :b, :benchmark, "Benchmark mode (ignore wait times)" option :u, :users, Integer, "Number of virtual users" option :r, :repetitions, Integer, "Number of times to repeat the testplan (per vuser)" option :t, :time, String, "Max duration to run test" option :d, :delay, Float, "Delay between client requests (s)" option :p, :testplan, String, "Path to testplan" do |v| raise Stella::InvalidOption, "Bad path: #{v}" unless File.exists?(v) v end command :load => Stella::CLI about "Initialize Stella" command :init do Stella::Config.init end if Drydock.debug? about "Blast away all Stella config assets" command :blast do Stella::Config.blast end end # ---------------------------------- STELLA MISCELLANEOUS -------- # ------------------------------------------------------------------ before do |obj| @start = Time.now Stella.enable_debug if Drydock.debug? end after do |obj| Drydock::Screen.flush @elapsed = Time.now - @start if Stella.loglev > 1 && @elapsed > 0.1 puts puts "Elapsed: %.2f seconds" % @elapsed.to_f end exit obj.exit_code || 0 end end begin Drydock.run!(ARGV, STDIN) if Drydock.run? && !Drydock.has_run? rescue Drydock::ArgError, Drydock::OptError => ex STDERR.puts ex.message STDERR.puts ex.usage rescue Drydock::InvalidArgument => ex STDERR.puts ex.message rescue Stella::Error => ex STDERR.puts ex.message STDERR.puts ex.backtrace if Drydock.debug? rescue Interrupt puts "#{$/}Exiting... " exit 1 rescue => ex STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}" STDERR.puts ex.backtrace if Drydock.debug? end