couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [36/36] couchdb commit: updated refs/heads/1963-eunit to 85f2750
Date Tue, 03 Jun 2014 15:55:14 GMT
Port 173-os-daemons-cfg-register.t etap test suite to eunit

Merged into couchdb_os_daemons_tests suite.


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

Branch: refs/heads/1963-eunit
Commit: 85f27505ffb132ce61e916a5b36f82fc2fa11510
Parents: c0ed8cf
Author: Alexander Shorin <kxepal@apache.org>
Authored: Tue Jun 3 19:31:44 2014 +0400
Committer: Alexander Shorin <kxepal@apache.org>
Committed: Tue Jun 3 19:53:23 2014 +0400

----------------------------------------------------------------------
 configure.ac                              |   1 +
 license.skip                              |   4 +
 test/couchdb/Makefile.am                  |   2 +
 test/couchdb/couchdb_os_daemons_tests.erl | 102 ++++++++++++++++++++--
 test/couchdb/fixtures/Makefile.am         |  15 ++++
 test/couchdb/fixtures/test_cfg_register.c |  31 +++++++
 test/etap/173-os-daemon-cfg-register.t    | 116 -------------------------
 test/etap/Makefile.am                     |   5 --
 test/etap/test_cfg_register.c             |  31 -------
 9 files changed, 150 insertions(+), 157 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/85f27505/configure.ac
----------------------------------------------------------------------
diff --git a/configure.ac b/configure.ac
index 4d45a97..aa293e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -755,6 +755,7 @@ AC_CONFIG_FILES([test/Makefile])
 AC_CONFIG_FILES([test/bench/Makefile])
 AC_CONFIG_FILES([test/couchdb/run])
 AC_CONFIG_FILES([test/couchdb/Makefile])
+AC_CONFIG_FILES([test/couchdb/fixtures/Makefile])
 AC_CONFIG_FILES([test/couchdb/couchdb_tests.hrl])
 AC_CONFIG_FILES([test/etap/Makefile])
 AC_CONFIG_FILES([test/etap/test_util.erl])

http://git-wip-us.apache.org/repos/asf/couchdb/blob/85f27505/license.skip
----------------------------------------------------------------------
diff --git a/license.skip b/license.skip
index b069451..ec5df1e 100644
--- a/license.skip
+++ b/license.skip
@@ -171,6 +171,10 @@
 ^test/couchdb/Makefile
 ^test/couchdb/Makefile.in
 ^test/couchdb/fixtures/logo.png
+^test/couchdb/fixtures/Makefile
+^test/couchdb/fixtures/Makefile.in
+^test/couchdb/fixtures/test_cfg_register
+^test/couchdb/fixtures/test_cfg_register.o
 ^test/etap/.*.beam
 ^test/etap/.*.o
 ^test/etap/.deps/.*

http://git-wip-us.apache.org/repos/asf/couchdb/blob/85f27505/test/couchdb/Makefile.am
----------------------------------------------------------------------
diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am
index bf306c8..937ddf6 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:

http://git-wip-us.apache.org/repos/asf/couchdb/blob/85f27505/test/couchdb/couchdb_os_daemons_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb/couchdb_os_daemons_tests.erl b/test/couchdb/couchdb_os_daemons_tests.erl
index 0591176..ece59c8 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).
 
 
@@ -104,6 +105,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
@@ -184,7 +200,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
@@ -192,7 +208,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)
@@ -204,17 +220,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(1000)
+    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(1000)
+    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).
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/85f27505/test/couchdb/fixtures/Makefile.am
----------------------------------------------------------------------
diff --git a/test/couchdb/fixtures/Makefile.am b/test/couchdb/fixtures/Makefile.am
new file mode 100644
index 0000000..1273234
--- /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

http://git-wip-us.apache.org/repos/asf/couchdb/blob/85f27505/test/couchdb/fixtures/test_cfg_register.c
----------------------------------------------------------------------
diff --git a/test/couchdb/fixtures/test_cfg_register.c b/test/couchdb/fixtures/test_cfg_register.c
new file mode 100644
index 0000000..c910bac
--- /dev/null
+++ b/test/couchdb/fixtures/test_cfg_register.c
@@ -0,0 +1,31 @@
+// 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.
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(int argc, const char * argv[])
+{
+    char c = '\0';
+    size_t num = 1;
+    
+    fprintf(stdout, "[\"register\", \"s1\"]\n");
+    fprintf(stdout, "[\"register\", \"s2\", \"k\"]\n");
+    fflush(stdout);
+    
+    while(c != '\n' && num > 0) {
+        num = fread(&c, 1, 1, stdin);
+    }
+    
+    exit(0);
+}

http://git-wip-us.apache.org/repos/asf/couchdb/blob/85f27505/test/etap/173-os-daemon-cfg-register.t
----------------------------------------------------------------------
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 256ee7d..0000000
--- 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.").

http://git-wip-us.apache.org/repos/asf/couchdb/blob/85f27505/test/etap/Makefile.am
----------------------------------------------------------------------
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
index e42d398..05a7870 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 \

http://git-wip-us.apache.org/repos/asf/couchdb/blob/85f27505/test/etap/test_cfg_register.c
----------------------------------------------------------------------
diff --git a/test/etap/test_cfg_register.c b/test/etap/test_cfg_register.c
deleted file mode 100644
index c910bac..0000000
--- a/test/etap/test_cfg_register.c
+++ /dev/null
@@ -1,31 +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.
-
-#include <stdio.h>
-#include <stdlib.h>
-
-int
-main(int argc, const char * argv[])
-{
-    char c = '\0';
-    size_t num = 1;
-    
-    fprintf(stdout, "[\"register\", \"s1\"]\n");
-    fprintf(stdout, "[\"register\", \"s2\", \"k\"]\n");
-    fflush(stdout);
-    
-    while(c != '\n' && num > 0) {
-        num = fread(&c, 1, 1, stdin);
-    }
-    
-    exit(0);
-}


Mime
View raw message