Class: Tester::Runner

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Runner

Returns a new instance of Runner.



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

def initialize(options)
  @config = (KVS['config'] || {}).merge(options)
  @checker = Checker.new(@config[:branch])
end

Instance Attribute Details

#checkerObject (readonly)

Returns the value of attribute checker.



7
8
9
# File 'lib/tester/runner.rb', line 7

def checker
  @checker
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/tester/runner.rb', line 7

def config
  @config
end

#startedObject

Returns the value of attribute started.



8
9
10
# File 'lib/tester/runner.rb', line 8

def started
  @started
end

#testingObject

Returns the value of attribute testing.



8
9
10
# File 'lib/tester/runner.rb', line 8

def testing
  @testing
end

Class Method Details

.start(options) ⇒ Object



3
4
5
# File 'lib/tester/runner.rb', line 3

def self.start(options)
  self.new(options).start
end

Instance Method Details

#startObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tester/runner.rb', line 15

def start
  return if started
  Thread.start do
    loop do
      begin
        test_if_updated
      rescue Exception => e
        puts "#{e.message}\n  #{e.backtrace.join("\n  ")}"
      ensure
        sleep config[:interval]
      end
    end
  end
  self.started = true
end

#test(hash) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tester/runner.rb', line 42

def test(hash)
  process = TestProcess.new(config[:test_command])
  process.start
  puts "#{hash} => #{process.status}"
  puts process.output
  Log[hash] = process.to_hash.merge(
                :hash => hash,
                :created_at => Time.now,
                :branch => config[:branch]
              )
end

#test_if_updatedObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/tester/runner.rb', line 31

def test_if_updated
  checker.if_updated do |hash|
    begin
      self.testing = true
      test(hash)
    ensure
      self.testing = false
    end
  end
end