roby 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. data/History.txt +7 -5
  2. data/Manifest.txt +91 -16
  3. data/README.txt +24 -24
  4. data/Rakefile +92 -64
  5. data/app/config/app.yml +42 -43
  6. data/app/config/init.rb +26 -0
  7. data/benchmark/alloc_misc.rb +123 -0
  8. data/benchmark/discovery_latency.rb +67 -0
  9. data/benchmark/garbage_collection.rb +48 -0
  10. data/benchmark/genom.rb +31 -0
  11. data/benchmark/transactions.rb +62 -0
  12. data/bin/roby +1 -1
  13. data/bin/roby-log +16 -6
  14. data/doc/guide/.gitignore +2 -0
  15. data/doc/guide/config.yaml +34 -0
  16. data/doc/guide/ext/init.rb +14 -0
  17. data/doc/guide/ext/previous_next.rb +40 -0
  18. data/doc/guide/ext/rdoc_links.rb +33 -0
  19. data/doc/guide/index.rdoc +16 -0
  20. data/doc/guide/overview.rdoc +62 -0
  21. data/doc/guide/plan_modifications.rdoc +67 -0
  22. data/doc/guide/src/abstraction/achieve_with.page +8 -0
  23. data/doc/guide/src/abstraction/forwarding.page +8 -0
  24. data/doc/guide/src/abstraction/hierarchy.page +19 -0
  25. data/doc/guide/src/abstraction/index.page +28 -0
  26. data/doc/guide/src/abstraction/task_models.page +13 -0
  27. data/doc/guide/src/basics.template +6 -0
  28. data/doc/guide/src/basics/app.page +139 -0
  29. data/doc/guide/src/basics/code_examples.page +33 -0
  30. data/doc/guide/src/basics/dry.page +69 -0
  31. data/doc/guide/src/basics/errors.page +443 -0
  32. data/doc/guide/src/basics/events.page +179 -0
  33. data/doc/guide/src/basics/hierarchy.page +275 -0
  34. data/doc/guide/src/basics/index.page +11 -0
  35. data/doc/guide/src/basics/log_replay/goForward_1.png +0 -0
  36. data/doc/guide/src/basics/log_replay/goForward_2.png +0 -0
  37. data/doc/guide/src/basics/log_replay/goForward_3.png +0 -0
  38. data/doc/guide/src/basics/log_replay/goForward_4.png +0 -0
  39. data/doc/guide/src/basics/log_replay/goForward_5.png +0 -0
  40. data/doc/guide/src/basics/log_replay/hierarchy_error_1.png +0 -0
  41. data/doc/guide/src/basics/log_replay/hierarchy_error_2.png +0 -0
  42. data/doc/guide/src/basics/log_replay/hierarchy_error_3.png +0 -0
  43. data/doc/guide/src/basics/log_replay/plan_repair_1.png +0 -0
  44. data/doc/guide/src/basics/log_replay/plan_repair_2.png +0 -0
  45. data/doc/guide/src/basics/log_replay/plan_repair_3.png +0 -0
  46. data/doc/guide/src/basics/log_replay/plan_repair_4.png +0 -0
  47. data/doc/guide/src/basics/log_replay/roby_log_main_window.png +0 -0
  48. data/doc/guide/src/basics/log_replay/roby_log_relation_window.png +0 -0
  49. data/doc/guide/src/basics/log_replay/roby_replay_event_representation.png +0 -0
  50. data/doc/guide/src/basics/plan_objects.page +71 -0
  51. data/doc/guide/src/basics/relations_display.page +203 -0
  52. data/doc/guide/src/basics/roby_cycle_overview.png +0 -0
  53. data/doc/guide/src/basics/shell.page +102 -0
  54. data/doc/guide/src/basics/summary.page +32 -0
  55. data/doc/guide/src/basics/tasks.page +357 -0
  56. data/doc/guide/src/basics_shell_header.txt +16 -0
  57. data/doc/guide/src/cycle/cycle-overview.png +0 -0
  58. data/doc/guide/src/cycle/cycle-overview.svg +208 -0
  59. data/doc/guide/src/cycle/error_handling.page +168 -0
  60. data/doc/guide/src/cycle/error_instantaneous_repair.png +0 -0
  61. data/doc/guide/src/cycle/error_instantaneous_repair.svg +1224 -0
  62. data/doc/guide/src/cycle/garbage_collection.page +10 -0
  63. data/doc/guide/src/cycle/index.page +23 -0
  64. data/doc/guide/src/cycle/propagation.page +154 -0
  65. data/doc/guide/src/cycle/propagation_diamond.png +0 -0
  66. data/doc/guide/src/cycle/propagation_diamond.svg +1279 -0
  67. data/doc/guide/src/default.css +319 -0
  68. data/doc/guide/src/default.template +74 -0
  69. data/doc/guide/src/htmldoc.metainfo +20 -0
  70. data/doc/guide/src/htmldoc.virtual +18 -0
  71. data/doc/guide/src/images/bodybg.png +0 -0
  72. data/doc/guide/src/images/contbg.png +0 -0
  73. data/doc/guide/src/images/footerbg.png +0 -0
  74. data/doc/guide/src/images/gradient1.png +0 -0
  75. data/doc/guide/src/images/gradient2.png +0 -0
  76. data/doc/guide/src/index.page +7 -0
  77. data/doc/guide/src/introduction/index.page +29 -0
  78. data/doc/guide/src/introduction/install.page +133 -0
  79. data/doc/{papers.rdoc → guide/src/introduction/publications.page} +5 -2
  80. data/doc/{videos.rdoc → guide/src/introduction/videos.page} +4 -2
  81. data/doc/guide/src/plugins/fault_tolerance.page +44 -0
  82. data/doc/guide/src/plugins/index.page +11 -0
  83. data/doc/guide/src/plugins/subsystems.page +45 -0
  84. data/doc/guide/src/relations/dependency.page +89 -0
  85. data/doc/guide/src/relations/index.page +12 -0
  86. data/doc/misc/update_github +24 -0
  87. data/doc/tutorials/02-GoForward.rdoc +3 -3
  88. data/ext/graph/graph.cc +46 -0
  89. data/lib/roby.rb +57 -22
  90. data/lib/roby/app.rb +132 -112
  91. data/lib/roby/app/plugins/rake.rb +21 -0
  92. data/lib/roby/app/rake.rb +0 -7
  93. data/lib/roby/app/run.rb +1 -1
  94. data/lib/roby/app/scripts/distributed.rb +1 -2
  95. data/lib/roby/app/scripts/generate/bookmarks.rb +1 -1
  96. data/lib/roby/app/scripts/results.rb +2 -1
  97. data/lib/roby/app/scripts/run.rb +6 -2
  98. data/lib/roby/app/scripts/shell.rb +11 -11
  99. data/lib/roby/config.rb +1 -1
  100. data/lib/roby/decision_control.rb +62 -3
  101. data/lib/roby/distributed.rb +4 -0
  102. data/lib/roby/distributed/base.rb +8 -0
  103. data/lib/roby/distributed/communication.rb +12 -8
  104. data/lib/roby/distributed/connection_space.rb +61 -44
  105. data/lib/roby/distributed/distributed_object.rb +1 -1
  106. data/lib/roby/distributed/notifications.rb +22 -30
  107. data/lib/roby/distributed/peer.rb +13 -8
  108. data/lib/roby/distributed/proxy.rb +5 -5
  109. data/lib/roby/distributed/subscription.rb +4 -4
  110. data/lib/roby/distributed/transaction.rb +3 -3
  111. data/lib/roby/event.rb +176 -110
  112. data/lib/roby/exceptions.rb +12 -4
  113. data/lib/roby/execution_engine.rb +1604 -0
  114. data/lib/roby/external_process_task.rb +225 -0
  115. data/lib/roby/graph.rb +0 -6
  116. data/lib/roby/interface.rb +221 -137
  117. data/lib/roby/log/console.rb +5 -3
  118. data/lib/roby/log/data_stream.rb +94 -16
  119. data/lib/roby/log/dot.rb +8 -8
  120. data/lib/roby/log/event_stream.rb +13 -3
  121. data/lib/roby/log/file.rb +43 -18
  122. data/lib/roby/log/gui/basic_display_ui.rb +89 -0
  123. data/lib/roby/log/gui/chronicle_view_ui.rb +90 -0
  124. data/lib/roby/log/gui/data_displays.rb +4 -5
  125. data/lib/roby/log/gui/data_displays_ui.rb +146 -0
  126. data/lib/roby/log/gui/relations.rb +18 -18
  127. data/lib/roby/log/gui/relations_ui.rb +120 -0
  128. data/lib/roby/log/gui/relations_view_ui.rb +144 -0
  129. data/lib/roby/log/gui/replay.rb +41 -13
  130. data/lib/roby/log/gui/replay_controls.rb +3 -0
  131. data/lib/roby/log/gui/replay_controls.ui +133 -110
  132. data/lib/roby/log/gui/replay_controls_ui.rb +249 -0
  133. data/lib/roby/log/hooks.rb +19 -18
  134. data/lib/roby/log/logger.rb +7 -6
  135. data/lib/roby/log/notifications.rb +4 -4
  136. data/lib/roby/log/plan_rebuilder.rb +20 -22
  137. data/lib/roby/log/relations.rb +44 -16
  138. data/lib/roby/log/server.rb +1 -4
  139. data/lib/roby/log/timings.rb +88 -19
  140. data/lib/roby/plan-object.rb +135 -11
  141. data/lib/roby/plan.rb +408 -224
  142. data/lib/roby/planning/loops.rb +32 -25
  143. data/lib/roby/planning/model.rb +157 -51
  144. data/lib/roby/planning/task.rb +47 -20
  145. data/lib/roby/query.rb +128 -92
  146. data/lib/roby/relations.rb +254 -136
  147. data/lib/roby/relations/conflicts.rb +6 -9
  148. data/lib/roby/relations/dependency.rb +358 -0
  149. data/lib/roby/relations/ensured.rb +0 -1
  150. data/lib/roby/relations/error_handling.rb +0 -1
  151. data/lib/roby/relations/events.rb +0 -2
  152. data/lib/roby/relations/executed_by.rb +26 -11
  153. data/lib/roby/relations/planned_by.rb +14 -14
  154. data/lib/roby/robot.rb +46 -0
  155. data/lib/roby/schedulers/basic.rb +34 -0
  156. data/lib/roby/standalone.rb +4 -0
  157. data/lib/roby/standard_errors.rb +21 -15
  158. data/lib/roby/state/events.rb +5 -4
  159. data/lib/roby/support.rb +107 -6
  160. data/lib/roby/task-operations.rb +23 -19
  161. data/lib/roby/task.rb +522 -148
  162. data/lib/roby/task_index.rb +80 -0
  163. data/lib/roby/test/common.rb +283 -44
  164. data/lib/roby/test/distributed.rb +53 -37
  165. data/lib/roby/test/testcase.rb +9 -204
  166. data/lib/roby/test/tools.rb +3 -3
  167. data/lib/roby/transactions.rb +154 -111
  168. data/lib/roby/transactions/proxy.rb +40 -7
  169. data/manifest.xml +20 -0
  170. data/plugins/fault_injection/README.txt +0 -3
  171. data/plugins/fault_injection/Rakefile +2 -8
  172. data/plugins/fault_injection/app.rb +1 -1
  173. data/plugins/fault_injection/fault_injection.rb +3 -3
  174. data/plugins/fault_injection/test/test_fault_injection.rb +19 -25
  175. data/plugins/subsystems/README.txt +0 -3
  176. data/plugins/subsystems/Rakefile +2 -7
  177. data/plugins/subsystems/app.rb +27 -16
  178. data/plugins/subsystems/test/app/config/init.rb +3 -0
  179. data/plugins/subsystems/test/app/planners/main.rb +1 -1
  180. data/plugins/subsystems/test/app/tasks/services.rb +1 -1
  181. data/plugins/subsystems/test/test_subsystems.rb +23 -16
  182. data/test/distributed/test_communication.rb +32 -15
  183. data/test/distributed/test_connection.rb +28 -26
  184. data/test/distributed/test_execution.rb +59 -54
  185. data/test/distributed/test_mixed_plan.rb +34 -34
  186. data/test/distributed/test_plan_notifications.rb +26 -26
  187. data/test/distributed/test_protocol.rb +57 -48
  188. data/test/distributed/test_query.rb +11 -7
  189. data/test/distributed/test_remote_plan.rb +71 -71
  190. data/test/distributed/test_transaction.rb +50 -47
  191. data/test/mockups/external_process +28 -0
  192. data/test/planning/test_loops.rb +163 -119
  193. data/test/planning/test_model.rb +3 -3
  194. data/test/planning/test_task.rb +27 -7
  195. data/test/relations/test_conflicts.rb +3 -3
  196. data/test/relations/test_dependency.rb +324 -0
  197. data/test/relations/test_ensured.rb +2 -2
  198. data/test/relations/test_executed_by.rb +94 -19
  199. data/test/relations/test_planned_by.rb +11 -9
  200. data/test/suite_core.rb +6 -3
  201. data/test/suite_distributed.rb +1 -0
  202. data/test/suite_planning.rb +1 -0
  203. data/test/suite_relations.rb +2 -2
  204. data/test/tasks/test_external_process.rb +126 -0
  205. data/test/{test_thread_task.rb → tasks/test_thread_task.rb} +17 -20
  206. data/test/test_bgl.rb +21 -1
  207. data/test/test_event.rb +229 -155
  208. data/test/test_exceptions.rb +79 -80
  209. data/test/test_execution_engine.rb +987 -0
  210. data/test/test_gui.rb +1 -1
  211. data/test/test_interface.rb +11 -5
  212. data/test/test_log.rb +18 -7
  213. data/test/test_log_server.rb +1 -0
  214. data/test/test_plan.rb +229 -395
  215. data/test/test_query.rb +193 -35
  216. data/test/test_relations.rb +88 -8
  217. data/test/test_state.rb +55 -37
  218. data/test/test_support.rb +1 -1
  219. data/test/test_task.rb +371 -218
  220. data/test/test_testcase.rb +32 -16
  221. data/test/test_transactions.rb +211 -170
  222. data/test/test_transactions_proxy.rb +37 -19
  223. metadata +169 -71
  224. data/.gitignore +0 -29
  225. data/doc/styles/allison.css +0 -314
  226. data/doc/styles/allison.js +0 -316
  227. data/doc/styles/allison.rb +0 -276
  228. data/doc/styles/jamis.rb +0 -593
  229. data/lib/roby/control.rb +0 -746
  230. data/lib/roby/executives/simple.rb +0 -30
  231. data/lib/roby/propagation.rb +0 -562
  232. data/lib/roby/relations/hierarchy.rb +0 -239
  233. data/lib/roby/transactions/updates.rb +0 -139
  234. data/test/relations/test_hierarchy.rb +0 -158
  235. data/test/test_control.rb +0 -399
  236. data/test/test_propagation.rb +0 -210
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.expand_path('..', File.dirname(__FILE__))
1
+ $LOAD_PATH.unshift File.expand_path(File.join('..', '..', 'lib'), File.dirname(__FILE__))
2
2
  require 'roby/test/common'
3
3
  require 'roby/test/tasks/simple_task'
4
4
 
@@ -8,7 +8,7 @@ class TC_PlannedBy < Test::Unit::TestCase
8
8
  PlannedBy = Roby::TaskStructure::PlannedBy
9
9
  SimpleTask = Roby::Test::SimpleTask
10
10
  def test_replace
11
- task, p1, p2 = prepare_plan :discover => 3
11
+ task, p1, p2 = prepare_plan :add => 3
12
12
  task.planned_by p1
13
13
 
14
14
  assert_raises(ArgumentError) { task.planned_by p2 }
@@ -24,24 +24,26 @@ class TC_PlannedBy < Test::Unit::TestCase
24
24
  task = Roby::Task.new
25
25
  planner = Roby::Test::SimpleTask.new
26
26
  task.planned_by planner
27
- plan.permanent(task)
27
+ plan.add_permanent(task)
28
28
 
29
- assert_equal([], PlannedBy.check_planning(plan))
29
+ assert_equal([], plan.check_structure.to_a)
30
30
  planner.start!
31
- assert_equal([], PlannedBy.check_planning(plan))
31
+ assert_equal([], plan.check_structure.to_a)
32
32
  planner.success!
33
- assert_equal([], PlannedBy.check_planning(plan))
33
+ assert_equal([], plan.check_structure.to_a)
34
34
 
35
35
  task.remove_planning_task planner
36
36
  planner = Roby::Test::SimpleTask.new
37
37
  task.planned_by planner
38
38
 
39
- assert_equal([], PlannedBy.check_planning(plan))
39
+ assert_equal([], plan.check_structure.to_a)
40
40
  planner.start!
41
- assert_equal([], PlannedBy.check_planning(plan))
41
+ assert_equal([], plan.check_structure.to_a)
42
42
  planner.failed!
43
43
 
44
- error = *PlannedBy.check_planning(plan)
44
+ errors = plan.check_structure.to_a
45
+ assert_equal 1, errors.size
46
+ error = errors.first.first.exception
45
47
  assert_kind_of(Roby::PlanningFailedError, error)
46
48
  assert_equal(planner, error.failed_task)
47
49
  assert_equal(task, error.planned_task)
@@ -1,3 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
1
2
  require 'test_support'
2
3
 
3
4
  require 'test_bgl'
@@ -6,19 +7,21 @@ require 'test_event'
6
7
  require 'test_task'
7
8
  require 'test_state'
8
9
 
9
- require 'test_propagation'
10
+ require 'test_execution_engine'
10
11
  require 'test_exceptions'
11
12
 
12
13
  require 'test_plan'
13
14
  require 'test_query'
14
15
  require 'test_transactions'
15
16
  require 'test_transactions_proxy'
16
- require 'test_thread_task'
17
+
18
+ require 'tasks/test_thread_task'
19
+
20
+ require 'test_testcase'
17
21
 
18
22
  require 'suite_planning'
19
23
  require 'suite_relations'
20
24
 
21
- require 'test_control'
22
25
  require 'test_interface'
23
26
  require 'test_log'
24
27
 
@@ -1,3 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
1
2
  require 'distributed/test_communication'
2
3
  require 'distributed/test_connection'
3
4
  require 'distributed/test_execution'
@@ -1,3 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
1
2
  require 'planning/test_model'
2
3
  require 'planning/test_task'
3
4
  require 'planning/test_loops'
@@ -1,8 +1,8 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
1
2
  require 'test_relations'
2
- require 'relations/test_hierarchy'
3
+ require 'relations/test_dependency'
3
4
  require 'relations/test_executed_by'
4
5
  require 'relations/test_planned_by'
5
6
  require 'relations/test_conflicts'
6
-
7
7
  require 'relations/test_ensured'
8
8
 
@@ -0,0 +1,126 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.join('..', '..', 'lib'), File.dirname(__FILE__))
2
+ require 'roby/test/common'
3
+ require 'roby/external_process_task'
4
+ require 'roby/test/tasks/simple_task'
5
+ require 'roby/test/tasks/empty_task'
6
+
7
+ class TC_ThreadTask < Test::Unit::TestCase
8
+ include Roby::Test
9
+
10
+ MOCKUP = File.expand_path(
11
+ File.join("..", "mockups", "external_process"),
12
+ File.dirname(__FILE__))
13
+
14
+ class MockupTask < Roby::ExternalProcessTask
15
+ event :stop do
16
+ FileUtils.touch "/tmp/external_process_mockup_stop"
17
+ end
18
+ end
19
+
20
+ def assert_polling_successful(timeout, sleep = 0.05)
21
+ now = Time.now
22
+ while (Time.now - now) < timeout
23
+ if yield
24
+ return
25
+ end
26
+ end
27
+ flunk "reached timeout"
28
+ end
29
+
30
+ def test_nominal
31
+ plan.add_permanent(task = ExternalProcessTask.new(:command_line => [MOCKUP, "--no-output"]))
32
+ engine.run
33
+ engine.once { task.start! }
34
+
35
+ assert_polling_successful(5) { task.success? }
36
+ end
37
+
38
+ def test_nominal_array_with_one_element
39
+ plan.add_permanent(task = ExternalProcessTask.new(:command_line => [MOCKUP]))
40
+ engine.run
41
+ engine.once { task.start! }
42
+
43
+ assert_polling_successful(5) { task.success? }
44
+ end
45
+
46
+ def test_nominal_no_array
47
+ plan.add_permanent(task = ExternalProcessTask.new(:command_line => MOCKUP))
48
+ engine.run
49
+ engine.once { task.start! }
50
+
51
+ assert_polling_successful(5) { task.success? }
52
+ end
53
+
54
+ def test_inexistent_program
55
+ plan.add_permanent(task = ExternalProcessTask.new(:command_line => ['does_not_exist', "--error"]))
56
+ engine.run
57
+ engine.once { task.start! }
58
+
59
+ assert_polling_successful(5) { task.failed? }
60
+ assert_equal 1, task.event(:failed).last.context.first.exitstatus
61
+ end
62
+
63
+ def test_failure
64
+ plan.add_permanent(task = ExternalProcessTask.new(:command_line => [MOCKUP, "--error"]))
65
+ engine.run
66
+ engine.once { task.start! }
67
+
68
+ assert_polling_successful(5) { task.failed? }
69
+ assert_equal 1, task.event(:failed).last.context.first.exitstatus
70
+ end
71
+
72
+ def test_signaling
73
+ plan.add_permanent(task = ExternalProcessTask.new(:command_line => [MOCKUP, "--block"]))
74
+ engine.run
75
+ engine.once { task.start! }
76
+ assert_polling_successful(5) { task.running? }
77
+
78
+ Process.kill 'KILL', task.pid
79
+ assert_polling_successful(5) { task.failed? }
80
+ assert task.event(:signaled).happened?
81
+
82
+ ev = task.event(:signaled).last
83
+ assert_equal 9, ev.context.first.termsig
84
+ end
85
+
86
+ def do_redirection(expected)
87
+ plan.add_permanent(task = ExternalProcessTask.new(:command_line => [MOCKUP]))
88
+ yield(task)
89
+ engine.run
90
+ engine.once { task.start! }
91
+
92
+ assert_polling_successful(5) { task.success? }
93
+
94
+ assert File.exists?("mockup-#{task.pid}.log")
95
+ File.read("mockup-#{task.pid}.log")
96
+
97
+ ensure
98
+ FileUtils.rm_f "mockup-#{task.pid}.log"
99
+ end
100
+
101
+ def test_stdout_redirection
102
+ do_redirection `#{MOCKUP}` do |task|
103
+ task.redirect_output :stdout => 'mockup-%p.log'
104
+ end
105
+ end
106
+
107
+ def test_stderr_redirection
108
+ do_redirection `#{MOCKUP}` do |task|
109
+ task.command_line << "--stderr"
110
+ task.redirect_output :stderr => 'mockup-%p.log'
111
+ end
112
+ end
113
+
114
+ def test_common_redirection
115
+ output = do_redirection(nil) do |task|
116
+ task.command_line << "--common"
117
+ task.redirect_output 'mockup-%p.log'
118
+ end
119
+
120
+
121
+ expected = `#{MOCKUP} --common 2>&1`
122
+ assert_equal expected, output
123
+ end
124
+ end
125
+
126
+
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.expand_path('..', File.dirname(__FILE__))
1
+ $LOAD_PATH.unshift File.expand_path(File.join('..', '..', 'lib'), File.dirname(__FILE__))
2
2
  require 'roby/test/common'
3
3
  require 'roby/thread_task'
4
4
  require 'roby/test/tasks/simple_task'
@@ -7,6 +7,15 @@ require 'roby/test/tasks/empty_task'
7
7
  class TC_ThreadTask < Test::Unit::TestCase
8
8
  include Roby::Test
9
9
 
10
+ # Starts +task+ and waits for the thread to end
11
+ def wait_thread_end(task)
12
+ task.start!
13
+ while task.thread
14
+ process_events
15
+ sleep 0.1
16
+ end
17
+ end
18
+
10
19
  def test_normal
11
20
  model = Class.new(Roby::ThreadTask) do
12
21
  implementation do
@@ -14,12 +23,8 @@ class TC_ThreadTask < Test::Unit::TestCase
14
23
  end
15
24
  end
16
25
 
17
- plan.insert(task = model.new)
18
- task.start!
19
- while task.thread
20
- process_events
21
- sleep 0.1
22
- end
26
+ plan.add_mission(task = model.new)
27
+ wait_thread_end(task)
23
28
 
24
29
  assert task.success?
25
30
  assert_equal 1, task.result
@@ -27,19 +32,15 @@ class TC_ThreadTask < Test::Unit::TestCase
27
32
 
28
33
  def test_implementation_fails
29
34
  Thread.abort_on_exception = false
30
- Roby.control.abort_on_exception = false
35
+ Roby.app.abort_on_exception = false
31
36
  model = Class.new(Roby::ThreadTask) do
32
37
  implementation do
33
38
  raise ArgumentError, "blaaaaaaaaah"
34
39
  end
35
40
  end
36
41
 
37
- plan.discover(task = model.new)
38
- task.start!
39
- while task.thread
40
- process_events
41
- sleep 0.1
42
- end
42
+ plan.add_permanent(task = model.new)
43
+ wait_thread_end(task)
43
44
 
44
45
  assert task.failed?
45
46
  assert_kind_of ArgumentError, task.event(:failed).last.context.first
@@ -58,12 +59,8 @@ class TC_ThreadTask < Test::Unit::TestCase
58
59
  end
59
60
  end
60
61
 
61
- plan.discover(task = model.new)
62
- task.start!
63
- while task.thread
64
- process_events
65
- sleep 0.1
66
- end
62
+ plan.add(task = model.new)
63
+ wait_thread_end(task)
67
64
 
68
65
  assert task.failed?
69
66
  assert_kind_of Interrupt, task.event(:failed).last.context.first
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.expand_path('..', File.dirname(__FILE__))
1
+ $LOAD_PATH.unshift File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
2
2
  require 'roby/test/common'
3
3
  require 'enumerator'
4
4
  require 'flexmock'
@@ -75,6 +75,26 @@ class TC_BGL < Test::Unit::TestCase
75
75
  assert_equal(2, v4[v3, graph])
76
76
  end
77
77
 
78
+ def test_clear
79
+ g1, g2 = Graph.new, Graph.new
80
+
81
+ vertices = (1..3).map do
82
+ g1.insert(v = Vertex.new)
83
+ g2.insert(v)
84
+
85
+ assert g1.include?(v)
86
+ assert g2.include?(v)
87
+ v
88
+ end
89
+
90
+ g1.clear
91
+ vertices.each do |v|
92
+ assert !g1.include?(v)
93
+ assert g2.include?(v)
94
+ assert_equal [g2], v.enum_for(:each_graph).to_a
95
+ end
96
+ end
97
+
78
98
  def test_edge_objects
79
99
  g1, g2 = Graph.new, Graph.new
80
100
 
@@ -1,4 +1,4 @@
1
- $LOAD_PATH.unshift File.expand_path('..', File.dirname(__FILE__))
1
+ $LOAD_PATH.unshift File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
2
2
  require 'roby/test/common'
3
3
  require 'flexmock'
4
4
  require 'roby/test/tasks/simple_task'
@@ -6,17 +6,28 @@ require 'roby/test/tasks/simple_task'
6
6
  require 'roby'
7
7
  class TC_Event < Test::Unit::TestCase
8
8
  include Roby::Test
9
+ def setup
10
+ super
11
+ Roby.app.filter_backtraces = false
12
+ end
13
+
14
+ def test_no_plan
15
+ event = EventGenerator.new { }
16
+ assert(!event.executable?)
17
+ assert_raises(Roby::EventNotExecutable) { event.emit }
18
+ assert_raises(Roby::EventNotExecutable) { event.call }
9
19
 
10
- def test_properties
11
- event = EventGenerator.new
12
- assert(! event.controlable?)
20
+ plan.add(event)
21
+ assert(event.executable?)
22
+ end
13
23
 
24
+ def test_controlable_events
14
25
  event = EventGenerator.new(true)
15
26
  assert(event.controlable?)
16
27
 
17
28
  # Check command & emission behavior for controlable events
18
29
  FlexMock.use do |mock|
19
- plan.discover(event = EventGenerator.new { |context| mock.call_handler(context); event.emit(*context) })
30
+ plan.add(event = EventGenerator.new { |context| mock.call_handler(context); event.emit(*context) })
20
31
  event.on { |event| mock.event_handler(event.context) }
21
32
 
22
33
  assert(event.controlable?)
@@ -24,19 +35,22 @@ class TC_Event < Test::Unit::TestCase
24
35
  mock.should_receive(:event_handler).once.with([42])
25
36
  event.call(42)
26
37
  end
38
+ end
27
39
 
40
+ def test_contingent_events
28
41
  # Check emission behavior for non-controlable events
29
42
  FlexMock.use do |mock|
30
43
  event = EventGenerator.new
31
- plan.discover(event)
44
+ plan.add(event)
32
45
  event.on { |event| mock.event(event.context) }
33
46
  mock.should_receive(:event).once.with([42])
34
47
  event.emit(42)
35
48
  end
36
49
  end
37
50
 
38
- def test_executable
39
- plan.discover(event = EventGenerator.new(true))
51
+ def test_explicit_executable_flag
52
+ plan.add(event = EventGenerator.new(true))
53
+ assert(event.executable?)
40
54
  event.executable = false
41
55
  assert_raises(EventNotExecutable) { event.call(nil) }
42
56
  assert_raises(EventNotExecutable) { event.emit(nil) }
@@ -45,14 +59,14 @@ class TC_Event < Test::Unit::TestCase
45
59
  assert_nothing_raised { event.call(nil) }
46
60
  assert_nothing_raised { event.emit(nil) }
47
61
 
48
- plan.discover(other = EventGenerator.new(true))
62
+ plan.add(other = EventGenerator.new(true))
49
63
  other.executable = false
50
- event.on other
64
+ event.signals other
51
65
  assert_raises(EventNotExecutable) { event.call(nil) }
52
66
 
53
67
  event.remove_signal(other)
54
68
  assert_nothing_raised { event.emit(nil) }
55
- other.emit_on event
69
+ event.forward_to other
56
70
  assert_raises(EventNotExecutable) { event.call(nil) }
57
71
 
58
72
  event.remove_forwarding(other)
@@ -61,9 +75,8 @@ class TC_Event < Test::Unit::TestCase
61
75
  assert_original_error(EventNotExecutable, EventHandlerError) { event.call(nil) }
62
76
  end
63
77
 
64
- def test_emit_failed
65
- event = EventGenerator.new
66
- plan.discover(event)
78
+ def test_emit_failed_raises
79
+ plan.add(event = EventGenerator.new)
67
80
  assert_original_error(NilClass, EmissionFailed) { event.emit_failed }
68
81
  assert_original_error(NilClass, EmissionFailed) { event.emit_failed("test") }
69
82
 
@@ -82,9 +95,11 @@ class TC_Event < Test::Unit::TestCase
82
95
  assert_equal(event, e.failed_generator)
83
96
  assert( e.message =~ /: test$/ )
84
97
  end
98
+ end
85
99
 
100
+ def test_emit_failed_removes_pending
86
101
  event = EventGenerator.new { }
87
- plan.discover(event)
102
+ plan.add(event)
88
103
  event.call
89
104
  assert(event.pending?)
90
105
  assert_raises(EmissionFailed) { event.emit_failed }
@@ -93,8 +108,8 @@ class TC_Event < Test::Unit::TestCase
93
108
 
94
109
  def test_propagation_id
95
110
  e1, e2, e3 = (1..3).map { EventGenerator.new(true) }.
96
- each { |e| plan.discover(e) }
97
- e1.on e2
111
+ each { |e| plan.add(e) }
112
+ e1.signals e2
98
113
  e1.emit(nil)
99
114
  assert_equal(e1.last.propagation_id, e2.last.propagation_id)
100
115
 
@@ -107,21 +122,82 @@ class TC_Event < Test::Unit::TestCase
107
122
  end
108
123
 
109
124
 
110
- def test_signal_relation
125
+ def test_signals_without_delay
111
126
  e1, e2 = EventGenerator.new(true), Roby::EventGenerator.new(true)
112
- plan.discover([e1, e2])
127
+ plan.add([e1, e2])
113
128
 
114
- e1.on e2
115
- assert( e1.child_object?( e2, EventStructure::Signal ))
116
- assert( e2.parent_object?( e1, EventStructure::Signal ))
129
+ e1.signals e2
117
130
 
118
- e1.call(nil)
119
- assert(e2.happened?)
131
+ assert( e1.child_object?( e2, EventStructure::Signal ))
132
+ assert( e2.parent_object?( e1, EventStructure::Signal ))
133
+
134
+ e1.call(nil)
135
+ assert(e2.happened?)
136
+ end
137
+
138
+ def test_forward_to_without_delay
139
+ e1, e2 = EventGenerator.new, Roby::EventGenerator.new
140
+ plan.add([e1, e2])
141
+
142
+ e1.forward_to e2
143
+
144
+ assert( e1.child_object?( e2, EventStructure::Forwarding ))
145
+ assert( e2.parent_object?( e1, EventStructure::Forwarding ))
146
+
147
+ e1.emit(nil)
148
+ assert(e2.happened?)
149
+ end
150
+
151
+ # b.emit_on(a) is replaced by a.forward_to(b)
152
+ def test_deprecated_emit_on
153
+ e1, e2 = EventGenerator.new, Roby::EventGenerator.new
154
+ plan.add([e1, e2])
155
+
156
+ deprecated_feature do
157
+ e2.emit_on e1
158
+ end
159
+
160
+ assert( e1.child_object?( e2, EventStructure::Forwarding ))
161
+ assert( e2.parent_object?( e1, EventStructure::Forwarding ))
162
+
163
+ e1.emit(nil)
164
+ assert(e2.happened?)
165
+ end
166
+
167
+ # forward has been renamed into #forward_to
168
+ def test_deprecated_forward
169
+ e1, e2 = EventGenerator.new, Roby::EventGenerator.new
170
+ plan.add([e1, e2])
171
+
172
+ deprecated_feature do
173
+ e1.forward e2
174
+ end
175
+
176
+ assert( e1.child_object?( e2, EventStructure::Forwarding ))
177
+ assert( e2.parent_object?( e1, EventStructure::Forwarding ))
178
+
179
+ e1.emit(nil)
180
+ assert(e2.happened?)
181
+ end
182
+
183
+ def test_deprecated_on
184
+ e1, e2 = EventGenerator.new(true), Roby::EventGenerator.new(true)
185
+ plan.add([e1, e2])
186
+
187
+ deprecated_feature do
188
+ e1.on e2
189
+ end
190
+
191
+ assert( e1.child_object?( e2, EventStructure::Signal ))
192
+ assert( e2.parent_object?( e1, EventStructure::Signal ))
193
+
194
+ e1.call(nil)
195
+ assert(e2.happened?)
120
196
  end
121
197
 
122
198
  def test_handlers
123
199
  e1, e2 = EventGenerator.new(true), Roby::EventGenerator.new(true)
124
- plan.discover([e1, e2])
200
+ plan.add([e1, e2])
125
201
  e1.on { e2.call(nil) }
126
202
 
127
203
  FlexMock.use do |mock|
@@ -135,45 +211,45 @@ class TC_Event < Test::Unit::TestCase
135
211
  end
136
212
  end
137
213
 
138
- def test_event_sources
139
- events = (1..6).map { EventGenerator.new(true) }
140
- forwarded, signalled,
141
- emitted_in_handler, called_in_handler,
142
- emitted_in_command, called_in_command = *events
143
-
144
- src = EventGenerator.new(true)
145
- e = EventGenerator.new do
146
- called_in_command.call
147
- emitted_in_command.emit
148
- e.emit
149
- end
150
- events << e
151
-
152
- plan.discover(events)
153
-
154
- e.forward forwarded
155
- e.on signalled
156
- e.on do
157
- called_in_handler.call
158
- emitted_in_handler.emit
159
- end
160
-
161
- src.on e
162
- src.call
163
- assert_equal([e.last], forwarded.last.sources.to_a)
164
- assert_equal([e.last], emitted_in_handler.last.sources.to_a)
165
- assert_equal([], emitted_in_command.last.sources.to_a)
166
- assert_equal([], signalled.last.sources.to_a)
167
- assert_equal([], called_in_handler.last.sources.to_a)
168
- assert_equal([], called_in_command.last.sources.to_a)
214
+ def common_test_source_setup(forwarding)
215
+ src = EventGenerator.new(true)
216
+ e = EventGenerator.new(true)
217
+ target = EventGenerator.new(true)
218
+ plan.add([src, e, target])
219
+ src.signals e
220
+ yield(e, target)
221
+ src.call
222
+ if forwarding
223
+ assert_equal([e.last], target.last.sources.to_a)
224
+ else
225
+ assert_equal([], target.last.sources.to_a)
226
+ end
227
+ end
228
+ def test_forward_source
229
+ common_test_source_setup(true) { |e, target| e.forward_to target }
230
+ end
231
+ def test_forward_in_handler_source
232
+ common_test_source_setup(true) { |e, target| e.on { target.emit } }
233
+ end
234
+ def test_forward_in_command_source
235
+ common_test_source_setup(false) { |e, target| e.command = lambda { |_| target.emit; e.emit } }
236
+ end
237
+ def test_signal_source
238
+ common_test_source_setup(false) { |e, target| e.signals target }
239
+ end
240
+ def test_signal_in_handler_source
241
+ common_test_source_setup(false) { |e, target| e.on { target.call } }
242
+ end
243
+ def test_signal_in_command_source
244
+ common_test_source_setup(false) { |e, target| e.command = lambda { |_| target.call; e.emit } }
169
245
  end
170
246
 
171
247
  def test_simple_signal_handler_ordering
172
248
  e1, e2, e3 = (1..3).map { EventGenerator.new(true) }.
173
- each { |e| plan.discover(e) }
174
- e1.on(e2)
249
+ each { |e| plan.add(e) }
250
+ e1.signals(e2)
175
251
  e1.on { e2.remove_signal(e3) }
176
- e2.on(e3)
252
+ e2.signals(e3)
177
253
 
178
254
  e1.call(nil)
179
255
  assert( e2.happened? )
@@ -194,7 +270,7 @@ class TC_Event < Test::Unit::TestCase
194
270
  generator = Class.new(EventGenerator) do
195
271
  include mod
196
272
  end.new(true)
197
- plan.discover(generator)
273
+ plan.add(generator)
198
274
 
199
275
  hooks.each do |name|
200
276
  mock.should_receive(name).once.with(generator).ordered
@@ -206,7 +282,7 @@ class TC_Event < Test::Unit::TestCase
206
282
  def test_postpone
207
283
  wait_for = EventGenerator.new(true)
208
284
  event = EventGenerator.new(true)
209
- plan.discover([wait_for, event])
285
+ plan.add([wait_for, event])
210
286
  event.singleton_class.class_eval do
211
287
  define_method(:calling) do |context|
212
288
  super if defined? super
@@ -228,7 +304,7 @@ class TC_Event < Test::Unit::TestCase
228
304
  FlexMock.use do |mock|
229
305
  wait_for = EventGenerator.new(true)
230
306
  event = EventGenerator.new(true)
231
- plan.discover([wait_for, event])
307
+ plan.add([wait_for, event])
232
308
  event.singleton_class.class_eval do
233
309
  define_method(:calling) do |context|
234
310
  super if defined? super
@@ -251,31 +327,18 @@ class TC_Event < Test::Unit::TestCase
251
327
 
252
328
  def test_can_signal
253
329
  a, b = EventGenerator.new(true), EventGenerator.new
254
- plan.discover([a, b])
255
- assert_raises(EventNotControlable) { a.on b }
256
- assert_nothing_raised { a.forward b }
330
+ plan.add([a, b])
331
+ assert_raises(EventNotControlable) { a.signals b }
332
+ assert_nothing_raised { a.forward_to b }
257
333
 
258
334
  a, b = EventGenerator.new(true), EventGenerator.new(true)
259
- plan.discover([a, b])
260
- a.on b
335
+ plan.add([a, b])
336
+ a.signals b
261
337
  def b.controlable?; false end
262
338
 
263
339
  assert_raise(EmissionFailed) { a.call(nil) }
264
340
  end
265
341
 
266
- def test_emit_on
267
- e1, e2 = (1..2).map { EventGenerator.new(true) }.
268
- each { |e| plan.discover(e) }
269
- e1.emit_on e2
270
- FlexMock.use do |mock|
271
- e1.on { mock.e1 }
272
- e2.on { mock.e2 }
273
- mock.should_receive(:e2).once.ordered
274
- mock.should_receive(:e1).once.ordered
275
- e2.call(nil)
276
- end
277
- end
278
-
279
342
  def test_and_generator
280
343
  and_event = AndGenerator.new
281
344
  FlexMock.use do |mock|
@@ -283,7 +346,7 @@ class TC_Event < Test::Unit::TestCase
283
346
  mock.should_receive(:called).once
284
347
 
285
348
  events = 5.enum_for(:times).map { EventGenerator.new(true) }
286
- plan.discover(events)
349
+ plan.add(events)
287
350
  events.each { |ev| and_event << ev }
288
351
 
289
352
  events.each do |ev|
@@ -304,7 +367,7 @@ class TC_Event < Test::Unit::TestCase
304
367
 
305
368
  # Check the behavior of the & operator
306
369
  e1, e2, e3, e4 = (1..4).map { EventGenerator.new(true) }.
307
- each { |e| plan.discover(e) }
370
+ each { |e| plan.add(e) }
308
371
  and_event = e1 & e2
309
372
  and_and = and_event & e3
310
373
  assert_equal([e1, e2].to_set, and_event.waiting.to_set)
@@ -313,10 +376,10 @@ class TC_Event < Test::Unit::TestCase
313
376
 
314
377
  # Check dynamic behaviour
315
378
  a, b, c, d = (1..4).map { EventGenerator.new(true) }.
316
- each { |e| plan.discover(e) }
379
+ each { |e| plan.add(e) }
317
380
  and1 = a & b
318
381
  and2 = and1 & c
319
- and2.on d
382
+ and2.signals d
320
383
  assert_equal([and1], a.enum_for(:each_signal).to_a)
321
384
  assert_equal([and1], b.enum_for(:each_signal).to_a)
322
385
  assert_equal([and2], and1.enum_for(:each_signal).to_a)
@@ -341,7 +404,7 @@ class TC_Event < Test::Unit::TestCase
341
404
  end
342
405
 
343
406
  def test_and_empty
344
- plan.discover(and_event = AndGenerator.new)
407
+ plan.add(and_event = AndGenerator.new)
345
408
 
346
409
  assert(and_event.empty?)
347
410
  and_event << EventGenerator.new(true)
@@ -351,7 +414,7 @@ class TC_Event < Test::Unit::TestCase
351
414
 
352
415
  def test_and_unreachability
353
416
  a, b = (1..2).map { EventGenerator.new(true) }.
354
- each { |e| plan.discover(e) }
417
+ each { |e| plan.add(e) }
355
418
 
356
419
  # Test unreachability
357
420
  ## it is unreachable once emitted, but if_unreachable(true) blocks
@@ -379,7 +442,7 @@ class TC_Event < Test::Unit::TestCase
379
442
 
380
443
  def test_and_reset
381
444
  a, b = (1..2).map { EventGenerator.new(true) }.
382
- each { |e| plan.discover(e) }
445
+ each { |e| plan.add(e) }
383
446
  and_event = (a & b)
384
447
  a.emit(nil)
385
448
 
@@ -406,10 +469,10 @@ class TC_Event < Test::Unit::TestCase
406
469
 
407
470
  def setup_aggregation(mock)
408
471
  e1, e2, m1, m2, m3 = 5.enum_for(:times).map { EventGenerator.new(true) }
409
- plan.discover([e1, e2, m1, m2, m3])
410
- e1.on e2
411
- m1.on m2
412
- m2.on m3
472
+ plan.add([e1, e2, m1, m2, m3])
473
+ e1.signals e2
474
+ m1.signals m2
475
+ m2.signals m3
413
476
 
414
477
  (e1 & e2 & m2).on { mock.and }
415
478
  (e2 | m1).on { mock.or }
@@ -422,7 +485,7 @@ class TC_Event < Test::Unit::TestCase
422
485
  def test_aggregator
423
486
  FlexMock.use do |mock|
424
487
  e1, e2, m1, *_ = setup_aggregation(mock)
425
- e2.on m1
488
+ e2.signals m1
426
489
  mock.should_receive(:or).once
427
490
  mock.should_receive(:and).once
428
491
  mock.should_receive(:and_or).once
@@ -451,7 +514,7 @@ class TC_Event < Test::Unit::TestCase
451
514
 
452
515
  def test_or_generator
453
516
  a, b, c = (1..3).map { EventGenerator.new(true) }.
454
- each { |e| plan.discover(e) }
517
+ each { |e| plan.add(e) }
455
518
 
456
519
  or_event = OrGenerator.new
457
520
  assert(or_event.empty?)
@@ -459,7 +522,7 @@ class TC_Event < Test::Unit::TestCase
459
522
  assert(!or_event.empty?)
460
523
 
461
524
  or_event = (a | b)
462
- or_event.on c
525
+ or_event.signals c
463
526
  assert( a.enum_for(:each_causal_link).find { |ev| ev == or_event } )
464
527
  assert( or_event.enum_for(:each_causal_link).find { |ev| ev == c } )
465
528
  a.call(nil)
@@ -468,7 +531,7 @@ class TC_Event < Test::Unit::TestCase
468
531
  end
469
532
 
470
533
  def test_or_emission
471
- plan.discover(or_event = OrGenerator.new)
534
+ plan.add(or_event = OrGenerator.new)
472
535
  events = (1..4).map { EventGenerator.new(true) }.
473
536
  each { |e| or_event << e }
474
537
 
@@ -483,7 +546,7 @@ class TC_Event < Test::Unit::TestCase
483
546
  end
484
547
 
485
548
  def test_or_reset
486
- plan.discover(or_event = OrGenerator.new)
549
+ plan.add(or_event = OrGenerator.new)
487
550
  events = (1..4).map { EventGenerator.new(true) }.
488
551
  each { |e| or_event << e }
489
552
 
@@ -499,7 +562,7 @@ class TC_Event < Test::Unit::TestCase
499
562
  def test_or_unreachability
500
563
  # Test unreachability properties
501
564
  a, b = (1..3).map { EventGenerator.new(true) }.
502
- each { |e| plan.discover(e) }
565
+ each { |e| plan.add(e) }
503
566
  or_event = (a | b)
504
567
 
505
568
  ## must be unreachable once emitted, but if_unreachable(true) blocks
@@ -526,10 +589,10 @@ class TC_Event < Test::Unit::TestCase
526
589
 
527
590
  def test_until
528
591
  source, sink, filter, limit = 4.enum_for(:times).map { EventGenerator.new(true) }
529
- plan.discover [source, sink, filter, limit]
592
+ plan.add [source, sink, filter, limit]
530
593
 
531
- source.on(filter)
532
- filter.until(limit).on(sink)
594
+ source.signals(filter)
595
+ filter.until(limit).signals(sink)
533
596
 
534
597
  FlexMock.use do |mock|
535
598
  sink.on { mock.passed }
@@ -544,19 +607,19 @@ class TC_Event < Test::Unit::TestCase
544
607
  def test_event_creation
545
608
  # Test for validation of the return value of #event
546
609
  generator = Class.new(EventGenerator) do
547
- def new(context); [Propagation.propagation_id, context] end
610
+ def new(context); [] end
548
611
  end.new(true)
549
- plan.discover(generator)
612
+ plan.add(generator)
550
613
 
551
614
  assert_raises(EmissionFailed) { generator.emit(nil) }
552
615
 
553
616
  generator = Class.new(EventGenerator) do
554
617
  def new(context);
555
618
  event_klass = Struct.new :propagation_id, :context, :generator, :sources
556
- event_klass.new(Propagation.propagation_id, context, self)
619
+ event_klass.new(plan.engine.propagation_id, context, self)
557
620
  end
558
621
  end.new(true)
559
- plan.discover(generator)
622
+ plan.add(generator)
560
623
  assert_nothing_raised { generator.call(nil) }
561
624
  end
562
625
 
@@ -564,10 +627,10 @@ class TC_Event < Test::Unit::TestCase
564
627
  FlexMock.use do |mock|
565
628
  e1 = EventGenerator.new { |context| mock.e1_cmd(context); e1.emit(*context) }
566
629
  e2 = EventGenerator.new { |context| mock.e2_cmd(context); e2.emit(*context) }
567
- e1.on e2
630
+ e1.signals e2
568
631
  e1.on { |event| mock.e1(event.context) }
569
632
  e2.on { |event| mock.e2(event.context) }
570
- plan.discover([e1, e2])
633
+ plan.add([e1, e2])
571
634
 
572
635
  mock.should_receive(:e1_cmd).with([mock]).once
573
636
  mock.should_receive(:e2_cmd).with([mock]).once
@@ -579,10 +642,10 @@ class TC_Event < Test::Unit::TestCase
579
642
  FlexMock.use do |mock|
580
643
  pass_through = EventGenerator.new(true)
581
644
  e2 = EventGenerator.new { |context| mock.e2_cmd(context); e2.emit(*context) }
582
- pass_through.on e2
645
+ pass_through.signals e2
583
646
  pass_through.on { |event| mock.e1(event.context) }
584
647
  e2.on { |event| mock.e2(event.context) }
585
- plan.discover([pass_through, e2])
648
+ plan.add([pass_through, e2])
586
649
 
587
650
  mock.should_receive(:e2_cmd).with([mock]).once
588
651
  mock.should_receive(:e1).with([mock]).once
@@ -593,10 +656,10 @@ class TC_Event < Test::Unit::TestCase
593
656
  FlexMock.use do |mock|
594
657
  e1 = EventGenerator.new { |context| mock.e1_cmd(context); e1.emit(*context) }
595
658
  e2 = EventGenerator.new { |context| mock.e2_cmd(context); e2.emit(*context) }
596
- e1.on e2
659
+ e1.signals e2
597
660
  e1.on { |event| mock.e1(event.context) }
598
661
  e2.on { |event| mock.e2(event.context) }
599
- plan.discover([e1, e2])
662
+ plan.add([e1, e2])
600
663
 
601
664
  mock.should_receive(:e1_cmd).with(nil).once
602
665
  mock.should_receive(:e2_cmd).with(nil).once
@@ -607,7 +670,7 @@ class TC_Event < Test::Unit::TestCase
607
670
  end
608
671
 
609
672
  def test_preconditions
610
- plan.discover(e1 = EventGenerator.new(true))
673
+ plan.add(e1 = EventGenerator.new(true))
611
674
  e1.precondition("context must be non-nil") do |generator, context|
612
675
  context
613
676
  end
@@ -622,27 +685,27 @@ class TC_Event < Test::Unit::TestCase
622
685
  cancel("testing cancel method")
623
686
  end
624
687
  end.new(true)
625
- plan.discover(e1)
688
+ plan.add(e1)
626
689
  assert_raises(EventCanceled) { e1.call(nil) }
627
690
  end
628
691
 
629
692
  def test_related_events
630
693
  e1, e2 = (1..2).map { EventGenerator.new(true) }.
631
- each { |ev| plan.discover(ev) }
694
+ each { |ev| plan.add(ev) }
632
695
 
633
696
  assert_equal([].to_value_set, e1.related_events)
634
- e1.on e2
697
+ e1.signals e2
635
698
  assert_equal([e2].to_value_set, e1.related_events)
636
699
  assert_equal([e1].to_value_set, e2.related_events)
637
700
  end
638
701
 
639
702
  def test_related_tasks
640
703
  e1, e2 = (1..2).map { EventGenerator.new(true) }.
641
- each { |ev| plan.discover(ev) }
704
+ each { |ev| plan.add(ev) }
642
705
  t1 = SimpleTask.new
643
706
 
644
707
  assert_equal([].to_value_set, e1.related_tasks)
645
- e1.on t1.event(:start)
708
+ e1.signals t1.event(:start)
646
709
  assert_equal([t1].to_value_set, e1.related_tasks)
647
710
  end
648
711
 
@@ -652,7 +715,7 @@ class TC_Event < Test::Unit::TestCase
652
715
  ev.emit(*context)
653
716
  mock.called(*context)
654
717
  end
655
- plan.discover(ev)
718
+ plan.add(ev)
656
719
 
657
720
  mock.should_receive(:called).with(42).once
658
721
  ev.call(42)
@@ -666,7 +729,7 @@ class TC_Event < Test::Unit::TestCase
666
729
  def test_set_command
667
730
  FlexMock.use do |mock|
668
731
  ev = EventGenerator.new
669
- plan.discover(ev)
732
+ plan.add(ev)
670
733
  assert(!ev.controlable?)
671
734
 
672
735
  ev.command = lambda { mock.first }
@@ -685,19 +748,25 @@ class TC_Event < Test::Unit::TestCase
685
748
  end
686
749
 
687
750
  def test_once
688
- ev1, ev2 = EventGenerator.new(true), EventGenerator.new(true)
689
- plan.discover([ev1, ev2])
751
+ plan.add(ev = EventGenerator.new(true))
752
+ FlexMock.use do |mock|
753
+ ev.once { mock.called_once }
754
+ mock.should_receive(:called_once).once
755
+
756
+ ev.call
757
+ ev.call
758
+ end
759
+ end
690
760
 
761
+ def test_signal_once
762
+ ev1, ev2 = EventGenerator.new(true), EventGenerator.new(true)
763
+ plan.add([ev1, ev2])
691
764
 
692
765
  FlexMock.use do |mock|
693
- ev1.once(ev2) do
694
- mock.called_once
695
- end
696
-
766
+ ev1.signals_once(ev2)
697
767
  ev2.on { mock.called }
698
768
 
699
769
  mock.should_receive(:called).once
700
- mock.should_receive(:called_once).once
701
770
 
702
771
  ev1.call
703
772
  ev1.call
@@ -706,10 +775,10 @@ class TC_Event < Test::Unit::TestCase
706
775
 
707
776
  def test_forward_once
708
777
  ev1, ev2 = EventGenerator.new(true), EventGenerator.new(true)
709
- plan.discover([ev1, ev2])
778
+ plan.add([ev1, ev2])
710
779
 
711
780
  FlexMock.use do |mock|
712
- ev1.forward_once(ev2)
781
+ ev1.forward_to_once(ev2)
713
782
  ev2.on { mock.called }
714
783
 
715
784
  mock.should_receive(:called).once
@@ -721,16 +790,16 @@ class TC_Event < Test::Unit::TestCase
721
790
 
722
791
  def test_filter
723
792
  ev1, ev_block, ev_value, ev_nil = (1..4).map { EventGenerator.new(true) }.
724
- each { |e| plan.discover(e) }
793
+ each { |e| plan.add(e) }
725
794
 
726
795
  FlexMock.use do |mock|
727
- ev1.filter { |v| mock.filtering(v); v*2 }.on ev_block
796
+ ev1.filter { |v| mock.filtering(v); v*2 }.signals ev_block
728
797
  ev_block.on { |ev| mock.block_filter(ev.context) }
729
798
 
730
- ev1.filter(42).on ev_value
799
+ ev1.filter(42).signals ev_value
731
800
  ev_value.on { |ev| mock.value_filter(ev.context) }
732
801
 
733
- ev1.filter.on ev_nil
802
+ ev1.filter.signals ev_nil
734
803
  ev_nil.on { |ev| mock.nil_filter(ev.context) }
735
804
 
736
805
  mock.should_receive(:filtering).with(21).once
@@ -743,7 +812,7 @@ class TC_Event < Test::Unit::TestCase
743
812
 
744
813
  def test_gather_events
745
814
  e1, e2 = (1..2).map { EventGenerator.new(true) }.
746
- each { |e| plan.discover(e) }
815
+ each { |e| plan.add(e) }
747
816
 
748
817
  collection = []
749
818
 
@@ -774,7 +843,7 @@ class TC_Event < Test::Unit::TestCase
774
843
  master = EventGenerator.new do
775
844
  master.achieve_with slave
776
845
  end
777
- plan.discover([master, slave])
846
+ plan.add([master, slave])
778
847
 
779
848
  master.call
780
849
  assert(!master.happened?)
@@ -786,7 +855,7 @@ class TC_Event < Test::Unit::TestCase
786
855
  master = EventGenerator.new do
787
856
  master.achieve_with slave
788
857
  end
789
- plan.discover([master, slave])
858
+ plan.add([master, slave])
790
859
 
791
860
  master.call
792
861
  assert(!master.happened?)
@@ -797,7 +866,7 @@ class TC_Event < Test::Unit::TestCase
797
866
  master = EventGenerator.new do
798
867
  master.achieve_with(slave) { [21, 42] }
799
868
  end
800
- plan.discover([master, slave])
869
+ plan.add([master, slave])
801
870
 
802
871
  master.call
803
872
  slave.emit
@@ -808,28 +877,28 @@ class TC_Event < Test::Unit::TestCase
808
877
 
809
878
  def test_if_unreachable
810
879
  FlexMock.use do |mock|
811
- plan.discover(ev = EventGenerator.new(true))
880
+ plan.add(ev = EventGenerator.new(true))
812
881
  ev.if_unreachable(false) { mock.called }
813
882
  ev.if_unreachable(true) { mock.canceled_called }
814
883
  ev.call
815
884
 
816
885
  mock.should_receive(:called).once
817
886
  mock.should_receive(:canceled_called).never
818
- plan.garbage_collect
887
+ engine.garbage_collect
819
888
  end
820
889
  end
821
890
 
822
891
  def test_when_unreachable
823
- plan.discover(ev = EventGenerator.new(true))
892
+ plan.add(ev = EventGenerator.new(true))
824
893
  ev.when_unreachable.on { |ev| mock.unreachable_fired }
825
894
  ev.call
826
- plan.garbage_collect
895
+ engine.garbage_collect
827
896
  assert(ev.happened?)
828
897
  end
829
898
 
830
899
  def test_or_if_unreachable
831
- plan.discover(e1 = EventGenerator.new(true))
832
- plan.discover(e2 = EventGenerator.new(true))
900
+ plan.add(e1 = EventGenerator.new(true))
901
+ plan.add(e2 = EventGenerator.new(true))
833
902
  a = e1 | e2
834
903
  FlexMock.use do |mock|
835
904
  a.if_unreachable(false) { mock.called }
@@ -846,8 +915,8 @@ class TC_Event < Test::Unit::TestCase
846
915
 
847
916
  def test_and_if_unreachable
848
917
  FlexMock.use do |mock|
849
- plan.discover(e1 = EventGenerator.new(true))
850
- plan.discover(e2 = EventGenerator.new(true))
918
+ plan.add(e1 = EventGenerator.new(true))
919
+ plan.add(e2 = EventGenerator.new(true))
851
920
  a = e1 & e2
852
921
 
853
922
  a.if_unreachable(false) { mock.called }
@@ -858,8 +927,8 @@ class TC_Event < Test::Unit::TestCase
858
927
  end
859
928
 
860
929
  FlexMock.use do |mock|
861
- plan.discover(e1 = EventGenerator.new(true))
862
- plan.discover(e2 = EventGenerator.new(true))
930
+ plan.add(e1 = EventGenerator.new(true))
931
+ plan.add(e2 = EventGenerator.new(true))
863
932
  a = e1 & e2
864
933
 
865
934
  a.if_unreachable(false) { mock.called }
@@ -871,7 +940,7 @@ class TC_Event < Test::Unit::TestCase
871
940
  end
872
941
 
873
942
  def test_dup
874
- plan.discover(e = EventGenerator.new(true))
943
+ plan.add(e = EventGenerator.new(true))
875
944
 
876
945
  e.call
877
946
  new = e.dup
@@ -881,15 +950,20 @@ class TC_Event < Test::Unit::TestCase
881
950
  end
882
951
 
883
952
  def test_event_after
884
- plan.discover(e = EventGenerator.new(true))
885
- e.call
886
- sleep(0.5)
887
- plan.discover(delayed = e.last.after(1))
888
- delayed.poll
889
- assert(!delayed.happened?)
890
- sleep(0.5)
891
- delayed.poll
892
- assert(delayed.happened?)
953
+ FlexMock.use(Time) do |time_proxy|
954
+ current_time = Time.now + 5
955
+ time_proxy.should_receive(:now).and_return { current_time }
956
+
957
+ plan.add(e = EventGenerator.new(true))
958
+ e.call
959
+ current_time += 0.5
960
+ plan.add(delayed = e.last.after(1))
961
+ delayed.poll
962
+ assert(!delayed.happened?)
963
+ current_time += 0.5
964
+ delayed.poll
965
+ assert(delayed.happened?)
966
+ end
893
967
  end
894
968
  end
895
969