module Orocos::Test::RubyTasks
Support for using ruby tasks in tests
Public Instance Methods
helpers_dir()
click to toggle source
# File lib/orocos/test/ruby_tasks.rb, line 5 def helpers_dir File.join(__dir__, 'helpers') end
new_external_ruby_task_context( name, typekits: ['std'], input_ports: [], output_ports: [], timeout: 2)
click to toggle source
# File lib/orocos/test/ruby_tasks.rb, line 39 def new_external_ruby_task_context( name, typekits: ['std'], input_ports: [], output_ports: [], timeout: 2) typekits = typekits.map do |typekit_name| "--typekit=#{typekit_name}" end output_ports = output_ports.map do |name, type| "--output-port=#{name}::#{type}" end input_ports = input_ports.map do |name, type| "--input-port=#{name}::#{type}" end pid = spawn(Gem.ruby, File.join(helpers_dir, 'ruby_task_spawner'), name, *typekits, *input_ports, *output_ports) start_time = Time.now while (Time.now - start_time) < timeout begin return Orocos.get(name), pid rescue Orocos::NotFound end end flunk "failed to create ruby task context #{name}" end
new_ruby_task_context(name, options = Hash.new, &block)
click to toggle source
# File lib/orocos/test/ruby_tasks.rb, line 33 def new_ruby_task_context(name, options = Hash.new, &block) task = Orocos::RubyTasks::TaskContext.new(name, options, &block) @allocated_task_contexts << task task end
register_allocated_ruby_tasks(*tasks)
click to toggle source
# File lib/orocos/test/ruby_tasks.rb, line 29 def register_allocated_ruby_tasks(*tasks) @allocated_task_contexts.concat(tasks) end
setup()
click to toggle source
Calls superclass method
# File lib/orocos/test/ruby_tasks.rb, line 9 def setup @allocated_task_contexts = Array.new @started_external_ruby_task_contexts = Array.new super end
teardown()
click to toggle source
Calls superclass method
# File lib/orocos/test/ruby_tasks.rb, line 15 def teardown super @allocated_task_contexts.each(&:dispose) @started_external_ruby_task_contexts.each do |pid| begin Process.kill 'INT', pid rescue Errno::ESRCH end _, status = Process.waitpid2 pid if !status.success? raise "subprocess #{pid} failed with #{status.inspect}" end end end