about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-03-10 17:24:02 -0800
committerEric Wong <normalperson@yhbt.net>2011-03-10 18:17:37 -0800
commite87875ba261fa5b0cd328bcf03e666e2d9078114 (patch)
treedab40b2e87cda1b6e7152ef8f108234ba2408a95 /test
parente516e45640206fa3e7864938da74a7cb5ca31715 (diff)
downloadraindrops-e87875ba261fa5b0cd328bcf03e666e2d9078114.tar.gz
Raindrops is designed to work with forking servers after all.
Diffstat (limited to 'test')
-rw-r--r--test/test_raindrops.rb20
-rw-r--r--test/test_raindrops_gc.rb21
2 files changed, 41 insertions, 0 deletions
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