Class: TestProcessWatch

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb

Defined Under Namespace

Modules: ChildProcessWatcher, ParentProcessWatcher

Instance Method Summary collapse

Instance Method Details

#setupObject



22
23
24
# File 'lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb', line 22

def setup
  EM.kqueue = true if EM.kqueue?
end

#teardownObject



26
27
28
# File 'lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb', line 26

def teardown
  EM.kqueue = false if EM.kqueue?
end

#test_eventsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ext/eventmachine-0.12.10/tests/test_process_watch.rb', line 30

def test_events
  EM.run{
    # watch ourselves for a fork notification
    EM.watch_process(Process.pid, ParentProcessWatcher)
    $fork_pid = fork{ sleep }
    child = EM.watch_process($fork_pid, ChildProcessWatcher)
    $pid = child.pid

    EM.add_timer(0.5){
      Process.kill('TERM', $fork_pid)
    }
  }

  assert_equal($pid, $fork_pid)
  assert($forked)
  assert($exited)
  assert($unbind)
end