#_ # Testing OpenWFE # # John Mettraux at openwfe.org # # Sun Oct 29 15:41:44 JST 2006 # # somewhere between Philippina and the Japan # require 'test/unit' require 'openwfe/workitem' require 'openwfe/engine/engine' require 'openwfe/rudefinitions' require 'openwfe/participants/participants' require 'rutest_utils' include OpenWFE #$SLEEP_TIME = 0.100 $WORKFLOW_ENGINE_CLASS = Engine persistence = ENV["__persistence__"] require "openwfe/engine/file_persisted_engine" if persistence if persistence == "pure-persistence" #$SLEEP_TIME = 0.999 $WORKFLOW_ENGINE_CLASS = FilePersistedEngine elsif persistence == "cached-persistence" #$SLEEP_TIME = 0.250 $WORKFLOW_ENGINE_CLASS = CachedFilePersistedEngine end puts puts "testing with engine of class " + $WORKFLOW_ENGINE_CLASS.to_s puts module FlowTestBase attr_reader \ :engine, :tracer def setup @engine = $WORKFLOW_ENGINE_CLASS.new() @engine.application_context[:ruby_eval_allowed] = true @tracer = Tracer.new @engine.application_context["__tracer"] = @tracer @engine.register_participant('pp-workitem') do |workitem| puts require 'pp'; pp workitem puts end @engine.register_participant('pp-fields') do |workitem| workitem.attributes.keys.sort.each do |field| next if field == "___map_type" or field == "__result__" next if field == "params" @tracer << "#{field}: #{workitem.attributes[field]}\n" end @tracer << "--\n" end @engine.register_participant('test-.*', PrintParticipant.new()) @engine.register_participant('block-participant') do |workitem| @tracer << "the block participant received a workitem" @tracer << "\n" end @engine.register_participant('p-toto') do |workitem| @tracer << "toto" end end def teardown @engine.stop if @engine end protected def print_exp_list (l) puts l.each do |fexp| puts " - #{fexp.fei.to_debug_s}" end puts end def name_of_test s = caller(1)[0] i = s.index('`') #s = s[i+1..s.length-2] s = s[i+6..s.length-2] return s end # # dotest() # def dotest (flowDef, expectedTrace, join=false, allowRemainingExpressions=false) @tracer.clear li = if flowDef.kind_of? OpenWFE::LaunchItem flowDef else OpenWFE::LaunchItem.new(flowDef) end fei = @engine.launch(li) #if join == true # @engine.get_scheduler.join_until_no_more_jobs #elsif join.is_a?(Numeric) # sleep join #end #if join.is_a?(Numeric) # sleep join #elsif join == true # @engine.wait_for_engine #else # sleep $SLEEP_TIME #end if join.is_a?(Numeric) sleep join else @engine.wait_for fei end trace = @tracer.to_s #puts "...'#{trace}' ?= '#{expectedTrace}'" if expectedTrace.kind_of?(Array) result = false expectedTrace.each do |etrace| result = (result or (trace == etrace)) end unless result puts puts ">#{trace}<" puts end assert \ result, "flow failed : trace doesn't correspond to any expected traces" elsif expectedTrace.kind_of? Regexp assert \ trace.match(expectedTrace) else assert \ trace == expectedTrace, """flow failed : '#{trace}' != '#{expectedTrace}' """ end if allowRemainingExpressions engine.get_expression_storages.each do |storage| storage.purge end return end exp_storage = engine.get_expression_storage if exp_storage.length != 1 puts puts " remaining expressions : #{exp_storage.length}" puts puts exp_storage.to_s puts end assert \ exp_storage.length == 1, "there are expressions remaining in the expression pool " + "(#{exp_storage.length})" return fei end end