From 63c34dd7b826a7887a7412250240d01054c68ef7 Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Sun, 16 Aug 2009 19:13:22 +0000
Subject: [PATCH] Fix TestERP5Administration.test_01_RunCheckStockTableAlarm

The test randomly failed since it was created because of low resolution of
creation_date column (in catalog table): Alarm.getLastActiveProcess failed
when the 2 last active processes were created in the same second.

This commit is a hack that relies on the fact that a new Active Process always
has an ID higher than previously created Active Processes.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28401 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/Alarm.py               | 4 +++-
 product/ERP5/tests/testERP5Administration.py | 6 +++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/product/ERP5/Document/Alarm.py b/product/ERP5/Document/Alarm.py
index 4d1589aa8d..81e5b614ba 100644
--- a/product/ERP5/Document/Alarm.py
+++ b/product/ERP5/Document/Alarm.py
@@ -508,7 +508,9 @@ Alarm Tool Node: %s
       limit = self.isActive() and 2 or 1
     active_process_list = self.getPortalObject().portal_catalog(
       portal_type='Active Process', limit=limit,
-      sort_on=(('creation_date', 'DESC'), ),
+      sort_on=(('creation_date', 'DESC'),
+               # XXX Work around poor resolution of MySQL dates.
+               ('CONVERT(`catalog`.`id`, UNSIGNED)', 'DESC')),
       causality_uid=self.getUid())
     if len(active_process_list) < limit:
       process = None
diff --git a/product/ERP5/tests/testERP5Administration.py b/product/ERP5/tests/testERP5Administration.py
index 4044c4f322..df131d3c5e 100644
--- a/product/ERP5/tests/testERP5Administration.py
+++ b/product/ERP5/tests/testERP5Administration.py
@@ -38,7 +38,7 @@ class TestERP5Administration(InventoryAPITestCase):
     return "ERP5Administration"
 
   def getBusinessTemplateList(self):
-    """ 
+    """
         Same list as for Inventory API and add erp5_administration
     """
     return InventoryAPITestCase.getBusinessTemplateList(self) + ('erp5_administration',)
@@ -53,7 +53,7 @@ class TestERP5Administration(InventoryAPITestCase):
     alarm = portal.portal_alarms.check_stock
 
     def checkActiveProcess(failed):
-      transaction.get().commit()
+      transaction.commit()
       self.tic()
       self.assertEqual(alarm.getLastActiveProcess().ActiveProcess_sense(),
                        failed)
@@ -68,7 +68,7 @@ class TestERP5Administration(InventoryAPITestCase):
 
     alarm.setAlarmNotificationMode('never')
     mvt = self._makeMovement(quantity=1.23)
-    transaction.get().commit()
+    transaction.commit()
     self.tic()
     alarm.activeSense()
     checkActiveProcess(0)
-- 
2.30.9