[PATCH] tests: fix caching issue in test_ip_restriction_git

Thomas De Schampheleire thomas.de_schampheleire at nokia.com
Sun May 6 19:44:40 UTC 2018


# HG changeset patch
# User Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>
# Date 1525635009 -7200
#      Sun May 06 21:30:09 2018 +0200
# Node ID 278c52698c0baa8d1ffc2983555e0ade2c9afed8
# Parent  5361141149f493d6c4f2c212c6bf3eabfcd3be78
tests: fix caching issue in test_ip_restriction_git

Following test failure is observed in
TestVCSOperations.test_ip_restriction_git:

―――――――――――――― TestVCSOperations.test_ip_restriction_git ――――――――――――――――――
kallithea/tests/other/test_vcs_operations.py:584: in test_ip_restriction_git
    assert re.search(r'\b403\b', stderr)
E   assert None
E    +  where None = <function search at 0x7fb9772da578>('\\b403\\b', "Cloning into '/tmp/kallithea-test-SZhXDz/vcs_operations-krPNvZ'...\n")
E    +    where <function search at 0x7fb9772da578> = re.search
------------------------- Captured stdout call ----------------------------
*** CMD git clone http://test_admin:test12@127.0.0.1:45291/vcs_test_git /tmp/kallithea-test-SZhXDz/vcs_operations-krPNvZ ***
stderr: "Cloning into '/tmp/kallithea-test-SZhXDz/vcs_operations-krPNvZ'...\n"



The test is setting up IP restrictions, verifying that access is no longer
possible, then clears the restriction. There already were sleeps after
clearing the restrictions, in order for the cache to expire and have the
setting take effect.
But there was no sleep on the enabling of the IP restriction, allowing
situations where the code would still run without restriction, and thus
allow the access, failing the test.

The failure has only been observed on test_ip_restriction_git, but the
change is also made for test_ip_restriction_hg.

The existing sleeps after restriction clearing are moved up to the 'finally'
clause to make it clear to which code they belong.

diff --git a/kallithea/tests/other/test_vcs_operations.py b/kallithea/tests/other/test_vcs_operations.py
--- a/kallithea/tests/other/test_vcs_operations.py
+++ b/kallithea/tests/other/test_vcs_operations.py
@@ -551,6 +551,8 @@ class TestVCSOperations(TestController):
         try:
             user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
             Session().commit()
+            # IP permissions are cached, need to wait for the cache in the server process to expire
+            time.sleep(1.5)
             clone_url = webserver.repo_url(HG_REPO)
             stdout, stderr = Command(TESTS_TMP_PATH).execute('hg clone', clone_url, _get_tmp_dir(), ignoreReturnCode=True)
             assert 'abort: HTTP Error 403: Forbidden' in stderr
@@ -559,9 +561,8 @@ class TestVCSOperations(TestController):
             for ip in UserIpMap.query():
                 UserIpMap.delete(ip.ip_id)
             Session().commit()
-
-        # IP permissions are cached, need to wait for the cache in the server process to expire
-        time.sleep(1.5)
+            # IP permissions are cached, need to wait for the cache in the server process to expire
+            time.sleep(1.5)
 
         clone_url = webserver.repo_url(HG_REPO)
         stdout, stderr = Command(TESTS_TMP_PATH).execute('hg clone', clone_url, _get_tmp_dir())
@@ -578,6 +579,8 @@ class TestVCSOperations(TestController):
         try:
             user_model.add_extra_ip(TEST_USER_ADMIN_LOGIN, '10.10.10.10/32')
             Session().commit()
+            # IP permissions are cached, need to wait for the cache in the server process to expire
+            time.sleep(1.5)
             clone_url = webserver.repo_url(GIT_REPO)
             stdout, stderr = Command(TESTS_TMP_PATH).execute('git clone', clone_url, _get_tmp_dir(), ignoreReturnCode=True)
             # The message apparently changed in Git 1.8.3, so match it loosely.
@@ -587,9 +590,8 @@ class TestVCSOperations(TestController):
             for ip in UserIpMap.query():
                 UserIpMap.delete(ip.ip_id)
             Session().commit()
-
-        # IP permissions are cached, need to wait for the cache in the server process to expire
-        time.sleep(1.5)
+            # IP permissions are cached, need to wait for the cache in the server process to expire
+            time.sleep(1.5)
 
         clone_url = webserver.repo_url(GIT_REPO)
         stdout, stderr = Command(TESTS_TMP_PATH).execute('git clone', clone_url, _get_tmp_dir())


More information about the kallithea-general mailing list