class WSDirector::Runner

Initiates all clients as a separate tasks (=threads)

Attributes

global_holder[R]
results_holder[R]
scenario[R]
total_count[R]

Public Class Methods

new(scenario) click to toggle source
# 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

Public Instance Methods

start() click to toggle source
# 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