Module: Orocos::Test::RubyTasks

Included in:
SelfTest, Component
Defined in:
lib/orocos/test/ruby_tasks.rb

Overview

Support for using ruby tasks in tests

Instance Method Summary collapse

Instance Method Details

#helpers_dirObject



5
6
7
# 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) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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) ⇒ Object



33
34
35
36
37
# 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) ⇒ Object



29
30
31
# File 'lib/orocos/test/ruby_tasks.rb', line 29

def register_allocated_ruby_tasks(*tasks)
    @allocated_task_contexts.concat(tasks)
end

#setupObject



9
10
11
12
13
# 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

#teardownObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# 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