From e87875ba261fa5b0cd328bcf03e666e2d9078114 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 10 Mar 2011 17:24:02 -0800 Subject: [PATCH] tests: ensure munmap() in children don't muck up the parent Raindrops is designed to work with forking servers after all. --- test/test_raindrops.rb | 20 ++++++++++++++++++++ test/test_raindrops_gc.rb | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/test/test_raindrops.rb b/test/test_raindrops.rb index a26d0e1..67089b7 100644 --- a/test/test_raindrops.rb +++ b/test/test_raindrops.rb @@ -142,4 +142,24 @@ class TestRaindrops < Test::Unit::TestCase assert_nil rd.evaporate! assert_raises(StandardError) { rd.evaporate! } end + + def test_evaporate_with_fork + tmp = Raindrops.new 2 + pid = fork do + tmp.incr 0 + exit(tmp.evaporate! == nil) + end + _, status = Process.waitpid2(pid) + assert status.success? + assert_equal [ 1, 0 ], tmp.to_ary + tmp.incr 1 + assert_equal [ 1, 1 ], tmp.to_ary + pid = fork do + tmp.incr 1 + exit([ 1, 2 ] == tmp.to_ary) + end + _, status = Process.waitpid2(pid) + assert status.success? + assert_equal [ 1, 2 ], tmp.to_ary + end end diff --git a/test/test_raindrops_gc.rb b/test/test_raindrops_gc.rb index a1fc3de..209b4ed 100644 --- a/test/test_raindrops_gc.rb +++ b/test/test_raindrops_gc.rb @@ -13,4 +13,25 @@ class TestRaindropsGc < Test::Unit::TestCase end end + def test_gc_postfork + tmp = Raindrops.new 2 + pid = fork do + 1000000.times do + tmp = Raindrops.new 2 + tmp.to_ary + end + end + _, status = Process.waitpid2(pid) + assert status.success? + assert_equal [ 0, 0 ], tmp.to_ary + tmp.incr 1 + assert_equal [ 0, 1 ], tmp.to_ary + pid = fork do + tmp.incr 1 + exit([ 0, 2 ] == tmp.to_ary) + end + _, status = Process.waitpid2(pid) + assert status.success? + assert_equal [ 0, 2 ], tmp.to_ary + end end -- 2.11.4.GIT