Class: TTK::Strategies::KillAll

Inherits:
Strategy show all
Includes:
Concrete
Defined in:
lib/ttk/strategies/KillAll.rb

Instance Attribute Summary

Attributes inherited from Strategy

#status, #symtbl

Instance Method Summary collapse

Methods inherited from Strategy

#abort, #assign, #clean_instance_variables, #display_unexpected_exc, #display_unexpected_synflow_exc, #fail, #initialize, #initialize_flow_factory, #pass, #raise_error, #reject, #run, #running?, #skip, #skip_if_cached, #strategy, #strategy=, #symbols=, #testify, #timeout=, #to_s, #wclass=

Constructor Details

This class inherits a constructor from TTK::Strategies::Strategy

Instance Method Details

#assertionObject



40
41
42
43
# File 'lib/ttk/strategies/KillAll.rb', line 40

def assertion
  pass if @pids.empty?
  fail "I killed some process #{@pids.inspect}"
end

#epilogueObject



45
46
47
48
49
50
# File 'lib/ttk/strategies/KillAll.rb', line 45

def epilogue 
  unless @pids.empty?
    @log.process = @pids
    sleep 0.2
  end
end

#prologueObject



14
15
16
17
# File 'lib/ttk/strategies/KillAll.rb', line 14

def prologue 
  super
  @pids = []
end

#run_implObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ttk/strategies/KillAll.rb', line 19

def run_impl 
  IO.popen('ps a') do |ps|
    ps.readline
    ps.each do |line|
      if line =~ /^\s*(\d+)(?:\s+\S+){3}\s+(.*)$/
        pid, name = $1.to_i, $2
        if name =~ @regexp
          @pids << pid
          begin
            Process.kill(@signal, pid)
          rescue
            raise RuntimeError, "Cannot kill #{name}:#{pid}"
          end
        end
      else
        raise RuntimeError, 'bad ps output'
      end
    end
  end
end