couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [29/48] couch commit: updated refs/heads/master to 7776921
Date Sat, 04 Apr 2015 23:29:24 GMT
Enable couchdb_compaction_daemon test suite

COUCHDB-2547


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

Branch: refs/heads/master
Commit: d4d726cce4d909cee8f00985a7ddfff33627be35
Parents: 0b3e896
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Tue Feb 3 13:14:20 2015 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Feb 10 11:06:07 2015 -0800

----------------------------------------------------------------------
 src/couch.app.src                  |  1 +
 test/couchdb_compaction_daemon.erl | 62 ++++++++++++++++++---------------
 2 files changed, 35 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/d4d726cc/src/couch.app.src
----------------------------------------------------------------------
diff --git a/src/couch.app.src b/src/couch.app.src
index 54eedf8..0b232f7 100644
--- a/src/couch.app.src
+++ b/src/couch.app.src
@@ -34,6 +34,7 @@
         sasl,
         inets,
         ssl,
+        os_mon,
 
         % Upstream deps
         ibrowse,

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/d4d726cc/test/couchdb_compaction_daemon.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_compaction_daemon.erl b/test/couchdb_compaction_daemon.erl
index c9e0c38..7d771fd 100644
--- a/test/couchdb_compaction_daemon.erl
+++ b/test/couchdb_compaction_daemon.erl
@@ -20,8 +20,6 @@
 -define(TIMEOUT_S, ?TIMEOUT div 1000).
 
 
--ifdef(run_broken_tests).
-
 start() ->
     Ctx = test_util:start_couch(),
     config:set("compaction_daemon", "check_interval", "3", false),
@@ -76,9 +74,11 @@ should_compact_by_default_rule(DbName) ->
             "[{db_fragmentation, \"70%\"}, {view_fragmentation, \"70%\"}]",
             false),
 
-        ok = timer:sleep(4000), % something >= check_interval
+        ok = timer:sleep(5000), % something >= check_interval
         wait_compaction_finished(DbName),
+
         ok = config:delete("compactions", "_default", false),
+        ok = timer:sleep(1000), % need to wait so gen_server:cast would complete
 
         {DbFrag2, DbFileSize2} = get_db_frag(DbName),
         {ViewFrag2, ViewFileSize2} = get_view_frag(DbName),
@@ -89,7 +89,7 @@ should_compact_by_default_rule(DbName) ->
         ?assert(DbFileSize > DbFileSize2),
         ?assert(ViewFileSize > ViewFileSize2),
 
-        ?assert(couch_db:is_idle(Db)),
+        ?assert(is_idle(DbName)),
         ok = couch_db:close(Db)
     end)}.
 
@@ -108,6 +108,7 @@ should_compact_by_dbname_rule(DbName) ->
         ok = timer:sleep(4000), % something >= check_interval
         wait_compaction_finished(DbName),
         ok = config:delete("compactions", ?b2l(DbName), false),
+        ok = timer:sleep(1000), % need to wait so gen_server:cast would complete
 
         {DbFrag2, DbFileSize2} = get_db_frag(DbName),
         {ViewFrag2, ViewFileSize2} = get_view_frag(DbName),
@@ -118,7 +119,7 @@ should_compact_by_dbname_rule(DbName) ->
         ?assert(DbFileSize > DbFileSize2),
         ?assert(ViewFileSize > ViewFileSize2),
 
-        ?assert(couch_db:is_idle(Db)),
+        ?assert(is_idle(DbName)),
         ok = couch_db:close(Db)
     end)}.
 
@@ -182,43 +183,48 @@ get_db_frag(DbName) ->
     {ok, Db} = couch_db:open_int(DbName, []),
     {ok, Info} = couch_db:get_db_info(Db),
     couch_db:close(Db),
-    FileSize = couch_util:get_value(disk_size, Info),
-    DataSize = couch_util:get_value(data_size, Info),
+    FileSize = get_size(file, Info),
+    DataSize = get_size(external, Info),
     {round((FileSize - DataSize) / FileSize * 100), FileSize}.
 
 get_view_frag(DbName) ->
     {ok, Db} = couch_db:open_int(DbName, []),
     {ok, Info} = couch_mrview:get_info(Db, <<"_design/foo">>),
     couch_db:close(Db),
-    FileSize = couch_util:get_value(disk_size, Info),
-    DataSize = couch_util:get_value(data_size, Info),
+    FileSize = get_size(file, Info),
+    DataSize = get_size(external, Info),
     {round((FileSize - DataSize) / FileSize * 100), FileSize}.
 
+get_size(Kind, Info) ->
+    couch_util:get_nested_json_value({Info}, [sizes, Kind]).
+
 wait_compaction_finished(DbName) ->
-    Parent = self(),
-    Loop = spawn_link(fun() -> wait_loop(DbName, Parent) end),
-    receive
-        {done, Loop} ->
+    WaitFun = fun() ->
+       case is_compaction_running(DbName) of
+           true -> wait;
+           false -> ok
+       end
+    end,
+    case test_util:wait(WaitFun, 10000) of
+        timeout ->
+            erlang:error({assertion_failed,
+                          [{module, ?MODULE},
+                           {line, ?LINE},
+                           {reason, "Compaction timeout"}]});
+        _ ->
             ok
-    after ?TIMEOUT ->
-        erlang:error(
-            {assertion_failed,
-             [{module, ?MODULE}, {line, ?LINE},
-              {reason, "Compaction timeout"}]})
     end.
 
-wait_loop(DbName, Parent) ->
+is_compaction_running(DbName) ->
     {ok, Db} = couch_db:open_int(DbName, []),
     {ok, DbInfo} = couch_db:get_db_info(Db),
     {ok, ViewInfo} = couch_mrview:get_info(Db, <<"_design/foo">>),
     couch_db:close(Db),
-    case (couch_util:get_value(compact_running, ViewInfo) =:= true) orelse
-        (couch_util:get_value(compact_running, DbInfo) =:= true) of
-        false ->
-            Parent ! {done, self()};
-        true ->
-            ok = timer:sleep(?DELAY),
-            wait_loop(DbName, Parent)
-    end.
+    (couch_util:get_value(compact_running, ViewInfo) =:= true)
+        orelse (couch_util:get_value(compact_running, DbInfo) =:= true).
 
--endif.
+is_idle(DbName) ->
+    {ok, Db} = couch_db:open_int(DbName, [?ADMIN_CTX]),
+    Monitors = couch_db:monitored_by(Db),
+    ok = couch_db:close(Db),
+    not lists:any(fun(M) -> M /= self() end, Monitors).


Mime
View raw message