Class: WSDirector::Runner
- Inherits:
-
Object
- Object
- WSDirector::Runner
- Defined in:
- lib/wsdirector/runner.rb
Overview
Initiates all clients as a separate tasks (=threads)
Instance Method Summary collapse
-
#initialize(scenario) ⇒ Runner
constructor
A new instance of Runner.
- #start ⇒ Object
Constructor Details
#initialize(scenario) ⇒ Runner
Returns a new instance of Runner.
14 15 16 17 18 19 |
# File 'lib/wsdirector/runner.rb', line 14 def initialize(scenario) @scenario = scenario @total_count = scenario["total"] @global_holder = ClientsHolder.new(total_count) @results_holder = ResultsHolder.new end |
Instance Method Details
#start ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/wsdirector/runner.rb', line 21 def start Thread.abort_on_exception = true tasks = scenario["clients"].flat_map do |client| result = Result.new(client.fetch("name")) results_holder << result Array.new(client.fetch("multiplier")) do Thread.new do Task.new(client.deep_dup, global_holder: global_holder, result: result) .run end end end tasks.each(&:join) results_holder.print_summary results_holder.success? end |