module Orocos::Test::Component
Public Instance Methods
Verify that no sample arrives on reader within
timeout seconds
# File lib/orocos/test/component.rb, line 45 def assert_has_no_new_sample(reader, timeout = 0.2) sleep timeout assert(!reader.read_new, "#{reader} has one new sample, but none was expected") end
Verifies that reader gets one sample within
timeout seconds
# File lib/orocos/test/component.rb, line 51 def assert_has_one_new_sample(reader, timeout = 3, poll_period = 0.01) Integer(timeout / poll_period).times do if sample = reader.read_new return sample end sleep poll_period end flunk("expected to get one new sample out of #{reader.port.name}, but got none") end
Tests if the state of task changes to an expected value. The
block should return whether the passed state is the expected state or not.
# File lib/orocos/test/component.rb, line 67 def assert_state_change(task, timeout = 1) sleep_time = Float(timeout) / 10 10.times do queued_state_changes = task.peek_state if queued_state_changes.any? { |s| yield(s) } return end sleep sleep_time end flunk("could not find the expected state change for #{task.name} in #{task.peek_state.inspect}") end
Gets the data reader for this port. It gets disconnected on teardown
# File lib/orocos/test/component.rb, line 121 def data_reader(port, policy = Hash.new) reader = port.reader(policy) data_readers << reader reader end
Gets the data writer for this port. It gets disconnected on teardown
# File lib/orocos/test/component.rb, line 129 def data_writer(port, policy = Hash.new) writer = port.writer(policy) data_writers << writer writer end
# File lib/orocos/test/component.rb, line 13 def setup if !Orocos.initialized? Orocos.initialize end self.class.run_specs.each do |name, task_name, run_spec| start(run_spec) instance_variable_set("@#{name}", Orocos.name_service.get(task_name)) end self.class.reader_specs.each do |task_name, port_name, reader_name, policy| reader = self.data_reader(send(task_name).port(port_name), policy) instance_variable_set("@#{reader_name}", reader) end self.class.writer_specs.each do |task_name, port_name, writer_name, policy| writer = self.data_writer(send(task_name).port(port_name), policy) instance_variable_set("@#{writer_name}", writer) end super if defined? super end
Requires the unit test to start a deployment/task at the point of the call, and make sure to shut it down during teardown. In test methods, the task object is made accessible with the 'attribute_name' attribute
In the first form, the task is given through its model. The global task name is registered with 'task_name', which defaults to 'attribute_name'
In the second form, the task is given through a deployment name / task name pair. If a prefix is given, task_name must include the prefix as well, i.e.:
start 'task', 'rock_logger', 'source_logger', 'source'
where 'logger' is a task of the 'rock_logger' deployment.
For instance:
describe 'xsens_imu::Task' do include Orocos::Test::Component it "should fail to configure if no device is present" do start 'xsens_imu::Task' => 'task' task = Orocos.name_service.get 'task' task.device = "" assert_raises(Orocos::StateTransitionFailed) { task.configure } end end
# File lib/orocos/test/component.rb, line 114 def start(*args) processes.concat(Orocos.run(*args)) nil end
# File lib/orocos/test/component.rb, line 34 def teardown data_readers.each { |r| r.disconnect } data_readers.clear data_writers.each { |w| w.disconnect } data_writers.clear processes.each { |p| p.kill } processes.clear super if defined? super end