URL: https://github.com/SSSD/sssd/pull/547
Author: fidencio
 Title: #547: Tests for #511
Action: opened

PR body:
"""
We've decided to split the fix/tests in two different PRs.
"""

To pull the PR as Git branch:
git remote add ghsssd https://github.com/SSSD/sssd
git fetch ghsssd pull/547/head:pr547
git checkout pr547
From aa8cfabd2f692bb36c479a2cd9edfb2d96d56aae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fiden...@redhat.com>
Date: Wed, 7 Feb 2018 13:26:46 +0100
Subject: [PATCH 1/2] TESTS: Rename test_idle_timeout()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

As this test is related to the client_idle_timeout, let's rename it
accordingly.

Resolves:
https://pagure.io/SSSD/sssd/issue/3633

Signed-off-by: Fabiano FidĂȘncio <fiden...@redhat.com>
---
 src/tests/intg/test_secrets.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/tests/intg/test_secrets.py b/src/tests/intg/test_secrets.py
index a145045ee..96b6f6b4a 100644
--- a/src/tests/intg/test_secrets.py
+++ b/src/tests/intg/test_secrets.py
@@ -369,7 +369,7 @@ def get_fds(pid):
 def setup_for_cli_timeout_test(request):
     """
     Same as the generic setup, except a short client_idle_timeout so that
-    the test_idle_timeout() test closes the fd towards the client.
+    the test_cli_idle_timeout() test closes the fd towards the client.
     """
     conf = generate_sec_config() + \
         unindent("""
@@ -380,7 +380,7 @@ def setup_for_cli_timeout_test(request):
     return create_sssd_secrets_fixture(request)
 
 
-def test_idle_timeout(setup_for_cli_timeout_test):
+def test_cli_idle_timeout(setup_for_cli_timeout_test):
     """
     Test that idle file descriptors are reaped after the idle timeout
     passes

From a39b02be1696bb7ad571b2495f72862ddb9c35e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fiden...@redhat.com>
Date: Wed, 7 Feb 2018 13:26:46 +0100
Subject: [PATCH 2/2] TESTS: Add test for responder_idle_timeout
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Two new tests have been added in order to test the following scenarios
of responder_idle_timeout:
- responder is shutdown after n seconds;
- responder has its shutdown delayed due to some activity and then is
  shutdown after n seconds;

In order to have the tests added, a new dep has been introduced:
python-psutil

Keep in mind those newly added tests make our test suite to take a few
minutes more to finish.

Resolves:
https://pagure.io/SSSD/sssd/issue/3633

Signed-off-by: Fabiano FidĂȘncio <fiden...@redhat.com>
---
 contrib/ci/deps.sh             |  2 +
 src/tests/intg/test_secrets.py | 84 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 83 insertions(+), 3 deletions(-)

diff --git a/contrib/ci/deps.sh b/contrib/ci/deps.sh
index 8287918be..d8b1414c8 100644
--- a/contrib/ci/deps.sh
+++ b/contrib/ci/deps.sh
@@ -42,6 +42,7 @@ if [[ "$DISTRO_BRANCH" == -redhat-* ]]; then
         openldap-servers
         pytest
         python-ldap
+        python-psutil
         pyldb
         rpm-build
         uid_wrapper
@@ -120,6 +121,7 @@ if [[ "$DISTRO_BRANCH" == -debian-* ]]; then
         python-ldap
         python-ldb
         python-requests
+        python-psutil
         ldap-utils
         slapd
         systemtap-sdt-dev
diff --git a/src/tests/intg/test_secrets.py b/src/tests/intg/test_secrets.py
index 96b6f6b4a..3632351cc 100644
--- a/src/tests/intg/test_secrets.py
+++ b/src/tests/intg/test_secrets.py
@@ -26,6 +26,7 @@
 import time
 import socket
 import pytest
+import psutil
 from requests import HTTPError
 
 from util import unindent
@@ -41,7 +42,7 @@ def create_conf_fixture(request, contents):
     request.addfinalizer(lambda: os.unlink(config.CONF_PATH))
 
 
-def create_sssd_secrets_fixture(request):
+def create_sssd_secrets_fixture(request, teardown=True):
     if subprocess.call(['sssd', "--genconf"]) != 0:
         raise Exception("failed to regenerate confdb")
 
@@ -72,13 +73,21 @@ def create_sssd_secrets_fixture(request):
 
         assert os.path.exists(sock_path)
 
+    def unlink_secdb():
+        for secdb_file in os.listdir(config.SECDB_PATH):
+            os.unlink(config.SECDB_PATH + "/" + secdb_file)
+
     def sec_teardown():
+        if teardown is False:
+            unlink_secdb()
+            return
+
         if secpid == 0:
             return
 
         os.kill(secpid, signal.SIGTERM)
-        for secdb_file in os.listdir(config.SECDB_PATH):
-            os.unlink(config.SECDB_PATH + "/" + secdb_file)
+        unlink_secdb()
+
     request.addfinalizer(sec_teardown)
     return secpid
 
@@ -602,3 +611,72 @@ def test_unlimited_quotas(setup_for_unlimited_quotas, secrets_cli):
     for i in range(DEFAULT_CONTAINERS_NEST_LEVEL):
         container += "%s/" % str(i)
         cli.create_container(container)
+
+
+@pytest.fixture
+def setup_for_resp_timeout_test(request):
+    """
+    Same as the generic setup, except a short responder_idle_timeout
+    so that the test_responder_idle_timeout() test verifies that the
+    responder has been shot down.
+    """
+    conf = generate_sec_config() + \
+        unindent("""
+        responder_idle_timeout = 60
+        """).format()
+
+    create_conf_fixture(request, conf)
+    return create_sssd_secrets_fixture(request, False)
+
+
+def test_resp_idle_timeout_shutdown(setup_for_resp_timeout_test):
+    """
+    Test that the responder is shutdown after the respoder_idle_timeout is
+    over
+    """
+    secpid = setup_for_resp_timeout_test
+    p = psutil.Process(secpid)
+
+    # With the responder_idle_timeout set to 60 seconds, we need to wait at
+    # least 90, because the internal timer ticks every timeout/2 seconds, so
+    # so it would tick at 30, 60 and 90 seconds and the responder_idle_timeout
+    # uses a greater-than comparison, so the 60-seconds tick wouldn't yet
+    # trigger the process' shutdown.
+    p.wait(timeout=90)
+    assert p.is_running() is False
+
+
+def test_resp_idle_timeout_postpone_shutdown(setup_for_resp_timeout_test,
+                                             secrets_cli):
+    """
+    Test that the responder's shutdown is postponed in case an activity
+    happens, but it's still shutdown after the responder_idle_timeout is
+    over
+    """
+    cli = secrets_cli
+
+    secpid = setup_for_resp_timeout_test
+    p = psutil.Process(secpid)
+
+    # Wait for 65 seconds and then fire a request to the responder, so its
+    # last_request_time gets updated and the process doesn't get shutdown.
+    time.sleep(65)
+    cli.set_secret("foo", "bar")
+    try:
+        # Wait for the process to finish for more 25 seconds, which is the
+        # time it'd be shutdown in case the last_request_time is not updated.
+        p.wait(timeout=25)
+    except psutil.TimeoutExpired:
+        # In case the timeout expired, we're fine, it just means that the
+        # last_request_time has been updated properly.
+        pass
+
+    # Assert that the process is still running after the 60s idle timeout has
+    # expired but some activity happened (thus,the last_request_time has been
+    # updated).
+    assert p.is_running() is True
+
+    # Wait more 60s in order to be sure that the process actually is shutdown
+    # when it should be.
+    p.wait(timeout=60)
+    assert p.is_running() is False
_______________________________________________
sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org
To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org

Reply via email to