From b724db15ce0c1593cfdd7b4da8e0c39e97942e8c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20=C5=BDidek?= <mzidek@redhat.com>
Date: Wed, 2 Dec 2015 16:44:48 +0100
Subject: [PATCH] ldap_test.py: Modify enum cache timeouts

There is a race condation between ldap
enumeration refresh timeout and the sleeps
that wait for the ldap changes to populate
to SSSD if the timeout and the sleeps have
the same value.
---
 src/tests/intg/ldap_test.py | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/src/tests/intg/ldap_test.py b/src/tests/intg/ldap_test.py
index 757ee20..8ec8dbe 100644
--- a/src/tests/intg/ldap_test.py
+++ b/src/tests/intg/ldap_test.py
@@ -33,7 +33,11 @@ import ldap_ent
 from util import *
 
 LDAP_BASE_DN = "dc=example,dc=com"
-INTERACTIVE_TIMEOUT = 4
+INTERACTIVE_TIMEOUT = 2
+
+
+def wait_for_ldap_enum_refresh():
+    time.sleep(INTERACTIVE_TIMEOUT + 4)
 
 
 @pytest.fixture(scope="module")
@@ -466,11 +470,11 @@ def test_add_remove_user(ldap_conn, blank_rfc2307):
     # Add the user
     ent.assert_passwd(ent.contains_only())
     ldap_conn.add_s(*e)
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_passwd(ent.contains_only(dict(name="user", uid=1001)))
     # Remove the user
     ldap_conn.delete_s(e[0])
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_passwd(ent.contains_only())
 
 
@@ -481,11 +485,11 @@ def test_add_remove_group_rfc2307(ldap_conn, blank_rfc2307):
     # Add the group
     ent.assert_group(ent.contains_only())
     ldap_conn.add_s(*e)
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_group(ent.contains_only(dict(name="group", gid=2001)))
     # Remove the group
     ldap_conn.delete_s(e[0])
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_group(ent.contains_only())
 
 
@@ -496,11 +500,11 @@ def test_add_remove_group_rfc2307_bis(ldap_conn, blank_rfc2307_bis):
     # Add the group
     ent.assert_group(ent.contains_only())
     ldap_conn.add_s(*e)
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_group(ent.contains_only(dict(name="group", gid=2001)))
     # Remove the group
     ldap_conn.delete_s(e[0])
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_group(ent.contains_only())
 
 
@@ -511,12 +515,12 @@ def test_add_remove_membership_rfc2307(ldap_conn, user_and_group_rfc2307):
     ent.assert_group_by_name("group", dict(mem=ent.contains_only()))
     ldap_conn.modify_s("cn=group,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_REPLACE, "memberUid", "user")])
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_group_by_name("group", dict(mem=ent.contains_only("user")))
     # Remove user from group
     ldap_conn.modify_s("cn=group,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_DELETE, "memberUid", None)])
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_group_by_name("group", dict(mem=ent.contains_only()))
 
 
@@ -532,26 +536,26 @@ def test_add_remove_membership_rfc2307_bis(ldap_conn,
     ldap_conn.modify_s("cn=group1,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_REPLACE, "member",
                          "uid=user,ou=Users," + ldap_conn.ds_inst.base_dn)])
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_group_by_name("group1", dict(mem=ent.contains_only("user")))
 
     # Add group1 to group2
     ldap_conn.modify_s("cn=group2,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_REPLACE, "member",
                          "cn=group1,ou=Groups," + ldap_conn.ds_inst.base_dn)])
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_group_by_name("group2", dict(mem=ent.contains_only("user")))
 
     # Remove group1 from group2
     ldap_conn.modify_s("cn=group2,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_DELETE, "member", None)])
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_group_by_name("group2", dict(mem=ent.contains_only()))
 
     # Remove user from group1
     ldap_conn.modify_s("cn=group1,ou=Groups," + ldap_conn.ds_inst.base_dn,
                        [(ldap.MOD_DELETE, "member", None)])
-    time.sleep(INTERACTIVE_TIMEOUT)
+    wait_for_ldap_enum_refresh()
     ent.assert_group_by_name("group1", dict(mem=ent.contains_only()))
 
 
-- 
2.1.0

