Sha256: 92efae21f21d5a1b2e2dcd350468e15397c87242fd8dfa0b3a550cf5568b8d9e
Contents?: true
Size: 1.73 KB
Versions: 3
Compression:
Stored size: 1.73 KB
Contents
# frozen_string_literal: true require "wsdirector/scenario_reader" require "wsdirector/clients_holder" require "wsdirector/results_holder" require "wsdirector/result" require "wsdirector/task" require "wsdirector/ext/deep_dup" module WSDirector def self.run(scenario, scale: 1, connection_options: {}, locals: {}, **options) scenario = ScenarioReader.parse(scenario, scale: scale, connection_options: connection_options, locals: locals) Runner.new(scenario, scale: scale, **options).execute end # Initiates all clients as a separate tasks (=threads) class Runner using WSDirector::Ext::DeepDup def initialize(scenario, url:, scale: 1, sync_timeout: 5, logger: nil, colorize: false) @scenario = scenario @url = url @scale = scale @logger = logger @colorize = colorize @total_count = scenario["total"] @global_holder = ClientsHolder.new(total_count, sync_timeout: sync_timeout) @results_holder = ResultsHolder.new end def execute Thread.abort_on_exception = true num = 0 tasks = scenario["clients"].flat_map do |client_config| name = client_config.fetch("name") result = Result.new(name) results_holder << result Array.new(client_config.fetch("multiplier")) do num += 1 id = "#{name}_#{num}" Thread.new do Task.new(client_config.deep_dup, id: id, colorize: colorize, global_holder: global_holder, result: result, scale: scale, logger: logger) .run(url) end end end tasks.each(&:join) results_holder end private attr_reader :scenario, :url, :scale, :total_count, :global_holder, :results_holder, :logger, :colorize end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
wsdirector-core-1.1.0 | lib/.rbnext/3.1/wsdirector/runner.rb |
wsdirector-core-1.0.3 | lib/.rbnext/3.1/wsdirector/runner.rb |
wsdirector-core-1.0.2 | lib/.rbnext/3.1/wsdirector/runner.rb |