diff options
author | Alexander Shorin <kxepal@apache.org> | 2014-06-03 19:31:44 +0400 |
---|---|---|
committer | Alexander Shorin <kxepal@apache.org> | 2015-12-02 04:18:38 +0300 |
commit | 96b15f9e03a65696d4a359d996f6c652481fd202 (patch) | |
tree | f4971623fde54ef53f15c7a4f57719aac0235a2b | |
parent | 7e8003502a1fe9ac2d0b2eac0b91eddd77284004 (diff) | |
download | couchdb-96b15f9e03a65696d4a359d996f6c652481fd202.tar.gz |
Port 173-os-daemons-cfg-register.t etap test suite to eunit
Merged into couchdb_os_daemons_tests suite.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | license.skip | 5 | ||||
-rw-r--r-- | test/couchdb/Makefile.am | 2 | ||||
-rw-r--r-- | test/couchdb/couchdb_os_daemons_tests.erl | 104 | ||||
-rw-r--r-- | test/couchdb/fixtures/Makefile.am | 15 | ||||
-rw-r--r-- | test/couchdb/fixtures/test_cfg_register.c (renamed from test/etap/test_cfg_register.c) | 0 | ||||
-rwxr-xr-x | test/etap/173-os-daemon-cfg-register.t | 116 | ||||
-rw-r--r-- | test/etap/Makefile.am | 5 |
8 files changed, 122 insertions, 126 deletions
diff --git a/.gitignore b/.gitignore index 4789429b0..329f96b2e 100644 --- a/.gitignore +++ b/.gitignore @@ -131,6 +131,7 @@ test/couchdb/run test/couchdb/fixtures/.deps/ test/couchdb/fixtures/os_daemon_configer.escript test/couchdb/include/couch_eunit.hrl +test/couchdb/fixtures/.deps/ test/etap/.deps/ test/etap/run test/etap/temp.* diff --git a/license.skip b/license.skip index 3050026ce..fe807b2c0 100644 --- a/license.skip +++ b/license.skip @@ -167,6 +167,11 @@ ^test/couchdb/Makefile ^test/couchdb/Makefile.in ^test/couchdb/fixtures/logo.png +^test/couchdb/fixtures/Makefile +^test/couchdb/fixtures/Makefile.in +^test/couchdb/fixtures/.deps/test_cfg_register-test_cfg_register.Po +^test/couchdb/fixtures/test_cfg_register +^test/couchdb/fixtures/test_cfg_register.o ^test/etap/.*.beam ^test/etap/.*.o ^test/etap/.deps/.* diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am index 36bb2c4a7..95f1b7797 100644 --- a/test/couchdb/Makefile.am +++ b/test/couchdb/Makefile.am @@ -10,6 +10,8 @@ ## License for the specific language governing permissions and limitations under ## the License. +SUBDIRS = fixtures + noinst_SCRIPTS = run all: diff --git a/test/couchdb/couchdb_os_daemons_tests.erl b/test/couchdb/couchdb_os_daemons_tests.erl index a1bd5b4e8..66bbbb5ec 100644 --- a/test/couchdb/couchdb_os_daemons_tests.erl +++ b/test/couchdb/couchdb_os_daemons_tests.erl @@ -32,6 +32,7 @@ -define(DAEMON_CAN_REBOOT, "os_daemon_can_reboot.sh"). -define(DAEMON_DIE_ON_BOOT, "os_daemon_die_on_boot.sh"). -define(DAEMON_DIE_QUICKLY, "os_daemon_die_quickly.sh"). +-define(DAEMON_CFGREG, "test_cfg_register"). -define(DELAY, 100). -define(FIXTURES_BUILDDIR, filename:join([?BUILDDIR, "test", "couchdb", "fixtures"])). @@ -44,6 +45,8 @@ setup(DName) -> Path = case DName of ?DAEMON_CONFIGER -> filename:join([?FIXTURES_BUILDDIR, DName]); + ?DAEMON_CFGREG -> + filename:join([?FIXTURES_BUILDDIR, DName]); _ -> filename:join([?FIXTURESDIR, DName]) end, @@ -112,6 +115,21 @@ error_test_() -> } }. +configuration_register_test_() -> + { + "OS daemon subscribed to config changes", + { + foreachx, + fun setup/1, fun teardown/2, + [{?DAEMON_CFGREG, Fun} || Fun <- [ + fun should_start_daemon/2, + fun should_restart_daemon_on_section_change/2, + fun should_not_restart_daemon_on_changing_ignored_section_key/2, + fun should_restart_daemon_on_section_key_change/2 + ]] + } + }. + should_check_daemon(DName, _) -> ?_test(begin @@ -192,7 +210,7 @@ should_not_being_halted(DName, _) -> ?_test(begin timer:sleep(1000), {ok, [D1]} = couch_os_daemons:info([table]), - check_daemon(D1, DName, 0), + check_daemon(D1, DName, running, 0), % Should reboot every two seconds. We're at 1s, so wait % until 3s to be in the middle of the next invocation's @@ -200,7 +218,7 @@ should_not_being_halted(DName, _) -> timer:sleep(2000), {ok, [D2]} = couch_os_daemons:info([table]), - check_daemon(D2, DName, 1), + check_daemon(D2, DName, running, 1), % If the kill command changed, that means we rebooted the process. ?assertNotEqual(D1#daemon.kill, D2#daemon.kill) @@ -212,17 +230,93 @@ should_halts(DName, Time) -> check_dead(D, DName), couch_config:delete("os_daemons", DName, false). +should_start_daemon(DName, _) -> + ?_test(begin + wait_for_start(10), + {ok, [D]} = couch_os_daemons:info([table]), + check_daemon(D, DName, running, 0, [{"s1"}, {"s2", "k"}]) + end). + +should_restart_daemon_on_section_change(DName, _) -> + ?_test(begin + wait_for_start(10), + {ok, [D1]} = couch_os_daemons:info([table]), + couch_config:set("s1", "k", "foo", false), + wait_for_restart(10), + {ok, [D2]} = couch_os_daemons:info([table]), + check_daemon(D2, DName, running, 0, [{"s1"}, {"s2", "k"}]), + ?assertNotEqual(D1, D2) + end). + +should_not_restart_daemon_on_changing_ignored_section_key(_, _) -> + ?_test(begin + wait_for_start(10), + {ok, [D1]} = couch_os_daemons:info([table]), + couch_config:set("s2", "k2", "baz", false), + timer:sleep(?DELAY), + {ok, [D2]} = couch_os_daemons:info([table]), + ?assertEqual(D1, D2) + end). + +should_restart_daemon_on_section_key_change(DName, _) -> + ?_test(begin + wait_for_start(10), + {ok, [D1]} = couch_os_daemons:info([table]), + couch_config:set("s2", "k", "bingo", false), + wait_for_restart(10), + {ok, [D2]} = couch_os_daemons:info([table]), + check_daemon(D2, DName, running, 0, [{"s1"}, {"s2", "k"}]), + ?assertNotEqual(D1, D2) + end). + + +wait_for_start(0) -> + erlang:error({assertion_failed, + [{module, ?MODULE}, + {line, ?LINE}, + {reason, "Timeout on waiting daemon for start"}]}); +wait_for_start(N) -> + case couch_os_daemons:info([table]) of + {ok, []} -> + timer:sleep(?DELAY), + wait_for_start(N - 1); + _ -> + timer:sleep(?TIMEOUT) + end. + +wait_for_restart(0) -> + erlang:error({assertion_failed, + [{module, ?MODULE}, + {line, ?LINE}, + {reason, "Timeout on waiting daemon for restart"}]}); +wait_for_restart(N) -> + {ok, [D]} = couch_os_daemons:info([table]), + case D#daemon.status of + restarting -> + timer:sleep(?DELAY), + wait_for_restart(N - 1); + _ -> + timer:sleep(?TIMEOUT) + end. + check_daemon(D) -> check_daemon(D, D#daemon.name). check_daemon(D, Name) -> - check_daemon(D, Name, 0). + check_daemon(D, Name, running). + +check_daemon(D, Name, Status) -> + check_daemon(D, Name, Status, 0). + +check_daemon(D, Name, Status, Errs) -> + check_daemon(D, Name, Status, Errs, []). -check_daemon(D, Name, Errs) -> +check_daemon(D, Name, Status, Errs, CfgPatterns) -> ?assert(is_port(D#daemon.port)), ?assertEqual(Name, D#daemon.name), ?assertNotEqual(undefined, D#daemon.kill), - ?assertEqual(running, D#daemon.status), + ?assertEqual(Status, D#daemon.status), + ?assertEqual(CfgPatterns, D#daemon.cfg_patterns), ?assertEqual(Errs, length(D#daemon.errors)), ?assertEqual([], D#daemon.buf). diff --git a/test/couchdb/fixtures/Makefile.am b/test/couchdb/fixtures/Makefile.am new file mode 100644 index 000000000..1273234f9 --- /dev/null +++ b/test/couchdb/fixtures/Makefile.am @@ -0,0 +1,15 @@ +## 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. + +noinst_PROGRAMS = test_cfg_register +test_cfg_register_SOURCES = test_cfg_register.c +test_cfg_register_CFLAGS = -D_BSD_SOURCE diff --git a/test/etap/test_cfg_register.c b/test/couchdb/fixtures/test_cfg_register.c index c910bac48..c910bac48 100644 --- a/test/etap/test_cfg_register.c +++ b/test/couchdb/fixtures/test_cfg_register.c diff --git a/test/etap/173-os-daemon-cfg-register.t b/test/etap/173-os-daemon-cfg-register.t deleted file mode 100755 index 256ee7d54..000000000 --- a/test/etap/173-os-daemon-cfg-register.t +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/env escript -%% -*- erlang -*- - -% 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. - --record(daemon, { - port, - name, - cmd, - kill, - status=running, - cfg_patterns=[], - errors=[], - buf=[] -}). - -daemon_name() -> - "wheee". - -daemon_cmd() -> - test_util:build_file("test/etap/test_cfg_register"). - -main(_) -> - test_util:init_code_path(), - - etap:plan(27), - case (catch test()) of - ok -> - etap:end_tests(); - Other -> - etap:diag(io_lib:format("Test died abnormally: ~p", [Other])), - etap:bail(Other) - end, - ok. - -test() -> - couch_config:start_link(test_util:config_files()), - couch_os_daemons:start_link(), - - DaemonCmd = daemon_cmd() ++ " 2> /dev/null", - - etap:diag("Booting the daemon"), - couch_config:set("os_daemons", daemon_name(), DaemonCmd, false), - wait_for_start(10), - {ok, [D1]} = couch_os_daemons:info([table]), - check_daemon(D1, running), - - etap:diag("Daemon restarts when section changes."), - couch_config:set("s1", "k", "foo", false), - wait_for_restart(10), - {ok, [D2]} = couch_os_daemons:info([table]), - check_daemon(D2, running), - etap:isnt(D2#daemon.kill, D1#daemon.kill, "Kill command shows restart."), - - etap:diag("Daemon doesn't restart for ignored section key."), - couch_config:set("s2", "k2", "baz", false), - timer:sleep(1000), % Message travel time. - {ok, [D3]} = couch_os_daemons:info([table]), - etap:is(D3, D2, "Same daemon info after ignored config change."), - - etap:diag("Daemon restarts for specific section/key pairs."), - couch_config:set("s2", "k", "bingo", false), - wait_for_restart(10), - {ok, [D4]} = couch_os_daemons:info([table]), - check_daemon(D4, running), - etap:isnt(D4#daemon.kill, D3#daemon.kill, "Kill command changed again."), - - ok. - -wait_for_start(0) -> - throw({error, wait_for_start}); -wait_for_start(N) -> - case couch_os_daemons:info([table]) of - {ok, []} -> - timer:sleep(200), - wait_for_start(N-1); - _ -> - timer:sleep(1000) - end. - -wait_for_restart(0) -> - throw({error, wait_for_restart}); -wait_for_restart(N) -> - {ok, [D]} = couch_os_daemons:info([table]), - case D#daemon.status of - restarting -> - timer:sleep(200), - wait_for_restart(N-1); - _ -> - timer:sleep(1000) - end. - -check_daemon(D, Status) -> - BaseName = filename:basename(daemon_cmd()) ++ " 2> /dev/null", - BaseLen = length(BaseName), - CmdLen = length(D#daemon.cmd), - CmdName = lists:sublist(D#daemon.cmd, CmdLen-BaseLen+1, BaseLen), - - etap:is(is_port(D#daemon.port), true, "Daemon port is a port."), - etap:is(D#daemon.name, daemon_name(), "Daemon name was set correctly."), - etap:is(CmdName, BaseName, "Command name was set correctly."), - etap:isnt(D#daemon.kill, undefined, "Kill command was set."), - etap:is(D#daemon.status, Status, "Daemon status is correct."), - etap:is(D#daemon.cfg_patterns, [{"s1"}, {"s2", "k"}], "Cfg patterns set"), - etap:is(D#daemon.errors, [], "No errors have occurred."), - etap:isnt(D#daemon.buf, nil, "Buffer is active."). diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am index e42d398bb..05a7870ca 100644 --- a/test/etap/Makefile.am +++ b/test/etap/Makefile.am @@ -13,10 +13,6 @@ noinst_SCRIPTS = run noinst_DATA = test_util.beam test_web.beam -noinst_PROGRAMS = test_cfg_register -test_cfg_register_SOURCES = test_cfg_register.c -test_cfg_register_CFLAGS = -D_BSD_SOURCE - %.beam: %.erl $(ERLC) $< @@ -36,7 +32,6 @@ fixture_files = \ fixtures/test.couch tap_files = \ - 173-os-daemon-cfg-register.t \ 180-http-proxy.ini \ 180-http-proxy.t \ 190-json-stream-parse.t \ |