Sha256: c3f47f46b875c944c24cef684a368ae1cbd18b2c42af9a5ef9160dc75e000061

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require 'restartable'

Given(/^I have invoked restartable with `(.*?)`$/) do |command|
  @stdout = IO.pipe
  @stderr = IO.pipe

  @pid = fork do
    Process.setpgrp

    @stdout[0].close
    STDOUT.reopen(@stdout[1])

    @stderr[0].close
    STDERR.reopen(@stderr[1])

    Restartable.new do
      Signal.trap('INT', 'EXIT')
      eval(command)
    end
  end

  @stdout[1].close
  @stderr[1].close
end

When(/^I have waited for (\d+) second$/) do |seconds|
  sleep seconds.to_i
end

Then(/^I should see "(.*?)" in stdout$/) do |string|
  Timeout::timeout(5) do
    @stdout[0].gets.should include(string)
  end
end

Then(/^I should see "(.*?)" in stderr$/) do |arg|
  Timeout::timeout(60) do
    strings = arg.split(/".*?"/)
    until strings.empty?
      line = @stderr[0].gets
      strings.reject! do |string|
        line.include?(string)
      end
    end
  end
end

When(/^I interrupt restartable$/) do
  Process.kill('INT', -@pid)
end

When(/^I interrupt restartable twice$/) do
  Process.kill('INT', -@pid)
  sleep 0.1
  Process.kill('INT', -@pid)
end

Then(/^there should be an inner process$/) do
  Timeout::timeout(5) do
    until Sys::ProcTable.ps.any?{ |pe| pe.ppid == @pid }
      sleep 1
    end
  end
end

Then(/^inner process should terminate$/) do
  Timeout::timeout(100) do
    until Sys::ProcTable.ps.none?{ |pe| pe.ppid == @pid }
      sleep 1
    end
  end
end

Then(/^restartable should finish$/) do
  Timeout::timeout(5) do
    Process.wait(@pid)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
restartable-0.2.2 features/step_definitions/restartable_steps.rb
restartable-0.2.1 features/step_definitions/restartable_steps.rb