summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2017-07-31 21:27:05 +0000
committerNick Vatamaniuc <nickva@users.noreply.github.com>2017-08-01 14:15:56 -0400
commit1053aee707753e072cc2b7b5ca9d64297124d9e2 (patch)
tree29ff8af689e9368126b5ffeb8ff923331f91ada2
parent939761b71830ec954701f94cb6df3dab6666a794 (diff)
downloadcouchdb-1053aee707753e072cc2b7b5ca9d64297124d9e2.tar.gz
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
-rw-r--r--src/couch/test/couch_auth_cache_tests.erl24
1 files 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 26596559f..6328c9b97 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) ->