PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/test/functional/ft_0_worker.rb

http://github.com/jmettraux/ruote
Ruby | 171 lines | 100 code | 63 blank | 8 comment | 3 complexity | d067a05ca5d277e2381fca648b7433b9 MD5 | raw file
  1. #
  2. # testing ruote
  3. #
  4. # Fri May 15 09:51:28 JST 2009
  5. #
  6. require File.expand_path('../base', __FILE__)
  7. class FtWorkerTest < Test::Unit::TestCase
  8. include FunctionalBase
  9. def test_launch_terminate
  10. pdef = Ruote.process_definition do
  11. end
  12. wfid = @dashboard.launch(pdef)
  13. r = @dashboard.wait_for(wfid)
  14. assert_equal 'terminated', r['action']
  15. #puts; logger.log.each { |e| p e }; puts
  16. assert_equal %w[ launch terminated ], logger.log.map { |e| e['action'] }
  17. end
  18. def test_stop_worker
  19. sleep 0.010 # warm up time
  20. assert_equal 'running', @dashboard.context.worker.state
  21. @dashboard.shutdown
  22. assert_equal 'stopped', @dashboard.context.worker.state
  23. pdef = Ruote.process_definition do; end
  24. @dashboard.launch(pdef)
  25. Thread.pass
  26. #assert_equal 1, @dashboard.storage.get_many('msgs').size
  27. # won't work with the latest ruote-redis implementations
  28. assert_equal 1, @dashboard.storage.get_msgs.size
  29. end
  30. def test_remaining_messages
  31. @dashboard.register_participant :alfred, Ruote::NullParticipant
  32. pdef = Ruote.process_definition do
  33. end
  34. assert_trace '', pdef
  35. sleep 0.300
  36. assert_equal 0, @dashboard.storage.get_msgs.size
  37. end
  38. def test_stop_workers_not_enabled
  39. assert_raise(RuntimeError) do
  40. @dashboard.worker_state = 'stopped'
  41. end
  42. end
  43. def test_pause_workers
  44. @dashboard.context['worker_state_enabled'] = true
  45. pdef = Ruote.define do
  46. 10.times { echo 'a' }
  47. end
  48. wfid = @dashboard.launch(pdef)
  49. @dashboard.worker_state = 'paused'
  50. s = @tracer.to_a.size
  51. assert s < 10
  52. sleep 0.500
  53. assert @tracer.to_a.size < 10
  54. assert_equal s, @tracer.to_a.size
  55. assert_equal 'paused', @dashboard.worker_state
  56. @dashboard.worker_state = 'running'
  57. @dashboard.wait_for('terminated')
  58. assert_equal 10, @tracer.to_a.size
  59. assert_equal 'running', @dashboard.worker_state
  60. end
  61. def test_stop_workers
  62. @dashboard.context['worker_state_enabled'] = true
  63. pdef = Ruote.define do
  64. 10.times { echo 'a' }
  65. end
  66. assert_equal 'running', @dashboard.context.worker.state
  67. wfid = @dashboard.launch(pdef)
  68. @dashboard.worker_state = 'stopped'
  69. s = @tracer.to_a.size
  70. assert s < 10
  71. sleep 0.500
  72. assert @tracer.to_a.size < 10
  73. assert_equal s, @tracer.to_a.size
  74. assert_equal 'stopped', @dashboard.worker_state
  75. assert_equal 'stopped', @dashboard.context.worker.state
  76. end
  77. def test_worker_thread_ruote_worker
  78. assert_equal @dashboard.worker, @dashboard.worker.run_thread['ruote_worker']
  79. end
  80. def test_handle_step_error_and_error_handler
  81. $err = nil
  82. $msg = nil
  83. class << @dashboard.worker
  84. def handle_step_error(err, msg)
  85. $err = err
  86. $msg = msg
  87. end
  88. end
  89. class << @dashboard.storage
  90. alias original_put_msg put_msg
  91. def put_msg(action, details)
  92. raise 'out of order' if action == 'error_intercepted'
  93. original_put_msg(action, details)
  94. end
  95. end
  96. wfid = @dashboard.launch(Ruote.define do
  97. error 'pure fail'
  98. end)
  99. 77.times { break if $msg; sleep 0.100 }
  100. assert_equal 'error_intercepted', $msg['action']
  101. assert_equal 'Ruote::ForcedError', $msg['error']['class']
  102. assert_equal 'pure fail', $msg['error']['message']
  103. assert_equal wfid, $msg['wfid']
  104. assert_equal '0_0', $msg['fei']['expid']
  105. assert_equal RuntimeError, $err.class
  106. assert_equal 'out of order', $err.message
  107. end
  108. end