couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [1/2] couch commit: updated refs/heads/master to 79b5243
Date Fri, 16 Oct 2015 15:59:15 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/master f55205d6c -> 79b5243ae


Stabilize os daemons test

Increase delay timeout to fix this failure:

```
**error:{assertNotEqual,[{module,couchdb_os_daemons_tests},
                 {line,207},
                 {expression,"D # daemon . kill"},
                 {value,undefined}]}
```

So far noticed this failure once out of more than 100 runs.


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

Branch: refs/heads/master
Commit: c3971a0a389de0d90fcc12b6f5bfa9c366138ed4
Parents: b5e7e54
Author: Nick Vatamaniuc <vatamane@gmail.com>
Authored: Wed Oct 14 14:04:20 2015 -0400
Committer: Nick Vatamaniuc <vatamane@gmail.com>
Committed: Fri Oct 16 11:09:40 2015 -0400

----------------------------------------------------------------------
 test/couchdb_os_daemons_tests.erl | 36 +++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/c3971a0a/test/couchdb_os_daemons_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_os_daemons_tests.erl b/test/couchdb_os_daemons_tests.erl
index a2f8cfe..dd6591e 100644
--- a/test/couchdb_os_daemons_tests.erl
+++ b/test/couchdb_os_daemons_tests.erl
@@ -32,7 +32,8 @@
 -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(DELAY, 100).
+-define(TRIES, 20).
+-define(TRY_DELAY_MS, 100).
 -define(TIMEOUT, 1000).
 
 
@@ -44,7 +45,7 @@ setup(DName) ->
     % Set configuration option to be used by configuration_reader_test_
     % This will be used in os_daemon_configer.escript:test_get_cfg2
     config:set("uuids", "algorithm","sequential", false),
-    timer:sleep(?DELAY),  % sleep a bit to let daemon set kill flag
+    ensure_n_daemons_are_alive(1),
     {Ctx, OsDPid}.
 
 teardown(_, {Ctx, OsDPid}) ->
@@ -122,7 +123,7 @@ should_spawn_multiple_daemons(DName, _) ->
                          filename:join([?FIXTURESDIR, DName]), false),
         config:set("os_daemons", "baz",
                          filename:join([?FIXTURESDIR, DName]), false),
-        timer:sleep(?DELAY),
+        ensure_n_daemons_are_alive(3), % DName, "bar" and "baz"
         {ok, Daemons} = couch_os_daemons:info([table]),
         lists:foreach(fun(D) ->
             check_daemon(D)
@@ -137,14 +138,14 @@ should_keep_alive_one_daemon_on_killing_other(DName, _) ->
     ?_test(begin
         config:set("os_daemons", "bar",
                          filename:join([?FIXTURESDIR, DName]), false),
-        timer:sleep(?DELAY),
+        ensure_n_daemons_are_alive(2), % DName and "bar"
         {ok, Daemons} = couch_os_daemons:info([table]),
         lists:foreach(fun(D) ->
             check_daemon(D)
         end, Daemons),
 
         config:delete("os_daemons", "bar", false),
-        timer:sleep(?DELAY),
+        ensure_n_daemons_are_alive(1), % Dname only, "bar" should be dead
         {ok, [D2]} = couch_os_daemons:info([table]),
         check_daemon(D2, DName),
 
@@ -216,3 +217,28 @@ check_dead(D, Name) ->
     ?assertEqual(halted, D#daemon.status),
     ?assertEqual(nil, D#daemon.errors),
     ?assertEqual(nil, D#daemon.buf).
+
+daemons() ->
+    {ok, Daemons} = couch_os_daemons:info([table]),
+    Daemons.
+
+ensure_n_daemons_are_alive(NumDaemons) ->
+    retry(fun() -> length(daemons()) == NumDaemons end, "spawning"),
+    retry(fun() ->
+                  lists:all(fun(D) -> D#daemon.kill =/= undefined end, daemons())
+          end, "waiting for kill flag").
+
+retry(Pred, FailReason) ->
+    retry(Pred, ?TRIES, FailReason).
+
+retry(_Pred, 0, FailReason) ->
+    erlang:error({assertion_failed,[{module, ?MODULE}, {line, ?LINE},
+                                    {reason, "Timed out: " ++ FailReason}]});
+retry(Pred, N, FailReason) ->
+    case Pred() of
+        true ->
+            ok;
+        false ->
+            timer:sleep(?TRY_DELAY_MS),
+            retry(Pred, N - 1, FailReason)
+    end.


Mime
View raw message