Class: SippyCup::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/sippy_cup/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scenario, opts = {}) ⇒ Runner

Create a runner from a scenario

Parameters:

  • scenario (Scenario, XMLScenario)

    The scenario to execute

  • opts (Hash) (defaults to: {})

    Options to modify the runner

Options Hash (opts):

  • :full_sipp_output (optional, true, false)

    Whether or not to copy SIPp’s stdout/stderr to the parent process. Defaults to true.

  • :logger (optional, Logger)

    A logger to use in place of the internal logger to STDOUT.

  • :command (optional, String)

    The command to execute. This is mostly available for testing.



21
22
23
24
25
26
27
28
29
30
# File 'lib/sippy_cup/runner.rb', line 21

def initialize(scenario, opts = {})
  @scenario = scenario
  @scenario_options = @scenario.scenario_options

  defaults = { full_sipp_output: true }
  @options = defaults.merge(opts)

  @command = @options[:command]
  @logger = @options[:logger] || Logger.new(STDOUT)
end

Instance Attribute Details

#sipp_pidObject

Returns the value of attribute sipp_pid.



10
11
12
# File 'lib/sippy_cup/runner.rb', line 10

def sipp_pid
  @sipp_pid
end

Instance Method Details

#runObject

Runs the loaded scenario using SIPp



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sippy_cup/runner.rb', line 35

def run
  @input_files = @scenario.to_tmpfiles

  @logger.info "Preparing to run SIPp command: #{command}"

  execute_with_redirected_streams

  wait unless @options[:async]
ensure
  cleanup_input_files unless @options[:async]
end

#stopObject

Tries to stop SIPp by killing the target PID



53
54
55
# File 'lib/sippy_cup/runner.rb', line 53

def stop
  Process.kill "KILL", @sipp_pid if @sipp_pid
end

#waitObject

Waits for the runner to finish execution

Returns:

  • Boolean true if execution succeeded without any failed calls, false otherwise



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/sippy_cup/runner.rb', line 69

def wait
  exit_status = Process.wait2 @sipp_pid.to_i
  @err_rd.close if @err_rd
  @stdout_rd.close if @stdout_rd
  final_result = process_exit_status exit_status, @stderr_buffer
  if final_result
    @logger.info "Test completed successfully!"
  else
    @logger.info "Test completed successfully but some calls failed."
  end
  @logger.info "Statistics logged at #{File.expand_path @scenario_options[:stats_file]}" if @scenario_options[:stats_file]

  final_result
ensure
  cleanup_input_files
end