Class: Mutalisk::RunnerThread

Inherits:
Object
  • Object
show all
Defined in:
lib/mutalisk/runner_thread.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, pipe, id) ⇒ RunnerThread

Returns a new instance of RunnerThread.



6
7
8
9
10
11
12
13
14
# File 'lib/mutalisk/runner_thread.rb', line 6

def initialize(options, pipe, id)
  @options = options
  @connections = []
  @responses = []

  @pipe = pipe
  @interrupted = false
  @thread_id = id
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



3
4
5
# File 'lib/mutalisk/runner_thread.rb', line 3

def results
  @results
end

#thread_idObject (readonly)

Returns the value of attribute thread_id.



4
5
6
# File 'lib/mutalisk/runner_thread.rb', line 4

def thread_id
  @thread_id
end

Instance Method Details

#joinObject



38
39
40
41
42
# File 'lib/mutalisk/runner_thread.rb', line 38

def join
  @thread.join

  Stats.collect(@responses.map(&:to_h))
end

#startObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mutalisk/runner_thread.rb', line 16

def start
  @t0 = Time.now

  @thread = Thread.new {
    # slow start
    until @connections.size == @options[:connections]
      spawn_connection
      send_requests
      check_response
    end

    # full speed
    loop do
      send_requests
      check_response
      break if times_up? or @interrupted
    end

    generate_report
  }
end