Sha256: 4d99e3662988d98e323e9add23f047e94373d7eb74f2cbb1e19f6d79981da473

Contents?: true

Size: 1.31 KB

Versions: 12

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require_relative 'helper'

class ProcessSupervisionTest < MiniTest::Test
  def test_process_supervisor_with_block
    i, o = IO.pipe

    watcher = spin do
      Polyphony.watch_process do
        i.close
        sleep 5
      ensure
        o << 'foo'
        o.close
      end
    end

    supervisor = spin { supervise(watcher, restart: :always) }

    sleep 0.05
    supervisor.terminate
    supervisor.await

    o.close
    msg = i.read
    assert_equal 'foo', msg
  end

  def test_process_supervisor_restart_with_block
    i1, o1 = IO.pipe
    i2, o2 = IO.pipe

    count = 0
    watcher = spin do
      count += 1
      Polyphony.watch_process do
        i1.gets
        o2.puts count
      end
    end

    supervisor = spin { supervise(watcher, restart: :always) }

    o1.puts
    l = i2.gets
    assert_equal "1\n", l

    o1.puts
    l = i2.gets
    assert_equal "2\n", l

    o1.puts
    l = i2.gets
    assert_equal "3\n", l
  end

  def test_process_supervisor_with_cmd
    fn = '/tmp/test_process_supervisor_with_cmd'
    FileUtils.rm(fn) rescue nil

    watcher = spin do
      Polyphony.watch_process("echo foo >> #{fn}")
    end

    supervisor = spin { supervise(watcher) }

    sleep 0.1
    supervisor.terminate
    supervisor.await

    assert_equal "foo\n", IO.read(fn)

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
polyphony-0.82 test/test_process_supervision.rb
polyphony-0.81.1 test/test_process_supervision.rb
polyphony-0.81 test/test_process_supervision.rb
polyphony-0.80 test/test_process_supervision.rb
polyphony-0.79 test/test_process_supervision.rb
polyphony-0.78 test/test_process_supervision.rb
polyphony-0.77 test/test_process_supervision.rb
polyphony-0.76 test/test_process_supervision.rb
polyphony-0.75 test/test_process_supervision.rb
polyphony-0.74 test/test_process_supervision.rb
polyphony-0.73.1 test/test_process_supervision.rb
polyphony-0.73 test/test_process_supervision.rb