File: test_raindrops_gc.rb

package info (click to toggle)
ruby-raindrops 0.20.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 500 kB
  • sloc: ruby: 3,537; ansic: 1,029; sh: 32; makefile: 9
file content (38 lines) | stat: -rw-r--r-- 958 bytes parent folder | download | duplicates (8)
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
# -*- encoding: binary -*-
require 'test/unit'
require 'raindrops'

class TestRaindropsGc < Test::Unit::TestCase

  # we may need to create more garbage as GC may be less aggressive
  # about expiring things.  This is completely unrealistic code,
  # though...
  def test_gc
    assert_nothing_raised do
      1000000.times { |i| Raindrops.new(24); [] }
    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 if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" &&
       ENV["STRESS"].to_i != 0