You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2014/07/22 01:57:46 UTC

[33/43] couchdb commit: updated refs/heads/1963-eunit-bigcouch to 424dca5

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/b17bfa9e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/b17bfa9e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/b17bfa9e

Branch: refs/heads/1963-eunit-bigcouch
Commit: b17bfa9e6c061d6f1fa53c70d2be00cc1c1bf339
Parents: 0ca3e0a
Author: Alexander Shorin <kx...@apache.org>
Authored: Tue Jun 3 19:31:44 2014 +0400
Committer: Russell Branca <ch...@apache.org>
Committed: Mon Jul 21 16:49:43 2014 -0700

----------------------------------------------------------------------
 .gitignore                                |   4 +
 license.skip                              |   6 ++
 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/test_cfg_register.c             |  31 -------
 7 files changed, 153 insertions(+), 152 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/b17bfa9e/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index ad9479d..c0bc173 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,7 @@ share/server/main.js
 src/couch/priv/couch_js/config.h
 src/couch/priv/couchjs
 src/couch/priv/couchspawnkillable
+
+test/couchdb/run
+test/couchdb/couch_eunit.hrl
+test/couchdb/fixtures/.deps/

http://git-wip-us.apache.org/repos/asf/couchdb/blob/b17bfa9e/license.skip
----------------------------------------------------------------------
diff --git a/license.skip b/license.skip
index 7b6ca04..8505a42 100644
--- a/license.skip
+++ b/license.skip
@@ -202,6 +202,12 @@
 ^test/Makefile.in
 ^test/bench/Makefile
 ^test/bench/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/etap.erl

http://git-wip-us.apache.org/repos/asf/couchdb/blob/b17bfa9e/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 aa949c9..e988548 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(TIMEOUT, 1000).
 
@@ -105,6 +106,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
@@ -185,7 +201,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
@@ -193,7 +209,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)
@@ -205,17 +221,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).
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/b17bfa9e/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/b17bfa9e/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/b17bfa9e/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 065e999..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() ->
-    application:start(config),
-    couch_os_daemons:start_link(),
-    
-    DaemonCmd = daemon_cmd() ++ " 2> /dev/null",
-    
-    etap:diag("Booting the daemon"),
-    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."),
-    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."),
-    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."),
-    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/b17bfa9e/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);
-}