From d0ebf5021985ab5a5d08b0d7d49b223f55b656c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Tue, 26 Nov 2019 12:26:32 +0100
Subject: [PATCH 1/2] tests: fix race confition in files provider tests

Lets give files provider more time to load changes from files to avoid
race condition failures. The files provider tests works like this:

1. File is changed
2. inotify callback is triggered in SSSD
3. Cache is updated
4. Assertions are done

This sleep is supposed to eliminated race condition between step 1 and 2
so tests do not continue before inotify callback had a chance to kick in.

One second was not enough in some slow virtual environments where the
test non-deterministicly failed (SSSD is starting, doing some initial tasks,
so it is possible that inotify callback is delayed a little bit).
Three seconds is a hopefully safe random value.
---
 src/tests/intg/test_files_provider.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/tests/intg/test_files_provider.py b/src/tests/intg/test_files_provider.py
index 9f3aad9949..795adf5551 100644
--- a/src/tests/intg/test_files_provider.py
+++ b/src/tests/intg/test_files_provider.py
@@ -451,7 +451,11 @@ def user_generator(seqnum):
                 shell='/bin/bash')
 
 
-def check_user(exp_user, delay=1.0):
+def check_user(exp_user, delay=3.0):
+    # We need to delay the flow a little bit to ensure that inotify callback
+    # in SSSD had a chance to fire. One second was sometimes not enough
+    # on some slow virtual environments. Three seconds is large hopefully
+    # safe random value as there is nothing else we can do here.
     if delay > 0:
         time.sleep(delay)
 
@@ -466,7 +470,11 @@ def group_generator(seqnum):
                 mem=[])
 
 
-def check_group(exp_group, delay=1.0):
+def check_group(exp_group, delay=3.0):
+    # We need to delay the flow a little bit to ensure that inotify callback
+    # in SSSD had a chance to fire. One second was sometimes not enough
+    # on some slow virtual environments. Three seconds is large hopefully
+    # safe random value as there is nothing else we can do here.
     if delay > 0:
         time.sleep(delay)
 
@@ -475,7 +483,7 @@ def check_group(exp_group, delay=1.0):
     assert found_group == exp_group
 
 
-def check_group_by_gid(exp_group, delay=1.0):
+def check_group_by_gid(exp_group, delay=3.0):
     if delay > 0:
         time.sleep(delay)
 
@@ -779,7 +787,7 @@ def test_add_remove_add_file_group(setup_gr_with_canary, files_domain_only):
     check_group(GROUP1)
 
     setup_gr_with_canary.groupdel(GROUP1["name"])
-    time.sleep(1)
+    time.sleep(3)
     res, group = call_sssd_getgrnam(GROUP1["name"])
     assert res == NssReturnCode.NOTFOUND
 

From b86c79274f99f47b8d84749b1904020b743b9cc5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Tue, 26 Nov 2019 12:42:27 +0100
Subject: [PATCH 2/2] tests: fix race condition in enumeration tests

This change is relevant to Nyquist frequency. To ensure that enumeration has been
run we need to wait at least twice the enumeration timeout. In other words, we need
to make sure enumeration is run at least twice the frequency of our assertions to
ensure that it has been run at least once.

Resolves:
https://pagure.io/SSSD/sssd/issue/3463
---
 src/tests/intg/test_enumeration.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/tests/intg/test_enumeration.py b/src/tests/intg/test_enumeration.py
index c105c6df02..34298ab49c 100644
--- a/src/tests/intg/test_enumeration.py
+++ b/src/tests/intg/test_enumeration.py
@@ -33,7 +33,11 @@
 from util import *
 
 LDAP_BASE_DN = "dc=example,dc=com"
-INTERACTIVE_TIMEOUT = 4
+
+# To ensure that enumeration was run before we need to wait little longer
+# before we make tests assertions. Twice the value is a good safe value..
+ENUMERATION_TIMEOUT = 4
+INTERACTIVE_TIMEOUT = ENUMERATION_TIMEOUT*2
 
 
 @pytest.fixture(scope="module")
@@ -151,7 +155,7 @@ def format_interactive_conf(ldap_conn, schema):
             ldap_enumeration_refresh_timeout    = {0}
             ldap_purge_cache_timeout            = 1
             entry_cache_timeout                 = {0}
-        """).format(INTERACTIVE_TIMEOUT)
+        """).format(ENUMERATION_TIMEOUT)
 
 
 def create_conf_file(contents):
