From 38da005297850b53bbf2f66318025e5b0d8d3be7 Mon Sep 17 00:00:00 2001
From: Yoshinori Okuji <yo@nexedi.com>
Date: Fri, 28 Oct 2005 11:48:26 +0000
Subject: [PATCH] Add a test for transaction-safe uid buffer.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@4160 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Catalog/tests/testERP5Catalog.py | 25 +++++++++++++++-----
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/product/ERP5Catalog/tests/testERP5Catalog.py b/product/ERP5Catalog/tests/testERP5Catalog.py
index 9d23790746..99a7b93099 100755
--- a/product/ERP5Catalog/tests/testERP5Catalog.py
+++ b/product/ERP5Catalog/tests/testERP5Catalog.py
@@ -349,15 +349,28 @@ class TestERP5Catalog(ERP5TypeTestCase):
     folder_object_list = [x.getObject().getTitle() for x in person_module.searchFolder(sort_on=[('title','ascending','int')])]
     self.assertEquals(['1','2','12'],folder_object_list)
 
-  def atest_99_BadCatalog(self, quiet=0, run=run_all_test):
-    """
-    We should make sure that if a catalog method fails,
-    then we will have an error on the user interface.
-    """
+  def test_12_TransactionalUidBuffer(self, quiet=0, run=run_all_test):
     if not run: return
     if not quiet:
-      message = 'Test Bad Catalog'
+      message = 'Transactional Uid Buffer'
       ZopeTestCase._print('\n%s ' % message)
       LOG('Testing... ',0,message)
 
+    portal_catalog = self.getCatalogTool()
+    catalog = portal_catalog.getSQLCatalog()
+    self.failUnless(catalog is not None)
+
+    # Clear out the uid buffer.
+    if hasattr(catalog, '_v_uid_buffer'):
+      del catalog._v_uid_buffer
+
+    # Need to abort a transaction artificially, so commit the current
+    # one, first.
+    get_transaction().commit()
+
+    catalog.newUid()
+    self.failUnless(hasattr(catalog, '_v_uid_buffer'))
+    self.failUnless(len(catalog._v_uid_buffer) > 0)
 
+    get_transaction().abort()
+    self.failUnless(len(getattr(catalog, '_v_uid_buffer', [])) == 0)
-- 
2.30.9