forked from eventmachine/eventmachine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_process_watch.rb
50 lines (43 loc) · 962 Bytes
/
test_process_watch.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
$:.unshift "../lib"
require 'eventmachine'
require 'test/unit'
if EM.kqueue?
class TestProcessWatch < Test::Unit::TestCase
module ParentProcessWatcher
def process_forked
$forked = true
end
end
module ChildProcessWatcher
def process_exited
$exited = true
end
def unbind
$unbind = true
EM.stop
end
end
def setup
EM.kqueue = true
end
def teardown
EM.kqueue = false
end
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.2){
Process.kill('TERM', $fork_pid)
}
}
assert_equal($pid, $fork_pid)
assert($forked)
assert($exited)
assert($unbind)
end
end
end