test/functional/base.rb in ruote-2.1.11 vs test/functional/base.rb in ruote-2.2.0
- old
+ new
@@ -8,19 +8,34 @@
require 'fileutils'
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'
+require 'ruote'
+trap 'USR2' do
+
+ require 'irb'
+ require 'irb/completion'
+
+ IRB.setup(nil)
+ ws = IRB::WorkSpace.new(binding)
+ irb = IRB::Irb.new(ws)
+ IRB::conf[:MAIN_CONTEXT] = irb.context
+ irb.eval_input
+end
+
+puts "pid #{$$}"
+
+
module FunctionalBase
def setup
+ p self.class if ARGV.include?('-T') or ARGV.include?('-N')
+
#require 'ruote/util/look'
#Ruote::Look.dump_lsof
#Ruote::Look.dump_lsof_count
#
# uncomment this when "too many open files"
@@ -29,17 +44,25 @@
Ruote::Engine.new(
Ruote::Worker.new(
determine_storage(
's_logger' => [ 'ruote/log/test_logger', 'Ruote::TestLogger' ])))
- #p @engine.storage.class
+ $_test = self
+ $_engine = @engine
+ #
+ # handy when hijacking (https://github.com/ileitch/hijack)
+ # or flinging USR2 at the test process
@tracer = Tracer.new
+ tracer = @tracer
+ @engine.context.instance_eval { @tracer = tracer }
+
@engine.add_service('tracer', @tracer)
+ @engine.add_service('stash', {})
- noisy if ARGV.include?('-n')
+ noisy if ARGV.include?('-N')
#noisy # uncommented, it makes all the tests noisy
end
def teardown
@@ -47,39 +70,50 @@
@engine.shutdown
@engine.context.storage.purge!
@engine.context.storage.close if @engine.context.storage.respond_to?(:close)
end
- def assert_log_count (count, &block)
+ def stash
+ @engine.context.stash
+ end
+
+ def assert_log_count(count, &block)
+
c = @engine.context.logger.log.select(&block).size
#logger.to_stdout if ( ! @engine.context[:noisy]) && c != count
assert_equal count, c
end
# assert_trace(*expected_traces, pdef)
# assert_trace(*expected_traces, fields, pdef)
#
- def assert_trace (*args)
+ def assert_trace(*args)
+ if args.last == :clear
+ args.pop
+ @tracer.clear
+ end
+
pdef = args.pop
fields = args.last.is_a?(Hash) ? args.pop : {}
expected_traces = args.collect { |et| et.is_a?(Array) ? et.join("\n") : et }
wfid = @engine.launch(pdef, fields)
- wait_for(wfid)
+ r = wait_for(wfid)
- #yield(@engine) if block_given?
-
assert_engine_clean(wfid)
+ trace = r['workitem']['fields']['_trace']
+ trace = trace ? trace.join('') : @tracer.to_s
+
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?
+ ok, nok = expected_traces.partition { |et| trace == et }
+ assert_equal(nok.first, trace) if ok.empty?
end
assert(true)
# so that the assertion count matches
@@ -91,28 +125,28 @@
@engine.context.logger
end
protected
- def noisy (on=true)
+ def noisy(on=true)
puts "\nnoisy " + caller[0] if on
@engine.context.logger.noisy = true
end
- def wait_for (*wfid_or_part)
+ def wait_for(*wfid_or_part)
@engine.wait_for(*wfid_or_part)
end
- def assert_engine_clean (wfid)
+ def assert_engine_clean(wfid)
assert_no_errors(wfid)
assert_no_remaining_expressions(wfid)
end
- def assert_no_errors (wfid)
+ def assert_no_errors(wfid)
errors = @engine.storage.get_many('errors', /#{wfid}$/)
return if errors.size == 0
@@ -129,11 +163,11 @@
puts_trace_so_far
flunk 'remaining process error(s)'
end
- def assert_no_remaining_expressions (wfid)
+ def assert_no_remaining_expressions(wfid)
expcount = @engine.storage.get_many('expressions').size
return if expcount == 0
tf, _, tn = caller[2].split(':')
@@ -167,10 +201,18 @@
puts '--->8---'
puts
end
end
+# Re-opening workitem for a shortcut to a '_trace' field
+#
+class Ruote::Workitem
+ def trace
+ @h['fields']['_trace'] ||= []
+ end
+end
+
class Tracer
attr_reader :s
def initialize
super
@s = ''
@@ -185,10 +227,10 @@
@s << s
end
def clear
@s = ''
end
- def puts (s)
+ def puts(s)
@s << "#{s}\n"
end
end