From 4b5ab02957ed94ff24f9105f6cf65fdee633785b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9gory=20Wisniewski?= <gregory@nexedi.com>
Date: Wed, 5 Aug 2009 14:42:18 +0000
Subject: [PATCH] Genericize expectMasterState(), wait after a kill() in
 __del__.

git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1199 71dcc9de-d417-0410-9af5-da40c76e7ee4
---
 neo/tests/functional/__init__.py | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/neo/tests/functional/__init__.py b/neo/tests/functional/__init__.py
index 9788806a..c887ae95 100644
--- a/neo/tests/functional/__init__.py
+++ b/neo/tests/functional/__init__.py
@@ -119,6 +119,7 @@ class NEOProcess:
         # If we get killed, kill subprocesses aswell.
         try:
             self.kill(signal.SIGKILL)
+            self.wait()
         except:
             # We can ignore all exceptions at this point, since there is no
             # garanteed way to handle them (other objects we would depend on
@@ -333,8 +334,8 @@ class NEOCluster(object):
     def getStorageNodeList(self, state=None):
         return self.__getNodeList(protocol.STORAGE_NODE_TYPE, state)
 
-    def getMasterNodeState(self, uuid):
-        node_list = self.getMasterNodeList()
+    def __getNodeState(self, node_type, uuid):
+        node_list = self.__getNodeList(node_type)
         for node_type, address, node_uuid, state in node_list:
             if node_uuid == uuid:
                 break
@@ -342,6 +343,9 @@ class NEOCluster(object):
             state = None
         return state
 
+    def getMasterNodeState(self, uuid):
+        return self.__getNodeState(protocol.MASTER_NODE_TYPE, uuid)
+
     def getPrimaryMaster(self):
         try:
             current_try = self.neoctl.getPrimaryMaster()
@@ -373,13 +377,21 @@ class NEOCluster(object):
             return (current_try == node_count, current_try)
         self.expectCondition(callback, timeout, delay)
 
-    def expectMasterState(self, uuid, state, timeout=0, delay=1):
+    def __expectNodeState(self, node_type, uuid, state, timeout=0, delay=1):
         if not isinstance(state, (tuple, list)):
             state = (state, )
         def callback(last_try):
-            current_try = self.getMasterNodeState(uuid)
+            current_try = self.__getNodeState(node_type, uuid)
             return current_try in state, current_try
         self.expectCondition(callback, timeout, delay)
+        
+    def expectMasterState(self, uuid, state, timeout=0, delay=1):
+        self.__expectNodeState(protocol.MASTER_NODE_TYPE, uuid, state, timeout,
+                delay)
+
+    def expectStorageState(self, uuid, state, timeout=0, delay=1):
+        self.__expectNodeState(protocol.STORAGE_NODE_TYPE, uuid, state, 
+                timeout,delay)
 
     def expectPrimaryMaster(self, uuid=None, timeout=0, delay=1):
         def callback(last_try):
-- 
2.30.9