Skip to content

Commit

Permalink
Block reporting infrastructure
Browse files Browse the repository at this point in the history
Added Collector, an event reporter that collects test run states and
Summary a block reporter that summarizes the run.
Cheat and use the Summary reporter to define the exit value
changed some message keys to symbols (the idea being that symbols are
guaranteed to define message types and are part of the message contract
- pretty half-baked atm)
  • Loading branch information
damphyr committed Mar 6, 2015
1 parent e39b32a commit bf558ee
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 30 deletions.
4 changes: 2 additions & 2 deletions lib/rutema/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def application_flow
if @check
#run just the check test
if @configuration.check
@engine.run(@configuration.check)
exit @engine.run(@configuration.check)
else
raise Rutema::RutemaError,"There is no check test defined in the configuration."
end
else
#run everything
@engine.run(@test_identifier)
exit @engine.run(@test_identifier)
end
end
end
Expand Down
28 changes: 21 additions & 7 deletions lib/rutema/core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ def run test_identifier=nil
end
message("end")
@dispatcher.exit
@dispatcher.report(tests)
end
def parse test_identifier=nil
specs=[]
#so, while we are parsing, we have a list of tests
#we're either parsing all of the tests, or just one
#make sure the one test is on the list
if test_identifier
p File.expand_path(test_identifier)
p @configuration.tests
if @configuration.tests.include?(File.expand_path(test_identifier))
specs<<parse_specification(File.expand_path(test_identifier))
else
Expand Down Expand Up @@ -118,15 +117,18 @@ def instantiate_class definition,configuration
end
end
class Dispatcher
INTERVAL=0.1
INTERVAL=0.01
def initialize queue,configuration
@queue = queue
@queues = {}
@streaming_reporters=[]
@block_reporters=[]
@collector=Rutema::Reporters::Collector.new(nil,self)
if configuration.reporters
@streaming_reporters,@block_reporters=configuration.reporters.collect{ |r| instantiate_reporter(r,configuration) }.compact.partition{|rep| rep.respond_to?(:update)}
@streaming_reporters,_=configuration.reporters.collect{ |r| instantiate_reporter(r,configuration) }.compact.partition{|rep| rep.respond_to?(:update)}
@block_reporters,_=configuration.reporters.collect{ |r| instantiate_reporter(r,configuration) }.compact.partition{|rep| rep.respond_to?(:report)}
end
@streaming_reporters<<@collector
end
def subscribe identifier
@queues[identifier]=Queue.new
Expand All @@ -143,17 +145,29 @@ def run!
end
end
def report specs
flush
@block_reporters.each do |r|
r.report(specs,@collector.states,@collector.errors)
end
Reporters::Summary.new(nil,self).report(specs,@collector.states,@collector.errors)
end
def exit
if @thread
flush
@streaming_reporters.each {|r| r.exit}
Thread.kill(@thread)
end
end
private
def flush
if @thread
while @queue.size>0 do
dispatch()
sleep INTERVAL
end
@streaming_reporters.each {|r| r.exit}
Thread.kill(@thread)
end
end
private
def instantiate_reporter definition,configuration
if definition[:class]
klass=definition[:class]
Expand Down
55 changes: 42 additions & 13 deletions lib/rutema/core/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class BlockReporter
def initialize configuration,dispatcher
@configuration=configuration
end
def report specifications,runner_states,parse_errors
def report specifications,states,errors
end
end
class EventReporter
Expand Down Expand Up @@ -45,23 +45,52 @@ def exit
end
end

class Collector<EventReporter
attr_reader :errors,:states
def initialize params,dispatcher
super(params,dispatcher)
@errors=[]
@states={}
end

def update data
if data[:error]
@errors<<data
elsif data[:test] && data['status']
@states[data[:test]]||=[]
@states[data[:test]]<<data
end
end
end
class Console<EventReporter
def update data
if data["test"] && data["phase"]
puts ">#{data["phase"]} #{data["test"]}"
elsif data[:message]
if data[:test]
if data[:error]
puts ">ERROR: #{data[:error]}"
elsif data[:test]
if data["phase"]
puts ">#{data["phase"]} #{data[:test]}"
elsif data[:message]
puts ">#{data[:test]} step #{data[:message]}"
else
puts ">#{data[:message]}"
elsif data["status"]==:error
puts ">FATAL: #{data[:test]}(#{data["number"]}) failed"
puts data.fetch("out","")
puts data.fetch("error","")
end
elsif data[:error]
puts ">ERROR: #{data[:error]}"
elsif data["status"]==:error
puts ">FATAL: #{data["test"]}(#{data["number"]}) failed"
puts data.fetch("out","")
puts data.fetch("error","")
elsif data[:message]
puts ">#{data[:message]}"
end
end
end
class Summary<BlockReporter
def report specs,states,errors
failures=0
states.each do |k,v|
failures+=1 if v.last['status']==:error
end
puts "#{errors.size} errors. #{states.size} test cases executed. #{failures} failed"
return failures
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions lib/rutema/core/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ def initialize context,queue
end

def run spec
state={'start_time'=>Time.now, "sequence_id"=>@number_of_runs,"test"=>spec.name}
state={'start_time'=>Time.now, "sequence_id"=>@number_of_runs,:test=>spec.name}
steps=[]
status=:success
message('test'=>spec.name,'phase'=>'started')
message(:test=>spec.name,'phase'=>'started')
if @setup
message('test'=>spec.name,'phase'=>'setup')
message(:test=>spec.name,'phase'=>'setup')
executed_steps,status=run_scenario("setup",@setup.scenario,@context)
steps+=executed_steps
end
if status!=:error
message('test'=>spec.name,'phase'=>'running')
message(:test=>spec.name,'phase'=>'running')
executed_steps,status=run_scenario(spec.name,spec.scenario,@context)
steps+=executed_steps
end
state['status']=status
if @teardown
message('test'=>spec.name,'phase'=>'teardown')
message(:test=>spec.name,'phase'=>'teardown')
executed_steps,status=run_scenario("teardown",@teardown.scenario,@context)
end
message('test'=>spec.name,'phase'=>'finished')
message(:test=>spec.name,'phase'=>'finished')
state["stop_time"]=Time.now
state['steps']=steps
@number_of_runs+=1
Expand All @@ -54,9 +54,9 @@ def run_scenario name,scenario,meta
status=:error
else
stps.each do |s|
message('test'=>name,:message=>s.to_s)
message(:test=>name,:message=>s.to_s)
executed_steps<<run_step(s,meta)
message('test'=>name,'number'=>s.number,'status'=>s.status,'out'=>s.output,'err'=>s.error,'duration'=>s.exec_time)
message(:test=>name,'number'=>s.number,'status'=>s.status,'out'=>s.output,'err'=>s.error,'duration'=>s.exec_time)
status=s.status
break if :error==s.status
end
Expand Down

0 comments on commit bf558ee

Please sign in to comment.