Sha256: 7df85eb65b61229d0c91d02e6e5ac42e79bc1a42e9471609feb71357e71ea356

Contents?: true

Size: 1.89 KB

Versions: 56

Compression:

Stored size: 1.89 KB

Contents

require File.expand_path('../spec_helper', __FILE__)
require "pid_behavior"

if ChildProcess.unix? && !ChildProcess.jruby? && !ChildProcess.posix_spawn?

  describe ChildProcess::Unix::Process do
    it_behaves_like "a platform that provides the child's pid"

    it "handles ECHILD race condition where process dies between timeout and KILL" do
      process = sleeping_ruby

      allow(process).to receive(:fork).and_return('fakepid')
      allow(process).to receive(:send_term)
      allow(process).to receive(:poll_for_exit).and_raise(ChildProcess::TimeoutError)
      allow(process).to receive(:send_kill).and_raise(Errno::ECHILD.new)

      process.start
      expect { process.stop }.not_to raise_error

      allow(process).to receive(:alive?).and_return(false)

      process.send(:send_signal, 'TERM')
    end

    it "handles ESRCH race condition where process dies between timeout and KILL" do
      process = sleeping_ruby

      allow(process).to receive(:fork).and_return('fakepid')
      allow(process).to receive(:send_term)
      allow(process).to receive(:poll_for_exit).and_raise(ChildProcess::TimeoutError)
      allow(process).to receive(:send_kill).and_raise(Errno::ESRCH.new)

      process.start
      expect { process.stop }.not_to raise_error

      allow(process).to receive(:alive?).and_return(false)

      process.send(:send_signal, 'TERM')
    end
  end

  describe ChildProcess::Unix::IO do
    let(:io) { ChildProcess::Unix::IO.new }

    it "raises an ArgumentError if given IO does not respond to :to_io" do
      expect { io.stdout = nil }.to raise_error(ArgumentError, /to respond to :to_io/)
    end

    it "raises a TypeError if #to_io does not return an IO" do
      fake_io = Object.new
      def fake_io.to_io() StringIO.new end

      expect { io.stdout = fake_io }.to raise_error(TypeError, /expected IO, got/)
    end
  end

end

Version data entries

56 entries across 42 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/childprocess-0.6.3/spec/unix_spec.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/childprocess-0.6.3/spec/unix_spec.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/spec/unix_spec.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/spec/unix_spec.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/spec/unix_spec.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/spec/unix_spec.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/spec/unix_spec.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/spec/unix_spec.rb
tdiary-5.0.13 vendor/bundle/gems/childprocess-0.9.0/spec/unix_spec.rb
tdiary-5.0.12.1 vendor/bundle/gems/childprocess-0.9.0/spec/unix_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/spec/unix_spec.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/childprocess-0.6.3/spec/unix_spec.rb
childprocess-1.0.0 spec/unix_spec.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/spec/unix_spec.rb
tdiary-5.0.11 vendor/bundle/gems/childprocess-0.9.0/spec/unix_spec.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/spec/unix_spec.rb
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/childprocess-0.6.3/spec/unix_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/childprocess-0.9.0/spec/unix_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/childprocess-0.9.0/spec/unix_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/childprocess-0.9.0/spec/unix_spec.rb