module BigBench # Dispatches the command line commands to BigBench calls. Available commands are: # # :include: executor.txt module Executor class Executable < Thor include Thor::Actions # Templates are here def self.source_root File.join(File.dirname(__FILE__), "templates") end # Version and Help desc "-v", "Show the version" method_options %w( version -v ) => :boolean def default options.version? ? puts(BigBench::VERSION) : help end default_task :default # Run Local desc "local TEST_FILE", "Run the TEST_FILE on the local machine" def local(file) BigBench.load_test! File.open(file, "rb"){ |file| file.read } BigBench.run! BigBench.write_local_trackings_to_file! BigBench.run_post_processors! end # Run Bots desc "bots TEST_FILE [REDIS_URL_WITH_PORT] [REDIS_PASSWORD]", "Run the TEST_FILE on all bots" def bots(file, redis_url = nil, redis_password = nil) # Load and validate tests test = File.open(file, "rb"){ |file| file.read } BigBench.load_test!(test) BigBench.config.mode = :bots # Initialize redis BigBench::Store.setup!(redis_url, redis_password) # Load current test to redis & start bots BigBench::Store.test = test BigBench::Store.start BigBench::Output.deployed_test # Wait for bots to run the tests @is_running = true timer = Thread.new{ sleep(BigBench.duration.to_i) BigBench::Store.stop @is_running = false } BigBench::Output.starting_bots_loop loop{ bots = BigBench::Store.bots BigBench::Output.running_bots_loop(bots) sleep(1) break if !@is_running and bots.size == 0 } # Gather trackings from redis and write them to the file BigBench::Output.finished_bots_loop BigBench.write_store_trackings_to_file! BigBench.run_post_processors! BigBench::Store.reset! end # Start Bot desc "bot [REDIS_URL_WITH_PORT] [REDIS_PASSWORD]", "Start a bot on the current machine" def bot(redis_url = nil, redis_password = nil) BigBench::Store.setup!(redis_url, redis_password) loop { BigBench::Output.bot_is_checking BigBench::Bot.check_test! sleep(BigBench.config.bot_checks_every.to_i) } end # Post Process desc "process TEST_FILE [POST_PROCESSOR]", "Run all post processors of the testfile or the single POST_PROCESSOR" def process(file, post_processor = nil) BigBench.load_test! File.open(file, "rb"){ |file| file.read } if post_processor BigBench::PostProcessor.reset! BigBench.post_process(post_processor) BigBench.run_post_processors! else BigBench.run_post_processors! end end # Reset desc "reset [REDIS_URL_WITH_PORT] [REDIS_PASSWORD]", "Reset everything including the redis storage" def reset(redis_url = nil, redis_password = nil) BigBench::Store.setup!(redis_url, redis_password) BigBench::Store.reset! BigBench::Configuration.reset! BigBench::Benchmark.reset! BigBench::Output.reset end # Generator desc "generate TEST_FILE", "Generates a simple test file to customize further" def generate(name) @name = name template "test_plan.rb.erb", "#{name}.rb" end end end end