qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jda...@apache.org
Subject [qpid-proton] branch master updated: PROTON-2220: smarter accounting for file descriptors in tests (#259)
Date Tue, 09 Jun 2020 13:23:48 GMT
This is an automated email from the ASF dual-hosted git repository.

jdanek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git


The following commit(s) were added to refs/heads/master by this push:
     new e4af698  PROTON-2220: smarter accounting for file descriptors in tests (#259)
e4af698 is described below

commit e4af6984b06bf663a14c4c0847c81f175828567b
Author: Jiri Daněk <jdanek@redhat.com>
AuthorDate: Tue Jun 9 15:23:39 2020 +0200

    PROTON-2220: smarter accounting for file descriptors in tests (#259)
---
 ...test_PROTON_1800_syncrequestresponse_fd_leak.py | 23 +++++++++++++---------
 ...test_PROTON_2121_blocking_connection_fd_leak.py | 14 ++++++-------
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/python/tests/integration/test_PROTON_1800_syncrequestresponse_fd_leak.py b/python/tests/integration/test_PROTON_1800_syncrequestresponse_fd_leak.py
index 08afc86..62134c2 100644
--- a/python/tests/integration/test_PROTON_1800_syncrequestresponse_fd_leak.py
+++ b/python/tests/integration/test_PROTON_1800_syncrequestresponse_fd_leak.py
@@ -31,6 +31,7 @@ import gc
 import os
 import threading
 import subprocess
+import warnings
 from collections import namedtuple
 
 import cproton
@@ -45,20 +46,24 @@ from proton.handlers import IncomingMessageHandler
 from test_unittest import unittest
 
 
-def count_fds():
-    # type: () -> int
-    return len(os.listdir('/proc/self/fd/'))
+def get_fd_set():
+    # type: () -> set[str]
+    return set(os.listdir('/proc/self/fd/'))
 
 
 @contextlib.contextmanager
 def no_fd_leaks(test):
     # type: (unittest.TestCase) -> None
-    before = count_fds()
-    yield
-    delta = count_fds() - before
-    if delta != 0:
-        subprocess.check_call("ls -lF /proc/{0}/fd/".format(os.getpid()), shell=True)
-        test.assertEqual(0, delta, "Found {0} new fd(s) after the test".format(delta))
+    with warnings.catch_warnings(record=True) as ws:
+        before = get_fd_set()
+        yield
+        delta = get_fd_set().difference(before)
+        if len(delta) != 0:
+            subprocess.check_call("ls -lF /proc/{0}/fd/".format(os.getpid()), shell=True)
+            test.fail("Found {0} new fd(s) after the test".format(delta))
+
+        if len(ws) > 0:
+            test.fail([w.message for w in ws])
 
 
 class Broker(proton.handlers.MessagingHandler):
diff --git a/python/tests/integration/test_PROTON_2121_blocking_connection_fd_leak.py b/python/tests/integration/test_PROTON_2121_blocking_connection_fd_leak.py
index dd6dcbe..97ed624 100644
--- a/python/tests/integration/test_PROTON_2121_blocking_connection_fd_leak.py
+++ b/python/tests/integration/test_PROTON_2121_blocking_connection_fd_leak.py
@@ -42,21 +42,21 @@ import proton.reactor
 from test_unittest import unittest
 
 
-def count_fds():
-    # type: () -> int
-    return len(os.listdir('/proc/self/fd/'))
+def get_fd_set():
+    # type: () -> set[str]
+    return set(os.listdir('/proc/self/fd/'))
 
 
 @contextlib.contextmanager
 def no_fd_leaks(test):
     # type: (unittest.TestCase) -> None
     with warnings.catch_warnings(record=True) as ws:
-        before = count_fds()
+        before = get_fd_set()
         yield
-        delta = count_fds() - before
-        if delta != 0:
+        delta = get_fd_set().difference(before)
+        if len(delta) != 0:
             subprocess.check_call("ls -lF /proc/{0}/fd/".format(os.getpid()), shell=True)
-            test.assertEqual(0, delta, "Found {0} new fd(s) after the test".format(delta))
+            test.fail("Found {0} new fd(s) after the test".format(delta))
 
         if len(ws) > 0:
             test.fail([w.message for w in ws])


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


Mime
View raw message