You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2017/08/01 18:15:59 UTC

[couchdb] branch master updated: Fix timeout in couch auth test

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 1053aee  Fix timeout in couch auth test
1053aee is described below

commit 1053aee707753e072cc2b7b5ca9d64297124d9e2
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Mon Jul 31 21:27:05 2017 +0000

    Fix timeout in couch auth test
    
    The test was racy. Use test_util:wait/1 function there just like other
    places like couch_index_compaction_tests
    
    Fixes #724
---
 src/couch/test/couch_auth_cache_tests.erl | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/couch/test/couch_auth_cache_tests.erl b/src/couch/test/couch_auth_cache_tests.erl
index 2659655..6328c9b 100644
--- a/src/couch/test/couch_auth_cache_tests.erl
+++ b/src/couch/test/couch_auth_cache_tests.erl
@@ -16,7 +16,7 @@
 -include_lib("couch/include/couch_db.hrl").
 
 -define(SALT, <<"SALT">>).
--define(TIMEOUT, 1000).
+-define(DB_TIMEOUT, 15000).
 
 start() ->
     test_util:start_couch([ioq]).
@@ -230,12 +230,12 @@ should_recover_cache_after_shutdown(DbName) ->
     end).
 
 should_close_old_db_on_auth_db_change(DbName) ->
-    ?_test(begin
-        ?assert(is_opened(DbName)),
+    {timeout, ?DB_TIMEOUT, ?_test(begin
+        ?assertEqual(ok, wait_db(DbName, fun is_opened/1)),
         config:set("couch_httpd_auth", "authentication_db",
                          ?b2l(?tempdb()), false),
-        ?assertNot(is_opened(DbName))
-    end).
+        ?assertEqual(ok, wait_db(DbName, fun is_closed/1))
+    end)}.
 
 update_user_doc(DbName, UserName, Password) ->
     update_user_doc(DbName, UserName, Password, nil).
@@ -259,6 +259,17 @@ update_user_doc(DbName, UserName, Password, Rev) ->
     ok = couch_db:close(AuthDb),
     {ok, couch_doc:rev_to_str(NewRev)}.
 
+wait_db(Db, DbFun) ->
+    test_util:wait(fun() ->
+        case DbFun(Db) of
+            true ->
+                ok;
+            false ->
+                wait
+        end
+   end, ?DB_TIMEOUT, 500).
+
+
 hash_password(Password) ->
     ?l2b(couch_util:to_hex(crypto:hash(sha, iolist_to_binary([Password, ?SALT])))).
 
@@ -314,6 +325,9 @@ is_opened(DbName) ->
     ok = couch_db:close(AuthDb),
     Monitors /= [].
 
+is_closed(DbName) ->
+    not is_opened(DbName).
+
 make_validate_test({Old, New, "ok"} = Case) ->
     {test_id(Case), ?_assertEqual(ok, validate(doc(Old), doc(New)))};
 make_validate_test({Old, New, Reason} = Case) ->

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].