test/functional/base.rb in ruote-0.9.20 vs test/functional/base.rb in ruote-2.1.1

- old
+ new

@@ -1,198 +1,187 @@ # -# Testing Ruote (OpenWFEru) +# testing ruote # -# John Mettraux at openwfe.org -# # Sat Sep 20 23:40:10 JST 2008 # -require File.dirname(__FILE__) + '/../test_helper.rb' -require File.dirname(__FILE__) + '/engine_helper.rb' +require 'fileutils' -require 'openwfe/engine' +require File.join(File.dirname(__FILE__), '..', 'test_helper.rb') +require File.join(File.dirname(__FILE__), 'storage_helper.rb') +require 'ruote/engine' +require 'ruote/worker' +require 'ruote/parser/ruby_dsl' + module FunctionalBase def setup - @tracer = Tracer.new + #require 'ruote/util/look' + #Ruote::Look.dump_lsof + #Ruote::Look.dump_lsof_count - ac = {} + @engine = + Ruote::Engine.new( + Ruote::Worker.new( + determine_storage( + 's_logger' => [ 'ruote/log/test_logger', 'Ruote::TestLogger' ]))) - class << ac - alias :old_put :[]= - def []= (k, v) - raise("!!!!! #{k.class}\n#{k.inspect}") \ - if k.class != String and k.class != Symbol - old_put(k, v) - end - end - # - # useful for tracking misuses of the application context + @tracer = Tracer.new - ac['__tracer'] = @tracer - ac[:ruby_eval_allowed] = true - ac[:definition_in_launchitem_allowed] = true - - @engine = determine_engine_class(ac).new(ac) - - @terminated_processes = [] - @engine.get_expression_pool.add_observer(:terminate) do |c, fe, wi| - @terminated_processes << fe.fei.wfid - #p [ :terminated, @terminated_processes ] - end + @engine.add_service('tracer', @tracer) end def teardown - $OWFE_LOG.level = Logger::INFO - @engine.stop + @engine.shutdown + @engine.context.storage.purge! end - # - # returns true when running on a Ruby 1.8.x like interpreter - # - def ruby18 + def assert_log_count (count, &block) - RUBY_VERSION.match(/^1\.8\./) + c = @engine.context.logger.log.select(&block).size + + #logger.to_stdout if ( ! @engine.context[:noisy]) && c != count + + assert_equal count, c end + # assert_trace(pdef, *expected_traces) + # assert_trace(pdef, fields, *expected_traces) # - # launch_thing is a process definition or a launch item - # - def assert_trace (launch_thing, expected_trace, opts={}) + def assert_trace (pdef, *expected_traces) - fei = @engine.launch(launch_thing, opts[:launch_opts] || {}) + fields = expected_traces.first.is_a?(Hash) ? expected_traces.shift : {} - wait(fei, opts) + expected_traces = expected_traces.collect do |et| + et.is_a?(Array) ? et.join("\n") : et + end - yield(@engine) if block_given? + wfid = @engine.launch(pdef, fields) - assert_engine_clean(fei, opts) + wait_for(wfid) - assert_equal(expected_trace, @tracer.to_s) if expected_trace + #yield(@engine) if block_given? - purge_engine unless opts[:no_purge] + assert_engine_clean(wfid) - fei - end + if expected_traces.length > 0 + ok, nok = expected_traces.partition { |et| @tracer.to_s == et } + assert_equal(nok.first, @tracer.to_s) if ok.empty? + end - protected + assert(true) + # so that the assertion count matches - def log_level_to_debug + wfid + end - $OWFE_LOG.level = Logger::DEBUG + def logger + + @engine.context.logger end - def wait (fei, opts={}) + protected - #opts[:wait] ? - # @engine.wait_for(fei) : - # sleep(opts[:after] || 0.350) + def noisy (on=true) - Thread.pass - return if @terminated_processes.include?(fei.wfid) - @engine.wait_for(fei) + puts "\nnoisy " + caller[0] if on + @engine.context.logger.noisy = true end - def assert_engine_clean (fei=nil, opts={}) + def wait_for (*wfid_or_part) - assert_no_errors(fei, opts) - assert_no_remaining_expressions(fei, opts) + @engine.context.logger.wait_for(*wfid_or_part) end - def assert_no_errors (fei, opts) + def assert_engine_clean (wfid) - return if opts[:ignore_errors] + assert_no_errors(wfid) + assert_no_remaining_expressions(wfid) + end - ps = if fei - @engine.process_status(fei.wfid) - else - @engine.process_statuses.values.first - end + def assert_no_errors (wfid) - return unless ps - return if ps.errors.size == 0 + errors = @engine.storage.get_many('errors', /#{wfid}$/) - # TODO : implement 'banner' function + return if errors.size == 0 + puts puts '-' * 80 - puts 'caught process error(s)' + puts 'remaining process error(s)' puts - ps.errors.values.each do |e| - puts " ** error : #{e.error_class} \"#{e.stacktrace}\"" + errors.each do |e| + puts " ** #{e['message']}" + puts e['trace'] end puts '-' * 80 puts_trace_so_far - flunk 'caught process error(s)' + flunk 'remaining process error(s)' end - def assert_no_remaining_expressions (fei, opts) + def assert_no_remaining_expressions (wfid) - return if opts[:ignore_errors] + expcount = @engine.storage.get_many('expressions').size + return if expcount == 0 - expcount = @engine.get_expression_storage.size - return if expcount == 1 + tf, _, tn = caller[2].split(':') - 50.times { Thread.pass } - expcount = @engine.get_expression_storage.size - return if expcount == 1 - + puts puts '-' * 80 puts 'too many expressions left in storage' puts - puts "this test's wfid : #{fei.wfid}" + puts "this test : #{tf}" + puts " #{tn}" puts + puts "this test's wfid : #{wfid}" + puts puts 'left :' puts - puts @engine.get_expression_storage.to_s + puts @engine.context.storage.dump('expressions') puts puts '-' * 80 puts_trace_so_far flunk 'too many expressions left in storage' end - def purge_engine - - @engine.application_context.values.each do |s| - s.purge if s.respond_to?(:purge) - end - FileUtils.rm_rf('work') - end - def puts_trace_so_far #puts '. ' * 40 puts 'trace so far' puts '---8<---' puts @tracer.to_s puts '--->8---' - puts '. ' * 40 + puts end end class Tracer + attr_reader :s def initialize super - @trace = '' + @s = '' end def to_s - @trace.to_s.strip + @s.to_s.strip end + def to_a + to_s.split("\n") + end def << s - @trace << s + @s << s end def clear - @trace = '' + @s = '' end - def puts s - @trace << "#{s}\n" + def puts (s) + @s << "#{s}\n" end end