VPP-1486: Unittest for stat segment file descriptor leak. 77/18177/2
authorPaul Vinciguerra <pvinci@vinciconsulting.com>
Mon, 11 Mar 2019 12:04:12 +0000 (05:04 -0700)
committerNeale Ranns <nranns@cisco.com>
Tue, 12 Mar 2019 05:26:04 +0000 (05:26 +0000)
Verifies: https://gerrit.fd.io/r/#/c/18167/

Before patch:

    ==============================================================================
    Test Stats Client
    ==============================================================================
    Test file descriptor count - VPP-1486                                    FAIL [ temp dir used by test case: /tmp/vpp-unittest-StatsClientTestCase-EAp0e7 ]

    ==============================================================================
    FAIL: Test file descriptor count - VPP-1486
    ------------------------------------------------------------------------------
    Traceback (most recent call last):
      File "/vpp/test/test_stats_client.py", line 39, in test_client_fd_leak
        initial_fds, ending_fds))
    AssertionError: initial client side file descriptor count: 20 is not equal to ending client side file descriptor count: 120

    04:55:38,038 Symlink to failed testcase directory: /tmp/vpp-failed-unittests/vpp-unittest-StatsClientTestCase-EAp0e7-FAILED -> vpp-unittest-StatsClientTestCase-EAp0e7

    ==============================================================================
    TEST RESULTS:
         Scheduled tests: 1
          Executed tests: 1
            Passed tests: 0
                Failures: 1
    FAILURES AND ERRORS IN TESTS:
      Testcase name: Test Stats Client
        FAILURE: Test file descriptor count - VPP-1486 [test_stats_client.StatsClientTestCase.test_client_fd_leak]
    =============================================================================

After patch:

    ==============================================================================
    Test Stats Client
    ==============================================================================
    Test file descriptor count - VPP-1486                                    OK

    ==============================================================================
    TEST RESULTS:
         Scheduled tests: 1
          Executed tests: 1
            Passed tests: 1
    ==============================================================================

    Test run was successful

Change-Id: I055e473ecf0566ebfbfbadd58ec6eaf11fc77d68
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
test/test_stats_client.py [new file with mode: 0644]

diff --git a/test/test_stats_client.py b/test/test_stats_client.py
new file mode 100644 (file)
index 0000000..87c9efd
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/env python2.7
+
+import unittest
+
+import psutil
+from vpp_papi.vpp_stats import VPPStats
+
+from framework import VppTestCase, VppTestRunner
+
+
+class StatsClientTestCase(VppTestCase):
+    """Test Stats Client"""
+
+    @classmethod
+    def setUpClass(cls):
+        super(StatsClientTestCase, cls).setUpClass()
+
+    @classmethod
+    def tearDownClass(cls):
+        super(StatsClientTestCase, cls).tearDownClass()
+
+    def test_client_fd_leak(self):
+        """Test file descriptor count - VPP-1486"""
+
+        cls = self.__class__
+        p = psutil.Process()
+        initial_fds = p.num_fds()
+
+        for _ in range(100):
+            stats = VPPStats(socketname=cls.stats_sock)
+            stats.disconnect()
+
+        ending_fds = p.num_fds()
+        self.assertEqual(initial_fds, ending_fds,
+                         "initial client side file descriptor count: %s "
+                         "is not equal to "
+                         "ending client side file descriptor count: %s" % (
+                             initial_fds, ending_fds))
+
+if __name__ == '__main__':
+    unittest.main(testRunner=VppTestRunner)