roby 0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +29 -0
- data/History.txt +4 -0
- data/License-fr.txt +519 -0
- data/License.txt +515 -0
- data/Manifest.txt +245 -0
- data/NOTES +4 -0
- data/README.txt +163 -0
- data/Rakefile +161 -0
- data/TODO.txt +146 -0
- data/app/README.txt +24 -0
- data/app/Rakefile +8 -0
- data/app/config/ROBOT.rb +5 -0
- data/app/config/app.yml +91 -0
- data/app/config/init.rb +7 -0
- data/app/config/roby.yml +3 -0
- data/app/controllers/.gitattributes +0 -0
- data/app/controllers/ROBOT.rb +2 -0
- data/app/data/.gitattributes +0 -0
- data/app/planners/ROBOT/main.rb +6 -0
- data/app/planners/main.rb +5 -0
- data/app/scripts/distributed +3 -0
- data/app/scripts/generate/bookmarks +3 -0
- data/app/scripts/replay +3 -0
- data/app/scripts/results +3 -0
- data/app/scripts/run +3 -0
- data/app/scripts/server +3 -0
- data/app/scripts/shell +3 -0
- data/app/scripts/test +3 -0
- data/app/tasks/.gitattributes +0 -0
- data/app/tasks/ROBOT/.gitattributes +0 -0
- data/bin/roby +210 -0
- data/bin/roby-log +168 -0
- data/bin/roby-shell +25 -0
- data/doc/images/event_generalization.png +0 -0
- data/doc/images/exception_propagation_1.png +0 -0
- data/doc/images/exception_propagation_2.png +0 -0
- data/doc/images/exception_propagation_3.png +0 -0
- data/doc/images/exception_propagation_4.png +0 -0
- data/doc/images/exception_propagation_5.png +0 -0
- data/doc/images/replay_handler_error.png +0 -0
- data/doc/images/replay_handler_error_0.png +0 -0
- data/doc/images/replay_handler_error_1.png +0 -0
- data/doc/images/roby_cycle_overview.png +0 -0
- data/doc/images/roby_replay_02.png +0 -0
- data/doc/images/roby_replay_03.png +0 -0
- data/doc/images/roby_replay_04.png +0 -0
- data/doc/images/roby_replay_event_representation.png +0 -0
- data/doc/images/roby_replay_first_state.png +0 -0
- data/doc/images/roby_replay_relations.png +0 -0
- data/doc/images/roby_replay_startup.png +0 -0
- data/doc/images/task_event_generalization.png +0 -0
- data/doc/papers.rdoc +11 -0
- data/doc/styles/allison.css +314 -0
- data/doc/styles/allison.js +316 -0
- data/doc/styles/allison.rb +276 -0
- data/doc/styles/jamis.rb +593 -0
- data/doc/tutorials/01-GettingStarted.rdoc +86 -0
- data/doc/tutorials/02-GoForward.rdoc +220 -0
- data/doc/tutorials/03-PlannedPath.rdoc +268 -0
- data/doc/tutorials/04-EventPropagation.rdoc +236 -0
- data/doc/tutorials/05-ErrorHandling.rdoc +319 -0
- data/doc/tutorials/06-Overview.rdoc +40 -0
- data/doc/videos.rdoc +69 -0
- data/ext/droby/dump.cc +175 -0
- data/ext/droby/extconf.rb +3 -0
- data/ext/graph/algorithm.cc +746 -0
- data/ext/graph/extconf.rb +7 -0
- data/ext/graph/graph.cc +529 -0
- data/ext/graph/graph.hh +183 -0
- data/ext/graph/iterator_sequence.hh +102 -0
- data/ext/graph/undirected_dfs.hh +226 -0
- data/ext/graph/undirected_graph.hh +421 -0
- data/lib/roby.rb +41 -0
- data/lib/roby/app.rb +870 -0
- data/lib/roby/app/rake.rb +56 -0
- data/lib/roby/app/run.rb +14 -0
- data/lib/roby/app/scripts/distributed.rb +13 -0
- data/lib/roby/app/scripts/generate/bookmarks.rb +162 -0
- data/lib/roby/app/scripts/replay.rb +31 -0
- data/lib/roby/app/scripts/results.rb +15 -0
- data/lib/roby/app/scripts/run.rb +26 -0
- data/lib/roby/app/scripts/server.rb +18 -0
- data/lib/roby/app/scripts/shell.rb +88 -0
- data/lib/roby/app/scripts/test.rb +40 -0
- data/lib/roby/basic_object.rb +151 -0
- data/lib/roby/config.rb +5 -0
- data/lib/roby/control.rb +747 -0
- data/lib/roby/decision_control.rb +17 -0
- data/lib/roby/distributed.rb +32 -0
- data/lib/roby/distributed/base.rb +440 -0
- data/lib/roby/distributed/communication.rb +871 -0
- data/lib/roby/distributed/connection_space.rb +592 -0
- data/lib/roby/distributed/distributed_object.rb +206 -0
- data/lib/roby/distributed/drb.rb +62 -0
- data/lib/roby/distributed/notifications.rb +539 -0
- data/lib/roby/distributed/peer.rb +550 -0
- data/lib/roby/distributed/protocol.rb +529 -0
- data/lib/roby/distributed/proxy.rb +343 -0
- data/lib/roby/distributed/subscription.rb +311 -0
- data/lib/roby/distributed/transaction.rb +498 -0
- data/lib/roby/event.rb +897 -0
- data/lib/roby/exceptions.rb +234 -0
- data/lib/roby/executives/simple.rb +30 -0
- data/lib/roby/graph.rb +166 -0
- data/lib/roby/interface.rb +390 -0
- data/lib/roby/log.rb +3 -0
- data/lib/roby/log/chronicle.rb +303 -0
- data/lib/roby/log/console.rb +72 -0
- data/lib/roby/log/data_stream.rb +197 -0
- data/lib/roby/log/dot.rb +279 -0
- data/lib/roby/log/event_stream.rb +151 -0
- data/lib/roby/log/file.rb +340 -0
- data/lib/roby/log/gui/basic_display.ui +83 -0
- data/lib/roby/log/gui/chronicle.rb +26 -0
- data/lib/roby/log/gui/chronicle_view.rb +40 -0
- data/lib/roby/log/gui/chronicle_view.ui +70 -0
- data/lib/roby/log/gui/data_displays.rb +172 -0
- data/lib/roby/log/gui/data_displays.ui +155 -0
- data/lib/roby/log/gui/notifications.rb +26 -0
- data/lib/roby/log/gui/relations.rb +248 -0
- data/lib/roby/log/gui/relations.ui +123 -0
- data/lib/roby/log/gui/relations_view.rb +185 -0
- data/lib/roby/log/gui/relations_view.ui +149 -0
- data/lib/roby/log/gui/replay.rb +327 -0
- data/lib/roby/log/gui/replay_controls.rb +200 -0
- data/lib/roby/log/gui/replay_controls.ui +259 -0
- data/lib/roby/log/gui/runtime.rb +130 -0
- data/lib/roby/log/hooks.rb +185 -0
- data/lib/roby/log/logger.rb +202 -0
- data/lib/roby/log/notifications.rb +244 -0
- data/lib/roby/log/plan_rebuilder.rb +470 -0
- data/lib/roby/log/relations.rb +1056 -0
- data/lib/roby/log/server.rb +550 -0
- data/lib/roby/log/sqlite.rb +47 -0
- data/lib/roby/log/timings.rb +164 -0
- data/lib/roby/plan-object.rb +247 -0
- data/lib/roby/plan.rb +762 -0
- data/lib/roby/planning.rb +13 -0
- data/lib/roby/planning/loops.rb +302 -0
- data/lib/roby/planning/model.rb +906 -0
- data/lib/roby/planning/task.rb +151 -0
- data/lib/roby/propagation.rb +562 -0
- data/lib/roby/query.rb +619 -0
- data/lib/roby/relations.rb +583 -0
- data/lib/roby/relations/conflicts.rb +70 -0
- data/lib/roby/relations/ensured.rb +20 -0
- data/lib/roby/relations/error_handling.rb +23 -0
- data/lib/roby/relations/events.rb +9 -0
- data/lib/roby/relations/executed_by.rb +193 -0
- data/lib/roby/relations/hierarchy.rb +239 -0
- data/lib/roby/relations/influence.rb +10 -0
- data/lib/roby/relations/planned_by.rb +63 -0
- data/lib/roby/robot.rb +7 -0
- data/lib/roby/standard_errors.rb +218 -0
- data/lib/roby/state.rb +5 -0
- data/lib/roby/state/events.rb +221 -0
- data/lib/roby/state/information.rb +55 -0
- data/lib/roby/state/pos.rb +110 -0
- data/lib/roby/state/shapes.rb +32 -0
- data/lib/roby/state/state.rb +353 -0
- data/lib/roby/support.rb +92 -0
- data/lib/roby/task-operations.rb +182 -0
- data/lib/roby/task.rb +1618 -0
- data/lib/roby/test/common.rb +399 -0
- data/lib/roby/test/distributed.rb +214 -0
- data/lib/roby/test/tasks/empty_task.rb +9 -0
- data/lib/roby/test/tasks/goto.rb +36 -0
- data/lib/roby/test/tasks/simple_task.rb +23 -0
- data/lib/roby/test/testcase.rb +519 -0
- data/lib/roby/test/tools.rb +160 -0
- data/lib/roby/thread_task.rb +87 -0
- data/lib/roby/transactions.rb +462 -0
- data/lib/roby/transactions/proxy.rb +292 -0
- data/lib/roby/transactions/updates.rb +139 -0
- data/plugins/fault_injection/History.txt +4 -0
- data/plugins/fault_injection/README.txt +37 -0
- data/plugins/fault_injection/Rakefile +18 -0
- data/plugins/fault_injection/TODO.txt +0 -0
- data/plugins/fault_injection/app.rb +52 -0
- data/plugins/fault_injection/fault_injection.rb +89 -0
- data/plugins/fault_injection/test/test_fault_injection.rb +84 -0
- data/plugins/subsystems/README.txt +40 -0
- data/plugins/subsystems/Rakefile +18 -0
- data/plugins/subsystems/app.rb +171 -0
- data/plugins/subsystems/test/app/README +24 -0
- data/plugins/subsystems/test/app/Rakefile +8 -0
- data/plugins/subsystems/test/app/config/app.yml +71 -0
- data/plugins/subsystems/test/app/config/init.rb +9 -0
- data/plugins/subsystems/test/app/config/roby.yml +3 -0
- data/plugins/subsystems/test/app/planners/main.rb +20 -0
- data/plugins/subsystems/test/app/scripts/distributed +3 -0
- data/plugins/subsystems/test/app/scripts/replay +3 -0
- data/plugins/subsystems/test/app/scripts/results +3 -0
- data/plugins/subsystems/test/app/scripts/run +3 -0
- data/plugins/subsystems/test/app/scripts/server +3 -0
- data/plugins/subsystems/test/app/scripts/shell +3 -0
- data/plugins/subsystems/test/app/scripts/test +3 -0
- data/plugins/subsystems/test/app/tasks/services.rb +15 -0
- data/plugins/subsystems/test/test_subsystems.rb +71 -0
- data/test/distributed/test_communication.rb +178 -0
- data/test/distributed/test_connection.rb +282 -0
- data/test/distributed/test_execution.rb +373 -0
- data/test/distributed/test_mixed_plan.rb +341 -0
- data/test/distributed/test_plan_notifications.rb +238 -0
- data/test/distributed/test_protocol.rb +516 -0
- data/test/distributed/test_query.rb +102 -0
- data/test/distributed/test_remote_plan.rb +491 -0
- data/test/distributed/test_transaction.rb +463 -0
- data/test/mockups/tasks.rb +27 -0
- data/test/planning/test_loops.rb +380 -0
- data/test/planning/test_model.rb +427 -0
- data/test/planning/test_task.rb +106 -0
- data/test/relations/test_conflicts.rb +42 -0
- data/test/relations/test_ensured.rb +38 -0
- data/test/relations/test_executed_by.rb +149 -0
- data/test/relations/test_hierarchy.rb +158 -0
- data/test/relations/test_planned_by.rb +54 -0
- data/test/suite_core.rb +24 -0
- data/test/suite_distributed.rb +9 -0
- data/test/suite_planning.rb +3 -0
- data/test/suite_relations.rb +8 -0
- data/test/test_bgl.rb +508 -0
- data/test/test_control.rb +399 -0
- data/test/test_event.rb +894 -0
- data/test/test_exceptions.rb +592 -0
- data/test/test_interface.rb +37 -0
- data/test/test_log.rb +114 -0
- data/test/test_log_server.rb +132 -0
- data/test/test_plan.rb +584 -0
- data/test/test_propagation.rb +210 -0
- data/test/test_query.rb +266 -0
- data/test/test_relations.rb +180 -0
- data/test/test_state.rb +414 -0
- data/test/test_support.rb +16 -0
- data/test/test_task.rb +938 -0
- data/test/test_testcase.rb +122 -0
- data/test/test_thread_task.rb +73 -0
- data/test/test_transactions.rb +569 -0
- data/test/test_transactions_proxy.rb +198 -0
- metadata +570 -0
@@ -0,0 +1,282 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../..', File.dirname(__FILE__))
|
2
|
+
require 'roby/test/distributed'
|
3
|
+
require 'roby/test/tasks/simple_task'
|
4
|
+
require 'flexmock'
|
5
|
+
|
6
|
+
class TC_DistributedConnection < Test::Unit::TestCase
|
7
|
+
include Rinda
|
8
|
+
include Roby
|
9
|
+
include Distributed
|
10
|
+
include Roby::Distributed::Test
|
11
|
+
|
12
|
+
def assert_has_neighbour(&check)
|
13
|
+
Distributed.state.start_neighbour_discovery
|
14
|
+
Distributed.state.wait_discovery
|
15
|
+
|
16
|
+
assert(!Distributed.state.discovering?)
|
17
|
+
assert(1, Distributed.neighbours.size)
|
18
|
+
assert(Distributed.neighbours.find(&check), Distributed.neighbours.map { |n| [n.name, n.remote_id] }.to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Test neighbour discovery using a remote central tuplespace as neighbour list
|
22
|
+
def test_centralized_drb_discovery
|
23
|
+
DRb.stop_service
|
24
|
+
|
25
|
+
central_tuplespace = TupleSpace.new
|
26
|
+
DRb.start_service 'druby://localhost:1245', central_tuplespace
|
27
|
+
|
28
|
+
remote_pid = remote_process do
|
29
|
+
DRb.stop_service
|
30
|
+
DRb.start_service
|
31
|
+
central_tuplespace = DRbObject.new_with_uri('druby://localhost:1245')
|
32
|
+
|
33
|
+
Distributed.state = ConnectionSpace.new :ring_discovery => false,
|
34
|
+
:discovery_tuplespace => central_tuplespace
|
35
|
+
end
|
36
|
+
Distributed.state = ConnectionSpace.new :ring_discovery => false,
|
37
|
+
:discovery_tuplespace => central_tuplespace
|
38
|
+
assert_has_neighbour { |n| n.name == "#{Socket.gethostname}-#{remote_pid}" }
|
39
|
+
end
|
40
|
+
|
41
|
+
BROADCAST = (1..10).map { |i| "127.0.0.#{i}" }
|
42
|
+
# Test neighbour discovery using UDP for discovery
|
43
|
+
def test_ringserver_discovery
|
44
|
+
DRb.stop_service
|
45
|
+
|
46
|
+
remote_pid = remote_process do
|
47
|
+
DRb.start_service
|
48
|
+
Distributed.state = ConnectionSpace.new :period => 0.5, :ring_discovery => true, :ring_broadcast => BROADCAST
|
49
|
+
Distributed.publish :bind => '127.0.0.2'
|
50
|
+
end
|
51
|
+
|
52
|
+
DRb.start_service
|
53
|
+
Distributed.state = ConnectionSpace.new :period => 0.5, :ring_discovery => true, :ring_broadcast => BROADCAST
|
54
|
+
Distributed.publish :bind => '127.0.0.1'
|
55
|
+
|
56
|
+
assert_has_neighbour { |n| n.name == "#{Socket.gethostname}-#{remote_pid}" }
|
57
|
+
end
|
58
|
+
|
59
|
+
# Test establishing peer-to-peer connection between two ConnectionSpace objects
|
60
|
+
# Note that #peer2peer is the exact same process
|
61
|
+
def test_connect(standalone = true)
|
62
|
+
if standalone
|
63
|
+
start_peers(true)
|
64
|
+
|
65
|
+
notified = []
|
66
|
+
Distributed.on_neighbour do |n|
|
67
|
+
notified << n
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
assert(local.discovery_thread)
|
72
|
+
|
73
|
+
# Initiate the connection from +local+
|
74
|
+
remote_neighbour = Distributed.neighbours.find { true }
|
75
|
+
Roby.execute do
|
76
|
+
did_yield = nil
|
77
|
+
Peer.initiate_connection(local, remote_neighbour) do |did_yield|
|
78
|
+
end
|
79
|
+
|
80
|
+
# Wait for the remote peer to take into account the fact that we
|
81
|
+
# try connecting
|
82
|
+
Distributed.state.synchronize do
|
83
|
+
remote_id = remote_neighbour.remote_id
|
84
|
+
assert(Distributed.state.pending_connections[remote_id] ||
|
85
|
+
Distributed.state.peers[remote_id])
|
86
|
+
end
|
87
|
+
|
88
|
+
sleep(1)
|
89
|
+
Distributed.state.synchronize do
|
90
|
+
remote_id = remote_neighbour.remote_id
|
91
|
+
assert(@remote_peer = Distributed.state.peers[remote_id], Distributed.state.peers)
|
92
|
+
assert_equal(remote_peer, did_yield)
|
93
|
+
end
|
94
|
+
assert(remote_peer.connected?)
|
95
|
+
assert(remote.send_local_peer(:connected?))
|
96
|
+
assert(remote_peer.link_alive?)
|
97
|
+
assert(remote.send_local_peer(:link_alive?))
|
98
|
+
|
99
|
+
did_yield = nil
|
100
|
+
Peer.initiate_connection(local, remote_neighbour) do |did_yield|
|
101
|
+
end
|
102
|
+
assert_equal(remote_peer, did_yield)
|
103
|
+
assert_equal(remote_peer, Peer.connect(remote_neighbour))
|
104
|
+
end
|
105
|
+
|
106
|
+
Roby.control.wait_one_cycle
|
107
|
+
assert(remote_peer.task.running?)
|
108
|
+
#assert_raises(ArgumentError) { Peer.initiate_connection(local, remote_neighbour) }
|
109
|
+
assert(remote_peer.link_alive?)
|
110
|
+
|
111
|
+
remote_peer.synchro_point
|
112
|
+
assert(remote_peer.connected?)
|
113
|
+
assert(remote_peer.task.ready?)
|
114
|
+
|
115
|
+
assert_equal('remote', remote_peer.remote_name)
|
116
|
+
assert_equal('remote', remote_peer.local_server.remote_name)
|
117
|
+
assert_equal('local', remote_peer.local_server.local_name)
|
118
|
+
|
119
|
+
if standalone
|
120
|
+
assert_equal(1, notified.size)
|
121
|
+
assert_equal([remote_neighbour], notified)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_synchronous_connect
|
126
|
+
start_peers(true) do |remote|
|
127
|
+
def remote.connected?
|
128
|
+
local_peer.connected?
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
sleep(0.5)
|
133
|
+
assert(remote_neighbour = Distributed.neighbours.find { true })
|
134
|
+
assert(remote_peer = Peer.connect(remote_neighbour))
|
135
|
+
|
136
|
+
assert_kind_of(Distributed::Peer, remote_peer)
|
137
|
+
assert(remote.connected?)
|
138
|
+
assert(remote_peer.connected?)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_concurrent_connection
|
142
|
+
GC.disable
|
143
|
+
start_peers(true) do |remote|
|
144
|
+
class << remote
|
145
|
+
def find_neighbour
|
146
|
+
@neighbour = Roby::Distributed.neighbours.find { true }
|
147
|
+
end
|
148
|
+
def connect
|
149
|
+
Roby::Distributed::Peer.initiate_connection(Roby::Distributed.state, @neighbour) do
|
150
|
+
@callback_called ||= 0
|
151
|
+
@callback_called += 1
|
152
|
+
end
|
153
|
+
nil
|
154
|
+
end
|
155
|
+
|
156
|
+
attr_reader :callback_called
|
157
|
+
def peer_objects
|
158
|
+
peer_objects = ObjectSpace.enum_for(:each_object, Roby::Distributed::Peer).to_a
|
159
|
+
[Roby::Distributed.peers.keys.size, peer_objects.size]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
sleep(0.5)
|
165
|
+
assert(remote.find_neighbour)
|
166
|
+
assert(remote_neighbour = Distributed.neighbours.find { true })
|
167
|
+
|
168
|
+
# We want to check that a concurrent connection creates only one Peer
|
169
|
+
# object. Still, we have to take into account that the remote peer is a
|
170
|
+
# fork of ourselves, and as such inherits the Peer objects this process
|
171
|
+
# has in its ObjectSpace (like the leftovers of other tests)
|
172
|
+
registered_peer_count, initial_remote_peer_count = remote.peer_objects
|
173
|
+
assert_equal(0, registered_peer_count)
|
174
|
+
registered_peer_count, initial_local_peer_count = Distributed.peers.keys.size,
|
175
|
+
ObjectSpace.enum_for(:each_object, Distributed::Peer).to_a.size
|
176
|
+
assert_equal(0, registered_peer_count)
|
177
|
+
|
178
|
+
remote.connect
|
179
|
+
remote.connect
|
180
|
+
|
181
|
+
callback_called = 0
|
182
|
+
2.times do
|
183
|
+
Peer.initiate_connection(local, remote_neighbour) do
|
184
|
+
callback_called += 1
|
185
|
+
end
|
186
|
+
end
|
187
|
+
sleep(1)
|
188
|
+
|
189
|
+
assert_equal(2, callback_called)
|
190
|
+
assert_equal(2, remote.callback_called)
|
191
|
+
assert_equal([1, initial_remote_peer_count + 1], remote.peer_objects)
|
192
|
+
assert_equal(1, Distributed.peers.keys.size)
|
193
|
+
assert_equal(initial_local_peer_count + 1, ObjectSpace.enum_for(:each_object, Distributed::Peer).to_a.size)
|
194
|
+
ensure
|
195
|
+
GC.enable
|
196
|
+
end
|
197
|
+
|
198
|
+
# Test the normal disconnection process
|
199
|
+
def test_disconnect
|
200
|
+
peer2peer(true) do |remote|
|
201
|
+
def remote.peers_empty?; Distributed.peers.empty? end
|
202
|
+
end
|
203
|
+
|
204
|
+
Roby.control.wait_one_cycle
|
205
|
+
assert(remote_peer.task.ready?)
|
206
|
+
|
207
|
+
remote_peer.disconnect
|
208
|
+
assert(remote_peer.disconnecting?)
|
209
|
+
process_events
|
210
|
+
remote.process_events
|
211
|
+
|
212
|
+
assert(remote_peer.disconnected?)
|
213
|
+
remote.send_local_peer(:disconnected?)
|
214
|
+
|
215
|
+
assert(Distributed.peers.empty?)
|
216
|
+
assert(remote.peers_empty?)
|
217
|
+
remote.reset_local_peer
|
218
|
+
|
219
|
+
# Make sure that we can reconnect
|
220
|
+
test_connect(false)
|
221
|
+
end
|
222
|
+
|
223
|
+
# Tests that the remote peer disconnects if #demux raises DisconnectedError
|
224
|
+
def test_disconnect_on_error
|
225
|
+
Roby.logger.level = Logger::FATAL
|
226
|
+
peer2peer(true) do |remote|
|
227
|
+
class << remote
|
228
|
+
include Test::Unit::Assertions
|
229
|
+
def assert_demux_raises
|
230
|
+
peer = peers.find { true }[1]
|
231
|
+
peer.transmit(:whatever)
|
232
|
+
peer.synchro_point rescue nil
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
remote_peer.disconnect
|
238
|
+
remote.assert_demux_raises
|
239
|
+
assert(remote.send_local_peer(:disconnected?))
|
240
|
+
|
241
|
+
assert(remote_peer.disconnected?)
|
242
|
+
remote.reset_local_peer
|
243
|
+
|
244
|
+
# Make sure that we can reconnect
|
245
|
+
test_connect(false)
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_socket_reconnect
|
249
|
+
peer2peer(true)
|
250
|
+
Distributed.state.synchronize do
|
251
|
+
remote_peer.socket.close
|
252
|
+
assert(!remote_peer.link_alive?)
|
253
|
+
end
|
254
|
+
|
255
|
+
sleep(1)
|
256
|
+
assert(!remote_peer.socket.closed?)
|
257
|
+
assert(remote_peer.connected?)
|
258
|
+
assert(remote_peer.link_alive?)
|
259
|
+
assert(remote.send_local_peer(:connected?))
|
260
|
+
assert(remote.send_local_peer(:link_alive?))
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_remote_dies
|
264
|
+
peer2peer(true)
|
265
|
+
Process.kill('KILL', remote_processes[1][0])
|
266
|
+
|
267
|
+
sleep(1)
|
268
|
+
assert(remote_peer.disconnected?)
|
269
|
+
end
|
270
|
+
|
271
|
+
|
272
|
+
def test_abort_connection
|
273
|
+
peer2peer(true)
|
274
|
+
remote_peer.disconnected!
|
275
|
+
|
276
|
+
sleep(1)
|
277
|
+
assert(remote_peer.socket.closed?)
|
278
|
+
assert(!remote_peer.connected?)
|
279
|
+
assert(!remote.send_local_peer(:connected?))
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
@@ -0,0 +1,373 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../..', File.dirname(__FILE__))
|
2
|
+
require 'roby/test/distributed'
|
3
|
+
require 'roby/test/tasks/simple_task'
|
4
|
+
require 'flexmock'
|
5
|
+
|
6
|
+
class TC_DistributedExecution < Test::Unit::TestCase
|
7
|
+
include Roby::Distributed::Test
|
8
|
+
SimpleTask = Roby::Test::SimpleTask
|
9
|
+
|
10
|
+
def test_event_status
|
11
|
+
peer2peer(true) do |remote|
|
12
|
+
class << remote
|
13
|
+
attr_reader :controlable
|
14
|
+
attr_reader :contingent
|
15
|
+
def create
|
16
|
+
# Put the task to avoir having GC clearing the events
|
17
|
+
plan.insert(t = SimpleTask.new(:id => 'task'))
|
18
|
+
plan.discover(@controlable = Roby::EventGenerator.new(true))
|
19
|
+
plan.discover(@contingent = Roby::EventGenerator.new(false))
|
20
|
+
t.on(:start, controlable)
|
21
|
+
t.forward(:start, contingent)
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
def fire
|
25
|
+
Roby.execute do
|
26
|
+
controlable.call(nil)
|
27
|
+
contingent.emit(nil)
|
28
|
+
end
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
remote.create
|
35
|
+
task = subscribe_task(:id => 'task')
|
36
|
+
controlable = *task.event(:start).child_objects(EventStructure::Signal).to_a
|
37
|
+
contingent = *task.event(:start).child_objects(EventStructure::Forwarding).to_a
|
38
|
+
|
39
|
+
FlexMock.use do |mock|
|
40
|
+
controlable.on do
|
41
|
+
mock.fired_controlable(Roby::Propagation.gathering?)
|
42
|
+
end
|
43
|
+
contingent.on do
|
44
|
+
mock.fired_contingent(Roby::Propagation.gathering?)
|
45
|
+
end
|
46
|
+
|
47
|
+
mock.should_receive(:fired_controlable).with(true).once
|
48
|
+
mock.should_receive(:fired_contingent).with(true).once
|
49
|
+
remote.fire
|
50
|
+
remote_peer.synchro_point
|
51
|
+
end
|
52
|
+
|
53
|
+
assert(controlable.happened?)
|
54
|
+
assert(contingent.happened?)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_signal_establishment
|
58
|
+
peer2peer(true) do |remote|
|
59
|
+
Roby::Distributed.on_transaction do |trsc|
|
60
|
+
trsc.edit do
|
61
|
+
local_task = trsc.find_tasks.which_fullfills(Roby::Test::SimpleTask).to_a.first
|
62
|
+
t = trsc[SimpleTask.new(:id => 'remote_task')]
|
63
|
+
local_task.realized_by t
|
64
|
+
local_task.on :start, t, :start
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
trsc = Roby::Distributed::Transaction.new(plan)
|
71
|
+
trsc.add_owner remote_peer
|
72
|
+
trsc.propose(remote_peer)
|
73
|
+
|
74
|
+
plan.insert(local_task = Roby::Test::SimpleTask.new)
|
75
|
+
trsc[local_task]
|
76
|
+
trsc.release
|
77
|
+
trsc.edit
|
78
|
+
trsc.commit_transaction
|
79
|
+
|
80
|
+
Roby.execute { local_task.start! }
|
81
|
+
Roby.wait_one_cycle
|
82
|
+
remote_peer.synchro_point
|
83
|
+
remote_task = subscribe_task(:id => 'remote_task')
|
84
|
+
assert(remote_task.running?)
|
85
|
+
|
86
|
+
Roby.execute do
|
87
|
+
plan.discard(local_task)
|
88
|
+
local_task.stop!
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# This test that the event/plan modification order is kept on a remote host
|
93
|
+
def test_keeps_causality
|
94
|
+
peer2peer(true) do |remote|
|
95
|
+
class << remote
|
96
|
+
attr_reader :event
|
97
|
+
attr_reader :task
|
98
|
+
def create
|
99
|
+
# Put the task to avoir having GC clearing the events
|
100
|
+
plan.insert(@task = SimpleTask.new(:id => 'task'))
|
101
|
+
plan.discover(@event = Roby::EventGenerator.new(true))
|
102
|
+
event.on task.event(:start)
|
103
|
+
nil
|
104
|
+
end
|
105
|
+
def fire
|
106
|
+
Roby.execute do
|
107
|
+
event.on do
|
108
|
+
plan.discard(task)
|
109
|
+
task.event(:start).on task.event(:success)
|
110
|
+
end
|
111
|
+
|
112
|
+
event.call(nil)
|
113
|
+
end
|
114
|
+
nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
remote.create
|
120
|
+
task = subscribe_task(:id => 'task')
|
121
|
+
event = *task.event(:start).parent_objects(EventStructure::Signal).to_a
|
122
|
+
|
123
|
+
FlexMock.use do |mock|
|
124
|
+
event.on do
|
125
|
+
mock.fired
|
126
|
+
assert(plan.free_events.include?(event))
|
127
|
+
end
|
128
|
+
|
129
|
+
mock.should_receive(:fired).once
|
130
|
+
remote.fire
|
131
|
+
remote_peer.synchro_point
|
132
|
+
end
|
133
|
+
|
134
|
+
assert(event.happened?)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_task_status
|
138
|
+
Roby.control.abort_on_exception = false
|
139
|
+
peer2peer(true) do |remote|
|
140
|
+
class << remote
|
141
|
+
include Test::Unit::Assertions
|
142
|
+
attr_reader :task
|
143
|
+
def create_task
|
144
|
+
plan.clear
|
145
|
+
plan.insert(@task = SimpleTask.new(:id => 1))
|
146
|
+
end
|
147
|
+
def start_task; Roby::Control.once { task.start! }; nil end
|
148
|
+
def stop_task
|
149
|
+
assert(task.executable?)
|
150
|
+
Roby::Control.once do
|
151
|
+
plan.discard(task)
|
152
|
+
task.stop!
|
153
|
+
end
|
154
|
+
nil
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
remote.create_task
|
160
|
+
p_task = remote_task(:id => 1)
|
161
|
+
assert(!p_task.event(:start).happened?)
|
162
|
+
process_events
|
163
|
+
assert(!p_task.plan)
|
164
|
+
|
165
|
+
# Start the task *before* subscribing to test that #subscribe maps the
|
166
|
+
# task status
|
167
|
+
remote.start_task
|
168
|
+
process_events
|
169
|
+
p_task = subscribe_task(:id => 1)
|
170
|
+
assert(p_task.running?)
|
171
|
+
assert(p_task.event(:start).happened?)
|
172
|
+
|
173
|
+
# Stop the task to see if the fired event is propagated
|
174
|
+
remote.stop_task
|
175
|
+
process_events
|
176
|
+
assert(p_task.finished?)
|
177
|
+
assert(p_task.failed?)
|
178
|
+
assert(p_task.event(:stop).happened?)
|
179
|
+
assert(p_task.finished?)
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_signalling
|
183
|
+
peer2peer(true) do |remote|
|
184
|
+
remote.plan.insert(task = SimpleTask.new(:id => 1))
|
185
|
+
remote.class.class_eval do
|
186
|
+
include Test::Unit::Assertions
|
187
|
+
define_method(:start_task) do
|
188
|
+
events = plan.free_events.to_a
|
189
|
+
assert_equal(2, events.size)
|
190
|
+
assert(sev = events.find { |ev| ev.controlable? })
|
191
|
+
assert(fev = events.find { |ev| !ev.controlable? })
|
192
|
+
assert(task.event(:start).child_object?(sev, Roby::EventStructure::Signal))
|
193
|
+
assert(task.event(:start).child_object?(fev, Roby::EventStructure::Forwarding))
|
194
|
+
Control.once { task.start! }
|
195
|
+
nil
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
p_task = subscribe_task(:id => 1)
|
200
|
+
|
201
|
+
FlexMock.use do |mock|
|
202
|
+
signalled_ev = EventGenerator.new do |context|
|
203
|
+
mock.signal_command
|
204
|
+
signalled_ev.emit(nil)
|
205
|
+
end
|
206
|
+
signalled_ev.on { |ev| mock.signal_emitted }
|
207
|
+
assert(signalled_ev.controlable?)
|
208
|
+
|
209
|
+
forwarded_ev = EventGenerator.new
|
210
|
+
forwarded_ev.on { |ev| mock.forward_emitted }
|
211
|
+
assert(!forwarded_ev.controlable?)
|
212
|
+
|
213
|
+
p_task.event(:start).on signalled_ev
|
214
|
+
p_task.event(:start).forward forwarded_ev
|
215
|
+
|
216
|
+
mock.should_receive(:signal_command).once.ordered('signal')
|
217
|
+
mock.should_receive(:signal_emitted).once.ordered('signal')
|
218
|
+
mock.should_receive(:forward_emitted).once
|
219
|
+
process_events
|
220
|
+
|
221
|
+
remote.start_task
|
222
|
+
process_events
|
223
|
+
assert(signalled_ev.happened?)
|
224
|
+
assert(forwarded_ev.happened?)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_event_handlers
|
229
|
+
peer2peer(true) do |remote|
|
230
|
+
remote.plan.insert(task = SimpleTask.new(:id => 1))
|
231
|
+
def remote.start(task)
|
232
|
+
task = local_peer.local_object(task)
|
233
|
+
Roby::Control.once { task.start! }
|
234
|
+
nil
|
235
|
+
end
|
236
|
+
end
|
237
|
+
FlexMock.use do |mock|
|
238
|
+
mock.should_receive(:started).once
|
239
|
+
|
240
|
+
task = subscribe_task(:id => 1)
|
241
|
+
task.on(:start) { mock.started }
|
242
|
+
remote.start(Distributed.format(task))
|
243
|
+
process_events
|
244
|
+
|
245
|
+
assert(task.running?)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# Test that we can 'forget' running tasks that was known to us because they
|
250
|
+
# were related to subscribed tasks
|
251
|
+
def test_forgetting
|
252
|
+
peer2peer(true) do |remote|
|
253
|
+
parent, child =
|
254
|
+
SimpleTask.new(:id => 'parent'),
|
255
|
+
SimpleTask.new(:id => 'child')
|
256
|
+
parent.realized_by child
|
257
|
+
|
258
|
+
remote.plan.insert(parent)
|
259
|
+
child.start!
|
260
|
+
remote.singleton_class.class_eval do
|
261
|
+
define_method(:remove_link) do
|
262
|
+
parent.remove_child(child)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
parent = subscribe_task(:id => 'parent')
|
268
|
+
child = nil
|
269
|
+
assert(child = local.plan.known_tasks.find { |t| t.arguments[:id] == 'child' })
|
270
|
+
assert(!child.subscribed?)
|
271
|
+
assert(child.running?)
|
272
|
+
remote.remove_link
|
273
|
+
process_events
|
274
|
+
assert(!local.plan.known_tasks.find { |t| t.arguments[:id] == 'child' })
|
275
|
+
end
|
276
|
+
|
277
|
+
# Tests that running remote tasks are aborted and pending tasks GCed if the
|
278
|
+
# connection is killed
|
279
|
+
def test_disconnect_kills_tasks
|
280
|
+
peer2peer(true) do |remote|
|
281
|
+
remote.plan.insert(task = SimpleTask.new(:id => 'remote-1'))
|
282
|
+
def remote.start(task)
|
283
|
+
task = local_peer.local_object(task)
|
284
|
+
Roby.execute do
|
285
|
+
task.start!
|
286
|
+
end
|
287
|
+
nil
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
task = subscribe_task(:id => 'remote-1')
|
292
|
+
remote.start(Distributed.format(task))
|
293
|
+
process_events
|
294
|
+
assert(task.running?)
|
295
|
+
assert(task.child_object?(remote_peer.task, TaskStructure::ExecutionAgent))
|
296
|
+
assert(task.subscribed?)
|
297
|
+
|
298
|
+
Roby.execute do
|
299
|
+
remote_peer.disconnected!
|
300
|
+
end
|
301
|
+
assert(!task.subscribed?)
|
302
|
+
assert(remote_peer.task.finished?)
|
303
|
+
assert(remote_peer.task.event(:aborted).happened?)
|
304
|
+
assert(remote_peer.task.event(:stop).happened?)
|
305
|
+
assert(task.finished?)
|
306
|
+
end
|
307
|
+
|
308
|
+
# Checks that the code blocks are called only in owning controllers
|
309
|
+
class CodeBlocksOwnersMockup < Roby::Test::SimpleTask
|
310
|
+
attr_reader :command_called
|
311
|
+
event :start do
|
312
|
+
@command_called = true
|
313
|
+
emit :start
|
314
|
+
end
|
315
|
+
|
316
|
+
attr_reader :handler_called
|
317
|
+
on(:start) { @handler_called = true }
|
318
|
+
|
319
|
+
attr_reader :poller_called
|
320
|
+
poll { @poller_called = true }
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_code_blocks_owners
|
324
|
+
peer2peer(true) do |remote|
|
325
|
+
remote.plan.insert(CodeBlocksOwnersMockup.new(:id => 'mockup'))
|
326
|
+
|
327
|
+
def remote.call
|
328
|
+
task = plan.find_tasks(CodeBlocksOwnersMockup).to_a.first
|
329
|
+
Roby.execute { task.start! }
|
330
|
+
end
|
331
|
+
|
332
|
+
def remote.blocks_called
|
333
|
+
task = plan.find_tasks(CodeBlocksOwnersMockup).to_a.first
|
334
|
+
task.command_called && task.poller_called && task.handler_called
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
mockup = subscribe_task(:id => 'mockup')
|
339
|
+
remote.call
|
340
|
+
remote_peer.synchro_point
|
341
|
+
|
342
|
+
assert(remote.blocks_called)
|
343
|
+
assert(!mockup.command_called)
|
344
|
+
assert(!mockup.poller_called)
|
345
|
+
assert(!mockup.handler_called)
|
346
|
+
end
|
347
|
+
|
348
|
+
# Checks that we get the update fine if +fired+ and +signalled+ are
|
349
|
+
# received in the same cycle
|
350
|
+
def test_joint_fired_signalled
|
351
|
+
peer2peer(true) do |remote|
|
352
|
+
remote.plan.insert(task = SimpleTask.new(:id => 'remote-1'))
|
353
|
+
Roby::Control.once { task.start! }
|
354
|
+
end
|
355
|
+
|
356
|
+
event_time = Time.now
|
357
|
+
remote = subscribe_task(:id => 'remote-1')
|
358
|
+
plan.insert(local = SimpleTask.new(:id => 'local'))
|
359
|
+
remote_peer.synchro_point
|
360
|
+
|
361
|
+
Roby.execute do
|
362
|
+
remote_peer.local_server.event_fired(remote.event(:success), 0, Time.now, [42])
|
363
|
+
remote_peer.local_server.event_add_propagation(true, remote.event(:success), local.event(:start), 0, event_time, [42])
|
364
|
+
end
|
365
|
+
process_events
|
366
|
+
|
367
|
+
assert(remote.finished?)
|
368
|
+
assert(remote.success?)
|
369
|
+
assert(local.started?)
|
370
|
+
assert_equal(1, remote.history.size, remote.history)
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|