couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vatam...@apache.org
Subject [couchdb] branch master updated: Fix timeout in couch auth test
Date Tue, 01 Aug 2017 18:15:59 GMT
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 <vatamane@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" <commits@couchdb.apache.org>'].

Mime
View raw message