about summary refs log tree commit
path: root/test/test_gc.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_gc.rb')
-rw-r--r--test/test_gc.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/test_gc.rb b/test/test_gc.rb
new file mode 100644
index 0000000..d567696
--- /dev/null
+++ b/test/test_gc.rb
@@ -0,0 +1,39 @@
+require 'test/unit'
+require 'rpatricia'
+
+# this takes a while, watch memory usage not grow in top(1) or similar
+
+class TestGc < Test::Unit::TestCase
+
+  def setup
+    @arrays = Patricia.new
+    @arrays.add('10.0.0.0/8', [])
+    @arrays.add('127.0.0.0/24', [])
+
+    @strings = Patricia.new
+    @strings.add('10.0.0.0/8', "big lan")
+    @strings.add('127.0.0.0/24', "localhost")
+  end
+
+  def test_gc
+    assert_nothing_raised do
+      10_000_000.times do
+        t = Patricia.new
+        t.add('10.0.0.0/8', {})
+        t.add('127.0.0.0/24', "home sweet home")
+      end
+    end
+
+    # ensure what we created originally didn't get GC-ed'
+    100.times do
+      assert_equal [], @arrays.match_best('127.0.0.1').data
+      assert_equal "localhost", @strings.match_best('127.0.0.1').data
+    end
+  end
+
+  def test_destroy
+    assert @strings.destroy
+    assert @strings.destroy
+  end
+
+end