NO-JIRA: Fix tests/fdlimit.py to work on python 2.6

Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/a518b1ce
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/a518b1ce
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/a518b1ce

Branch: refs/heads/go1
Commit: a518b1ce98ca90ed9ce7541dde789004697338a3
Parents: e238bb6
Author: Alan Conway <acon...@redhat.com>
Authored: Mon Oct 16 13:33:48 2017 +0100
Committer: Alan Conway <acon...@redhat.com>
Committed: Mon Oct 16 13:33:48 2017 +0100

----------------------------------------------------------------------
 proton-c/src/tests/fdlimit.py | 69 ++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/a518b1ce/proton-c/src/tests/fdlimit.py
----------------------------------------------------------------------
diff --git a/proton-c/src/tests/fdlimit.py b/proton-c/src/tests/fdlimit.py
index 4f4a342..beb00a8 100644
--- a/proton-c/src/tests/fdlimit.py
+++ b/proton-c/src/tests/fdlimit.py
@@ -41,48 +41,43 @@ class LimitedBroker(object):
 # Check if we can run prlimit to control resources
 try:
     Proc(["prlimit"]).wait_exit()
-    has_prlimit = True
-except:
-    has_prlimit = False
 
-class FdLimitTest(ProcTestCase):
+    class FdLimitTest(ProcTestCase):
+
+        def proc(self, *args, **kwargs):
+            """Skip valgrind for all processes started by this test"""
+            return super(FdLimitTest, self).proc(*args, valgrind=False, 
**kwargs)
 
-    def setUp(self):
-        global has_prlimit
-        if not has_prlimit:
-            self.skipTest("prlimit not available")
-        super(FdLimitTest, self).setUp()
+        def test_fd_limit_broker(self):
+            """Check behaviour when running out of file descriptors on 
accept"""
+            # Not too many FDs but not too few either, some are used for 
system purposes.
+            fdlimit = 256
+            with LimitedBroker(self, fdlimit) as b:
+                receivers = []
+                # Start enough receivers to use all FDs, make sure the broker 
logs an error
+                for i in xrange(fdlimit+1):
+                    receivers.append(self.proc(["receive", "", b.port, 
str(i)]))
 
-    def proc(self, *args, **kwargs):
-        """Skip valgrind for all processes started by this test"""
-        return super(FdLimitTest, self).proc(*args, valgrind=False, **kwargs)
+                # Note: libuv silently swallows EMFILE/ENFILE errors so there 
is no error reporting.
+                # The epoll proactor will close the users connection with the 
EMFILE/ENFILE error
+                if "TRANSPORT_CLOSED" in b.proc.out:
+                    self.assertIn("open files", b.proc.out)
 
-    def test_fd_limit_broker(self):
-        """Check behaviour when running out of file descriptors on accept"""
-        # Not too many FDs but not too few either, some are used for system 
purposes.
-        fdlimit = 256
-        with LimitedBroker(self, fdlimit) as b:
-            receivers = []
-            # Start enough receivers to use all FDs, make sure the broker logs 
an error
-            for i in xrange(fdlimit+1):
-                receivers.append(self.proc(["receive", "", b.port, str(i)]))
+                # All FDs are now in use, send attempt should fail or hang
+                self.assertIn(self.proc(["send", "", b.port, "x"]).poll(), [1, 
None])
 
-            # Note: libuv silently swallows EMFILE/ENFILE errors so there is 
no error reporting.
-            # The epoll proactor will close the users connection with the 
EMFILE/ENFILE error
-            if "TRANSPORT_CLOSED" in b.proc.out:
-                self.assertIn("open files", b.proc.out)
+                # Kill receivers to free up FDs
+                for r in receivers:
+                    r.kill()
+                for r in receivers:
+                    r.wait_exit(expect=None)
+                # send/receive should succeed now
+                self.assertIn("10 messages sent", self.proc(["send", "", 
b.port]).wait_exit())
+                self.assertIn("10 messages received", self.proc(["receive", 
"", b.port]).wait_exit())
 
-            # All FDs are now in use, send attempt should fail or hang
-            self.assertIn(self.proc(["send", "", b.port, "x"]).poll(), [1, 
None])
+    if __name__ == "__main__":
+        main()
 
-            # Kill receivers to free up FDs
-            for r in receivers:
-                r.kill()
-            for r in receivers:
-                r.wait_exit(expect=None)
-            # send/receive should succeed now
-            self.assertIn("10 messages sent", self.proc(["send", "", 
b.port]).wait_exit())
-            self.assertIn("10 messages received", self.proc(["receive", "", 
b.port]).wait_exit())
+except:
+    print "Skipping test: prlimit not available"
 
-if __name__ == "__main__":
-    main()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to