You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/04/17 17:04:41 UTC

[GitHub] eiri closed pull request #1285: Fix mem3 tests

eiri closed pull request #1285: Fix mem3 tests
URL: https://github.com/apache/couchdb/pull/1285
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/mem3/src/mem3_shards.erl b/src/mem3/src/mem3_shards.erl
index 0975d2f8fd..c84b87397a 100644
--- a/src/mem3/src/mem3_shards.erl
+++ b/src/mem3/src/mem3_shards.erl
@@ -724,42 +724,25 @@ spawn_link_mock_writer(Db, Shards, Timeout) ->
 
 
 mem3_shards_changes_test_() -> {
-    "Test mem3_shards changes listener", {
-        foreach,
-        fun setup_changes/0, fun teardown_changes/1,
+    "Test mem3_shards changes listener",
+    {
+        setup,
+        fun test_util:start_couch/0, fun test_util:stop_couch/1,
         [
-            fun should_kill_changes_listener_on_shutdown/1
+            fun should_kill_changes_listener_on_shutdown/0
         ]
     }
 }.
 
 
-setup_changes() ->
-    RespDb = test_util:fake_db([{name, <<"dbs">>}, {update_seq, 0}]),
-    ok = meck:expect(mem3_util, ensure_exists, ['_'], {ok, RespDb}),
-    ok = meck:expect(couch_db, close, ['_'], ok),
-    ok = application:start(config),
+should_kill_changes_listener_on_shutdown() ->
     {ok, Pid} = ?MODULE:start_link(),
+    {ok, ChangesPid} = get_changes_pid(),
+    ?assert(is_process_alive(ChangesPid)),
     true = erlang:unlink(Pid),
-    Pid.
-
-
-teardown_changes(Pid) ->
-    true = exit(Pid, shutdown),
-    ok = application:stop(config),
-    meck:unload().
-
-
-should_kill_changes_listener_on_shutdown(Pid) ->
-    ?_test(begin
-        ?assert(is_process_alive(Pid)),
-        {ok, ChangesPid} = get_changes_pid(),
-        ?assert(is_process_alive(ChangesPid)),
-        true = test_util:stop_sync_throw(
-            ChangesPid, fun() -> exit(Pid, shutdown) end, wait_timeout),
-        ?assertNot(is_process_alive(ChangesPid)),
-        ok
-    end).
-
+    true = test_util:stop_sync_throw(
+        ChangesPid, fun() -> exit(Pid, shutdown) end, wait_timeout),
+    ?assertNot(is_process_alive(ChangesPid)),
+    exit(Pid, shutdown).
 
 -endif.
diff --git a/src/mem3/test/01-config-default.ini b/src/mem3/test/01-config-default.ini
deleted file mode 100644
index dde92ce2d9..0000000000
--- a/src/mem3/test/01-config-default.ini
+++ /dev/null
@@ -1,14 +0,0 @@
-# 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.
-
-[cluster]
-n=3
diff --git a/src/mem3/test/mem3_sync_security_test.erl b/src/mem3/test/mem3_sync_security_test.erl
index 8b6af3c0fa..4e06dd8073 100644
--- a/src/mem3/test/mem3_sync_security_test.erl
+++ b/src/mem3/test/mem3_sync_security_test.erl
@@ -19,11 +19,14 @@
 
 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).
+    try
+        ok = meck:new(fabric, [passthrough]),
+        meck:expect(fabric, all_dbs, fun() ->
+            {ok, [<<"NoExistDb1">>, <<"NoExistDb2">>]}
+        end),
+        Result = mem3_sync_security:go(),
+        ?assertEqual(ok, Result)
+    after
+        meck:unload(),
+        test_util:stop_couch(Ctx)
+    end.
diff --git a/src/mem3/test/mem3_util_test.erl b/src/mem3/test/mem3_util_test.erl
index 163580cc2f..214217ec4c 100644
--- a/src/mem3/test/mem3_util_test.erl
+++ b/src/mem3/test/mem3_util_test.erl
@@ -121,47 +121,18 @@ build_shards_test() ->
 %% n_val tests
 
 nval_test_() ->
-    {"n_val tests explicit",
-     [
-      {setup,
-       fun () ->
-               meck:new([couch_log]),
-               meck:expect(couch_log, error, fun(_, _) -> ok end),
-               ok
-       end,
-       fun (_) -> meck:unload([couch_log]) end,
-       [
-        ?_assertEqual(2, mem3_util:n_val(2,4)),
-        ?_assertEqual(1, mem3_util:n_val(-1,4)),
-        ?_assertEqual(4, mem3_util:n_val(6,4))
+    {
+        setup,
+        fun() ->
+            meck:new([config, couch_log]),
+            meck:expect(couch_log, error, 2, ok),
+            meck:expect(config, get, 3, "5")
+        end,
+        fun(_) -> meck:unload() end,
+        [
+            ?_assertEqual(2, mem3_util:n_val(2, 4)),
+            ?_assertEqual(1, mem3_util:n_val(-1, 4)),
+            ?_assertEqual(4, mem3_util:n_val(6, 4)),
+            ?_assertEqual(5, mem3_util:n_val(undefined, 6))
         ]
-       }
-     ]
     }.
-
-
-config_01_setup() ->
-    Ini = filename:join([code:lib_dir(mem3, test), "01-config-default.ini"]),
-    {ok, Pid} = config:start_link([Ini]),
-    Pid.
-
-config_teardown(Pid) ->
-    test_util:stop_config(Pid).
-
-
-n_val_test_() ->
-    {"n_val tests with config",
-     [
-      {setup,
-       fun config_01_setup/0,
-       fun config_teardown/1,
-       fun(Pid) ->
-           {with, Pid, [
-               fun n_val_1/1
-            ]}
-       end}
-     ]
-    }.
-
-n_val_1(_Pid) ->
-    ?assertEqual(3, mem3_util:n_val(undefined, 4)).


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services