test/restart_cron_test.rb in openwferu-0.9.16 vs test/restart_cron_test.rb in openwferu-0.9.17
- old
+ new
@@ -4,15 +4,19 @@
# John Mettraux at openwfe.org
#
# Sun Oct 29 15:41:44 JST 2006
#
+require 'rubygems'
+
require 'test/unit'
+require 'fileutils'
+
require 'openwfe/workitem'
require 'openwfe/engine/file_persisted_engine'
-require 'openwfe/expressions/raw_prog'
+require 'openwfe/def'
require 'rutest_utils'
include OpenWFE
@@ -21,62 +25,106 @@
#def setup
# @engine = $WORKFLOW_ENGINE_CLASS.new()
#end
- #def teardown
- #end
+ def teardown
+ FileUtils.rm_rf 'work'
+ end
+ # test 0
+
class RestartDefinition0 < ProcessDefinition
- #def make
- # process_definition :name => "rs0", :revision => "0" do
- cron :tab => "* * * * *", :name => "//cron" do
- #participant :cron_event_restart
- cron_event_restart
- end
- # end
- #end
+ cron :tab => "* * * * *", :name => "//mycron" do
+ cron_event_restart
+ end
end
- def test_restart_0
+ def test_0
- engine = FilePersistedEngine.new
+ dotest RestartDefinition0
- count = 0
+ assert_equal(
+ 1, @engine.get_expression_storage.size,
+ "\n\n" + @engine.get_expression_storage.to_s)
+ end
- participant = lambda do
- #puts "______________________ :cron_event_restart"
- count = count + 1
+ # test 1
+
+ class RestartDefinition1 < ProcessDefinition
+ concurrence do
+ cron :tab => "* * * * *", :name => "mycron" do
+ cron_event_restart
+ end
+ participant :ref => "nada"
end
- engine.register_participant(:cron_event_restart, &participant)
+ end
- engine.launch(RestartDefinition0)
+ def test_1
- sleep(60)
+ dotest RestartDefinition1
- engine.stop()
+ assert_equal(
+ 6, @engine.get_expression_storage.size,
+ "\n\n" + @engine.get_expression_storage.to_s)
+ end
- #puts "___restarting to new engine"
+ protected
- old_engine = engine
- engine = FilePersistedEngine.new
+ def dotest (definition)
- engine.register_participant(:cron_event_restart, &participant)
+ @engine = new_engine
- engine.reload
- #
- # very important
+ feis = []
- sleep(60)
+ participant = lambda do |wi|
+ feis << wi.fei.dup
+ end
+ @engine.register_participant :cron_event_restart, &participant
+ @engine.register_participant :nada, NullParticipant
- engine.stop()
+ @engine.launch definition
- #puts "_count : #{count}"
+ sleep 60
- assert \
- count == 2,
- "the cron expression should have counted to 2, "+
- "but it counted to #{count}"
- end
+ @engine.stop
+
+ assert_equal 1, @engine.get_scheduler.cron_job_count
+ assert_equal 1, feis.size
+
+ assert_equal ".0", feis[0].wfid[-2, 2]
+
+ #puts "___restarting to new engine"
+
+ #old_engine = @engine
+ new_engine
+
+ @engine.register_participant :cron_event_restart, &participant
+ @engine.register_participant :nada, NullParticipant
+
+ @engine.reload
+ #
+ # very important
+
+ sleep 60
+
+ assert_equal(
+ 1, @engine.get_scheduler.cron_job_count, "wrong cron job count")
+
+ @engine.stop
+
+ assert_equal 2, feis.size
+ assert_not_equal feis[0].wfid, feis[1].wfid
+
+ assert feis[0].wfid[-1, 1].to_i < feis[1].wfid[-1, 1].to_i
+ end
+
+ def new_engine
+
+ @engine = FilePersistedEngine.new
+ #engine = CachedFilePersistedEngine.new
+
+ #$OWFE_LOG.level = Logger::DEBUG
+ end
end