Author: aconway
Date: Mon Jun 30 21:43:12 2014
New Revision: 1606938

URL: http://svn.apache.org/r1606938
Log:
NO-JIRA: Fix problems with system tests.

- Skip system_tests_broker if its requirements (qpidd etc.) are not installed.
- Fix logic for creating/deleting test directories, was failing on old python.

Modified:
    qpid/dispatch/trunk/tests/system_test.py
    qpid/dispatch/trunk/tests/system_tests_broker.py
    qpid/dispatch/trunk/tests/system_tests_management.py

Modified: qpid/dispatch/trunk/tests/system_test.py
URL: 
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_test.py?rev=1606938&r1=1606937&r2=1606938&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_test.py (original)
+++ qpid/dispatch/trunk/tests/system_test.py Mon Jun 30 21:43:12 2014
@@ -19,6 +19,7 @@
 
 """System test library, provides tools for tests that start multiple processes,
 with special support for qpidd and qdrouter processes.
+
 Features:
 - Create separate directories for each test.
 - Save logs, sub-process output, core files etc.
@@ -26,8 +27,7 @@ Features:
 - Tools to manipulate qpidd and qdrouter configuration files.
 - Sundry other tools.
 
-Requires the following:
- - proton with python bindings
+To run qpidd, additional to basic dispatch requirements:
  - qpidd with AMQP 1.0 support
  - qpidtoollibs python module from qpid/tools
  - qpid_messaging python module from qpid/cpp
@@ -95,7 +95,7 @@ def _check_requirements():
     """If requirements are missing, return a message, else return empty 
string."""
     missing = MISSING_MODULES
     required_exes = ['qpidd', 'qdrouterd']
-    missing += ["No exectuable  %s"%e for e in required_exes if not 
find_exe(e)]
+    missing += ["No exectuable %s"%e for e in required_exes if not find_exe(e)]
     if find_exe('qpidd'):
         p = subprocess.Popen(['qpidd', '--help'], stdout=subprocess.PIPE)
         if not "AMQP 1.0" in p.communicate()[0]:
@@ -221,7 +221,11 @@ class Process(subprocess.Popen):
         kwargs.setdefault('stdout', self.out)
         kwargs.setdefault('stderr', kwargs['stdout'])
         args = with_valgrind(args)
-        super(Process, self).__init__(args, **kwargs)
+        try:
+            super(Process, self).__init__(args, **kwargs)
+        except Exception, e:
+            raise Exception("subprocess.Popen(%s, %s) failed: %s: %s" %
+                            (args, kwargs, type(e).__name__, e))
 
     def assert_running(self):
         """Assert that the proces is still running"""
@@ -267,11 +271,6 @@ class Config(object):
             f.write(str(self))
         return name
 
-    # def __getitem(self, key):
-    #     """Get an item, make sure any defaults have been set first"""
-    #     # defaults()
-    #     return super(Config, self).__getitem__(self, key)
-
 class Qdrouterd(Process):
     """Run a Qpid Dispatch Router Daemon"""
 
@@ -480,17 +479,22 @@ class Tester(object):
 
     # Wipe the old test tree when we are first imported.
     root_dir = os.path.abspath(__name__+'.dir')
-    shutil.rmtree(root_dir, ignore_errors=True) # Wipe the old test tree.
 
-    def __init__(self, id, *args, **kwargs):
+    def __init__(self, id):
         """
         @param id: module.class.method or False if no directory should be 
created
         """
+        self.directory = os.path.join(self.root_dir, *id.split('.'))
         self.cleanup_list = []
-        if id:                  # not id: means don't create a directory.
-            self.directory = os.path.join(self.root_dir, *id.split('.'))
-            os.makedirs(self.directory)
-            os.chdir(self.directory)
+
+    def rmtree(self):
+        """Remove old test class results directory"""
+        shutil.rmtree(os.path.dirname(self.directory), ignore_errors=True)
+
+    def setup(self):
+        """Called from test setup and class setup."""
+        os.makedirs(self.directory)
+        os.chdir(self.directory)
 
     def teardown(self):
         """Clean up (tear-down, stop or close) objects recorded via 
cleanup()"""
@@ -554,30 +558,34 @@ class TestCase(unittest.TestCase, Tester
 
     def __init__(self, test_method):
         unittest.TestCase.__init__(self, test_method)
-        # Older python will create an instance of TestCase itself as well as
-        # subclasses, we don't want the Tester to create a directory in that 
case.
-        Tester.__init__(self, self.__class__ is not TestCase and self.id())
+        Tester.__init__(self, self.id())
 
     @classmethod
     def setUpClass(cls):
-        # Python < 2.7 will call setUpClass on the system_test.TestCase class
-        # itself as well as the subclasses. Ignore that.
-        if cls is not TestCase:
-            cls.tester = Tester('.'.join([cls.__module__, cls.__name__, 
'setUpClass']))
+        cls.tester = Tester('.'.join([cls.__module__, cls.__name__, 
'setUpClass']))
+        cls.tester.rmtree()
+        cls.tester.setup()
 
     @classmethod
     def tearDownClass(cls):
-        if inspect.isclass(cls) and cls is not TestCase and hasattr(cls, 
'tester'):
+        if hasattr(cls, 'tester'):
             cls.tester.teardown()
             del cls.tester
 
     def setUp(self):
+        # Python < 2.7 will call setUp on the system_test.TestCase class
+        # itself as well as the subclasses. Ignore that.
+        if self.__class__ is TestCase: return
         # Hack to support setUpClass on older python.
         # If the class has not already been set up, do it now.
-        if self.__class__ is not TestCase and not hasattr(self.__class__, 
'tester'):
+        if not hasattr(self.__class__, 'tester'):
             self.setUpClass()
+        Tester.setup(self)
 
     def tearDown(self):
+        # Python < 2.7 will call tearDown on the system_test.TestCase class
+        # itself as well as the subclasses. Ignore that.
+        if self.__class__ is TestCase: return
         Tester.teardown(self)
         # Hack to support tearDownClass on older versions of python.
         if hasattr(self.__class__, '_tear_down_class'):
@@ -589,13 +597,13 @@ class TestCase(unittest.TestCase, Tester
         if hasattr(unittest.TestCase, 'skipTest'):
             unittest.TestCase.skipTest(self, reason)
         else:
-            print "Skipping test", id(), reason
+            print "Skipping test", self.id(), reason
 
     # Hack to support tearDownClass on older versions of python.
     # The default TestLoader sorts tests alphabetically so we insert
     # a fake tests that will run last to call tearDownClass.
     # NOTE: definitely not safe for a parallel test-runner.
-    if not hasattr(unittest.TestCase, 'setUpClass'):
+    if not hasattr(unittest.TestCase, 'tearDownClass'):
         def test_zzzz_teardown_class(self):
             """Fake test to call tearDownClass"""
             if self.__class__ is not TestCase:

Modified: qpid/dispatch/trunk/tests/system_tests_broker.py
URL: 
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_tests_broker.py?rev=1606938&r1=1606937&r2=1606938&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_tests_broker.py (original)
+++ qpid/dispatch/trunk/tests/system_tests_broker.py Mon Jun 30 21:43:12 2014
@@ -28,84 +28,84 @@ from itertools import cycle
 class DistributedQueueTest(system_test.TestCase): # pylint: 
disable=too-many-public-methods
     """System tests involving routers and qpidd brokers"""
 
-    @classmethod
-    def setUpClass(cls):
-        """Start 3 qpidd brokers, wait for them to be ready."""
-        super(DistributedQueueTest, cls).setUpClass()
-        cls.qpidds = [cls.tester.qpidd('qpidd%s'%i, port=cls.get_port(), 
wait=False)
-                    for i in xrange(3)]
-        for q in cls.qpidds:
-            q.wait_ready()
-
-    @classmethod
-    def tearDownClass(cls):
-        super(DistributedQueueTest, cls).tearDownClass()
-
-    def setUp(self):
-        super(DistributedQueueTest, self).setUp()
-        self.testq = 'testq.'+self.id().split('.')[-1] # The distributed queue 
name
-
-    def common_router_conf(self, name, mode='standalone'):
-        """Common router configuration for the tests"""
-        return Qdrouterd.Config([
-            # ('log', {'module':'DEFAULT', 'level':'info', 
'output':name+".log"}),
-            # ('log', {'module':'ROUTER', 'level':'trace'}),
-            # ('log', {'module':'MESSAGE', 'level':'trace'}),
-            ('container', {'container-name':name}),
-            ('router', {'mode': mode, 'router-id': name})
-        ])
-
-    def verify_equal_spread(self, send_addresses, receive_addresses):
-        """Verify we send/receive to the queue the load was spread over the 
brokers.
-        Send to each of the send_addresses in turn, subscribe to all of the 
receive_addresses.
-        """
-        msgr = self.messenger()
-        for a in receive_addresses:
-            msgr.subscribe(a)
-        msgr.flush()
-        n = 20                  # Messages per broker
-        r = ["x-%02d"%i for i in range(n*len(self.qpidds))]
-        for b, a in zip(r, cycle(send_addresses)):
-            msgr.put(message(address=a, body=b))
-        msgr.flush()
-        messages = sorted(msgr.fetch().body for i in r)
-        msgr.flush()
-        self.assertEqual(r, messages)
-
-        qs = [q.agent.getQueue(self.testq) for q in self.qpidds]
-        enq = sum(q.msgTotalEnqueues for q in qs)
-        deq = sum(q.msgTotalDequeues for q in qs)
-        self.assertEquals((enq, deq), (len(r), len(r)))
-        # Verify each broker handled a reasonable share of the messages.
-        self.assert_fair([q.msgTotalEnqueues for q in qs])
-
-    def test_distrbuted_queue(self):
-        """Create a distributed queue with N routers and N brokers.
-        Each router is connected to all the brokers."""
-        for q in self.qpidds:
-            q.agent.addQueue(self.testq)
-
-        def router(i):
-            """Create router<i> with waypoints to each broker."""
-            name = "router%s"%i
-            rconf = self.common_router_conf(name, mode='interior')
-            rconf += [
-                ('listener', {'port':self.get_port(), 'role':'normal'}),
-                ('fixed-address', {'prefix':self.testq, 'phase':0, 
'fanout':'single', 'bias':'spread'}),
-                ('fixed-address', {'prefix':self.testq, 'phase':1, 
'fanout':'single', 'bias':'spread'})]
+    if MISSING_REQUIREMENTS:
+        def test_skip(self):
+            self.skipTest(MISSING_REQUIREMENTS)
+    else:
+        @classmethod
+        def setUpClass(cls):
+            """Start 3 qpidd brokers, wait for them to be ready."""
+            super(DistributedQueueTest, cls).setUpClass()
+            cls.qpidds = [cls.tester.qpidd('qpidd%s'%i, port=cls.get_port(), 
wait=False)
+                        for i in xrange(3)]
+            for q in cls.qpidds:
+                q.wait_ready()
+
+        @classmethod
+        def tearDownClass(cls):
+            super(DistributedQueueTest, cls).tearDownClass()
+
+        def setUp(self):
+            super(DistributedQueueTest, self).setUp()
+            self.testq = 'testq.'+self.id().split('.')[-1] # The distributed 
queue name
+
+        def common_router_conf(self, name, mode='standalone'):
+            """Common router configuration for the tests"""
+            return Qdrouterd.Config([
+                # ('log', {'module':'DEFAULT', 'level':'info', 
'output':name+".log"}),
+                # ('log', {'module':'ROUTER', 'level':'trace'}),
+                # ('log', {'module':'MESSAGE', 'level':'trace'}),
+                ('container', {'container-name':name}),
+                ('router', {'mode': mode, 'router-id': name})
+            ])
+
+        def verify_equal_spread(self, send_addresses, receive_addresses):
+            """Verify we send/receive to the queue the load was spread over 
the brokers.
+            Send to each of the send_addresses in turn, subscribe to all of 
the receive_addresses.
+            """
+            msgr = self.messenger()
+            for a in receive_addresses:
+                msgr.subscribe(a)
+            msgr.flush()
+            n = 20                  # Messages per broker
+            r = ["x-%02d"%i for i in range(n*len(self.qpidds))]
+            for b, a in zip(r, cycle(send_addresses)):
+                msgr.put(message(address=a, body=b))
+            msgr.flush()
+            messages = sorted(msgr.fetch().body for i in r)
+            msgr.flush()
+            self.assertEqual(r, messages)
+
+            qs = [q.agent.getQueue(self.testq) for q in self.qpidds]
+            enq = sum(q.msgTotalEnqueues for q in qs)
+            deq = sum(q.msgTotalDequeues for q in qs)
+            self.assertEquals((enq, deq), (len(r), len(r)))
+            # Verify each broker handled a reasonable share of the messages.
+            self.assert_fair([q.msgTotalEnqueues for q in qs])
+
+        def test_distrbuted_queue(self):
+            """Create a distributed queue with N routers and N brokers.
+            Each router is connected to all the brokers."""
             for q in self.qpidds:
-                rconf += [
-                    ('connector', {'name':q.name, 'port':q.port}),
-                    ('waypoint', {'name':self.testq, 'out-phase':1, 
'in-phase':0, 'connector':q.name})]
-            return self.qdrouterd(name, rconf)
-        routers = [router(i) for i in xrange(len(self.qpidds))]
-        for r in routers: r.wait_ready()
-        addrs = [r.addresses[0]+"/"+self.testq for r in routers]
-        self.verify_equal_spread(addrs, addrs)
+                q.agent.addQueue(self.testq)
 
+            def router(i):
+                """Create router<i> with waypoints to each broker."""
+                name = "router%s"%i
+                rconf = self.common_router_conf(name, mode='interior')
+                rconf += [
+                    ('listener', {'port':self.get_port(), 'role':'normal'}),
+                    ('fixed-address', {'prefix':self.testq, 'phase':0, 
'fanout':'single', 'bias':'spread'}),
+                    ('fixed-address', {'prefix':self.testq, 'phase':1, 
'fanout':'single', 'bias':'spread'})]
+                for q in self.qpidds:
+                    rconf += [
+                        ('connector', {'name':q.name, 'port':q.port}),
+                        ('waypoint', {'name':self.testq, 'out-phase':1, 
'in-phase':0, 'connector':q.name})]
+                return self.qdrouterd(name, rconf)
+            routers = [router(i) for i in xrange(len(self.qpidds))]
+            for r in routers: r.wait_ready()
+            addrs = [r.addresses[0]+"/"+self.testq for r in routers]
+            self.verify_equal_spread(addrs, addrs)
 
 if __name__ == '__main__':
-    if MISSING_REQUIREMENTS:
-        print MISSING_REQUIREMENTS
-    else:
-        unittest.main()
+    unittest.main()

Modified: qpid/dispatch/trunk/tests/system_tests_management.py
URL: 
http://svn.apache.org/viewvc/qpid/dispatch/trunk/tests/system_tests_management.py?rev=1606938&r1=1606937&r2=1606938&view=diff
==============================================================================
--- qpid/dispatch/trunk/tests/system_tests_management.py (original)
+++ qpid/dispatch/trunk/tests/system_tests_management.py Mon Jun 30 21:43:12 
2014
@@ -21,7 +21,7 @@
 
 import unittest, system_test, re
 from qpid_dispatch_internal.management import Node, ManagementError
-from system_test import Qdrouterd, MISSING_REQUIREMENTS
+from system_test import Qdrouterd
 from httplib import BAD_REQUEST, NOT_IMPLEMENTED
 
 class ManagementTest(system_test.TestCase): # pylint: 
disable=too-many-public-methods
@@ -95,7 +95,4 @@ class ManagementTest(system_test.TestCas
         except: pass
 
 if __name__ == '__main__':
-    if MISSING_REQUIREMENTS:
-        print MISSING_REQUIREMENTS
-    else:
-        unittest.main()
+    unittest.main()



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to