summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Sun <tony.sun427@gmail.com>2017-07-17 08:48:02 -0700
committerTony Sun <tony.sun427@gmail.com>2017-07-17 08:48:02 -0700
commit7bee63fa40c44772e06c34e5a16905cd79a9d90a (patch)
treed359fe58d36baeab7016dca7cb8d67b06c9b3bbd
parent6c4def6699717b462688ea72b11616347a77ae11 (diff)
parent38cc13957debe6f34b328b9a3f0cb86a7eff0dfb (diff)
downloadcouchdb-7bee63fa40c44772e06c34e5a16905cd79a9d90a.tar.gz
Merge branch '3423-add-try-catch-mem3'
-rw-r--r--src/mem3/src/mem3_sync_security.erl14
-rw-r--r--src/mem3/test/mem3_sync_security_test.erl29
2 files changed, 41 insertions, 2 deletions
diff --git a/src/mem3/src/mem3_sync_security.erl b/src/mem3/src/mem3_sync_security.erl
index 9edd0ec57..291e4e085 100644
--- a/src/mem3/src/mem3_sync_security.erl
+++ b/src/mem3/src/mem3_sync_security.erl
@@ -44,10 +44,20 @@ maybe_sync_int(#shard{name=Name}=Src, Dst) ->
go() ->
{ok, Dbs} = fabric:all_dbs(),
- lists:foreach(fun handle_db/1, Dbs).
+ lists:foreach(fun handle_existing_db/1, Dbs).
go(DbName) when is_binary(DbName) ->
- handle_db(DbName).
+ handle_existing_db(DbName).
+
+handle_existing_db(DbName) ->
+ try handle_db(DbName) of
+ _ -> ok
+ catch
+ error:database_does_not_exist->
+ couch_log:error("Db was deleted while getting security"
+ " object. DbName: ~p", [DbName]),
+ ok
+ end.
handle_db(DbName) ->
ShardCount = length(mem3:shards(DbName)),
diff --git a/src/mem3/test/mem3_sync_security_test.erl b/src/mem3/test/mem3_sync_security_test.erl
new file mode 100644
index 000000000..8b6af3c0f
--- /dev/null
+++ b/src/mem3/test/mem3_sync_security_test.erl
@@ -0,0 +1,29 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(mem3_sync_security_test).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+-include("mem3.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+go_test() ->
+ Ctx = test_util:start_couch([fabric, mem3]),
+ ok = meck:new(fabric, [passthrough]),
+ meck:expect(fabric, all_dbs, fun() ->
+ {ok, [<<"NoExistDb1">>, <<"NoExistDb2">>]}
+ end),
+ Result = mem3_sync_security:go(),
+ meck:unload(fabric),
+ test_util:stop_couch(Ctx),
+ ?assertEqual(ok, Result).