README: update with extra disclaimer
[raindrops.git] / test / test_raindrops_gc.rb
bloba9f20265a1ea6dee8579900c9b82305798723cbd
1 # -*- encoding: binary -*-
2 # frozen_string_literal: false
3 require 'test/unit'
4 require 'raindrops'
6 class TestRaindropsGc < Test::Unit::TestCase
8   # we may need to create more garbage as GC may be less aggressive
9   # about expiring things.  This is completely unrealistic code,
10   # though...
11   def test_gc
12     assert_nothing_raised do
13       1000000.times { |i| Raindrops.new(24); [] }
14     end
15   end
17   def test_gc_postfork
18     tmp = Raindrops.new 2
19     pid = fork do
20       1000000.times do
21         tmp = Raindrops.new 2
22         tmp.to_ary
23       end
24     end
25     _, status = Process.waitpid2(pid)
26     assert status.success?
27     assert_equal [ 0, 0 ], tmp.to_ary
28     tmp.incr 1
29     assert_equal [ 0, 1 ], tmp.to_ary
30     pid = fork do
31       tmp.incr 1
32       exit([ 0, 2 ] == tmp.to_ary)
33     end
34     _, status = Process.waitpid2(pid)
35     assert status.success?
36     assert_equal [ 0, 2 ], tmp.to_ary
37   end
38 end if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" &&
39        ENV["STRESS"].to_i != 0