Rev 4717: add a test that Key.intern() doesn't create an immortal object. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-memory-consumption

John Arbash Meinel john at arbash-meinel.com
Wed Sep 30 18:31:16 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-memory-consumption

------------------------------------------------------------
revno: 4717
revision-id: john at arbash-meinel.com-20090930173110-p03w37bugnjkbtao
parent: john at arbash-meinel.com-20090930170200-wbwxxcyiizc3w05u
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-memory-consumption
timestamp: Wed 2009-09-30 12:31:10 -0500
message:
  add a test that Key.intern() doesn't create an immortal object.
-------------- next part --------------
=== modified file 'bzrlib/tests/test__keys_type.py'
--- a/bzrlib/tests/test__keys_type.py	2009-09-30 16:50:51 +0000
+++ b/bzrlib/tests/test__keys_type.py	2009-09-30 17:31:10 +0000
@@ -388,3 +388,23 @@
         # We have one more ref in 'key2' but otherwise no extra refs
         self.assertEqual(3, sys.getrefcount(key))
         self.assertIs(key, key2)
+
+    def test__c_keys_are_not_immortal(self):
+        if self.module is _keys_type_py:
+            return # Not applicable
+        unique_str1 = 'unique str ' + osutils.rand_chars(20)
+        unique_str2 = 'unique str ' + osutils.rand_chars(20)
+        key = self.module.Key(unique_str1, unique_str2)
+        self.assertFalse(key in self.module._interned_keys)
+        self.assertEqual(2, sys.getrefcount(key))
+        key = key.intern()
+        self.assertEqual(2, sys.getrefcount(key))
+        self.assertTrue(key in self.module._interned_keys)
+        self.assertTrue(key._is_interned())
+        del key
+        # Create a new entry, which would point to the same location
+        key = self.module.Key(unique_str1, unique_str2)
+        self.assertEqual(2, sys.getrefcount(key))
+        # This old entry in _interned_keys should be gone
+        self.assertFalse(key in self.module._interned_keys)
+        self.assertFalse(key._is_interned())



More information about the bazaar-commits mailing list