couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [21/48] couch commit: updated refs/heads/master to 7776921
Date Sat, 04 Apr 2015 23:29:16 GMT
Add test should_close_old_db_on_auth_db_change

COUCHDB-2547


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/53310568
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/53310568
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/53310568

Branch: refs/heads/master
Commit: 533105688d199bdac372fac516ba40ff6446015a
Parents: 72981ec
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Mon Feb 2 11:58:52 2015 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Feb 10 11:04:12 2015 -0800

----------------------------------------------------------------------
 src/couch_db.erl                | 15 ++++++++++-----
 test/couch_auth_cache_tests.erl | 16 +++++++++++++++-
 2 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/53310568/src/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_db.erl b/src/couch_db.erl
index 0d4857f..63aef55 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -32,6 +32,7 @@
 -export([reopen/1, is_system_db/1, compression/1, make_doc/5]).
 -export([load_validation_funs/1]).
 -export([check_md5/2, with_stream/3]).
+-export([monitored_by/1]).
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -122,15 +123,19 @@ close(#db{fd_monitor=RefCntr}) ->
     ok.
 
 is_idle(#db{compactor_pid=nil, waiting_delayed_commit=nil} = Db) ->
+    monitored_by(Db) == [];
+is_idle(_Db) ->
+    false.
+
+monitored_by(Db) ->
     case erlang:process_info(Db#db.fd, monitored_by) of
     undefined ->
-        true;
+        [];
     {monitored_by, Pids} ->
         PidTracker = whereis(couch_stats_process_tracker),
-        (Pids -- [Db#db.main_pid, PidTracker]) =:= []
-    end;
-is_idle(_Db) ->
-    false.
+        Pids -- [Db#db.main_pid, PidTracker]
+    end.
+
 
 monitor(#db{main_pid=MainPid}) ->
     erlang:monitor(process, MainPid).

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/53310568/test/couch_auth_cache_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_auth_cache_tests.erl b/test/couch_auth_cache_tests.erl
index 4223319..cba77ed 100644
--- a/test/couch_auth_cache_tests.erl
+++ b/test/couch_auth_cache_tests.erl
@@ -51,7 +51,8 @@ couch_auth_cache_test_() ->
                     fun should_restore_cache_after_userdoc_recreation/1,
                     fun should_drop_cache_on_auth_db_change/1,
                     fun should_restore_cache_on_auth_db_change/1,
-                    fun should_recover_cache_after_shutdown/1
+                    fun should_recover_cache_after_shutdown/1,
+                    fun should_close_old_db_on_auth_db_change/1
                 ]
             }
         }
@@ -153,6 +154,13 @@ should_recover_cache_after_shutdown(DbName) ->
         ?assertEqual(PasswordHash, get_user_doc_password_sha(DbName, "joe"))
     end).
 
+should_close_old_db_on_auth_db_change(DbName) ->
+    ?_test(begin
+        ?assert(is_opened(DbName)),
+        config:set("couch_httpd_auth", "authentication_db",
+                         ?b2l(?tempdb()), false),
+        ?assertNot(is_opened(DbName))
+    end).
 
 update_user_doc(DbName, UserName, Password) ->
     update_user_doc(DbName, UserName, Password, nil).
@@ -224,3 +232,9 @@ full_commit(DbName) ->
     {ok, AuthDb} = couch_db:open_int(DbName, [?ADMIN_CTX]),
     {ok, _} = couch_db:ensure_full_commit(AuthDb),
     ok = couch_db:close(AuthDb).
+
+is_opened(DbName) ->
+    {ok, AuthDb} = couch_db:open_int(DbName, [?ADMIN_CTX]),
+    Monitors = couch_db:monitored_by(AuthDb) -- [self()],
+    ok = couch_db:close(AuthDb),
+    Monitors /= [].


Mime
View raw message