diff options
author | Eric Avdey <eiri@eiri.ca> | 2018-04-17 14:04:39 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-17 14:04:39 -0300 |
commit | 8de46c7a3ea097b4e50dfb4656172562a0dc69dc (patch) | |
tree | 0015042b3191253c723e8107c30b29ad8dc47951 | |
parent | 069c02be2bd3b9a5486661589ba48b13f75e5c45 (diff) | |
download | couchdb-8de46c7a3ea097b4e50dfb4656172562a0dc69dc.tar.gz |
Fix mem3 tests (#1285)
The changes listener started in setup of mem3_shards test
was crashing when tried to register on unstarted couch_event
server, so the test was either fast enough to do assertions
before of that or failed on dead listener process.
This change removes dependency on mocking and uses
a standard test_util's star and stop of couch. Module start
moved into the test body to avoid masking potential failure
in a setup.
Also the tests mem3_sync_security_test and mem3_util_test
been modified to avoid setup and teardown side effects.
-rw-r--r-- | src/mem3/src/mem3_shards.erl | 41 | ||||
-rw-r--r-- | src/mem3/test/01-config-default.ini | 14 | ||||
-rw-r--r-- | src/mem3/test/mem3_sync_security_test.erl | 19 | ||||
-rw-r--r-- | src/mem3/test/mem3_util_test.erl | 55 |
4 files changed, 36 insertions, 93 deletions
diff --git a/src/mem3/src/mem3_shards.erl b/src/mem3/src/mem3_shards.erl index 0975d2f8f..c84b87397 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 dde92ce2d..000000000 --- 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 8b6af3c0f..4e06dd807 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 163580cc2..214217ec4 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)). |