couchdb-commits mailing list archives

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

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

Branch: refs/heads/master
Commit: c51247d6519eff35b429ebc7a25183c0aa8801f6
Parents: 0d5acb1
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Tue Feb 3 12:23:36 2015 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Feb 10 11:05:02 2015 -0800

----------------------------------------------------------------------
 test/couchdb_file_compression_tests.erl | 74 +++++++++++++---------------
 1 file changed, 35 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/c51247d6/test/couchdb_file_compression_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_file_compression_tests.erl b/test/couchdb_file_compression_tests.erl
index 1b9c491..a62114e 100644
--- a/test/couchdb_file_compression_tests.erl
+++ b/test/couchdb_file_compression_tests.erl
@@ -19,9 +19,6 @@
 -define(DOCS_COUNT, 5000).
 -define(TIMEOUT, 30000).
 
-
--ifdef(run_broken_tests).
-
 setup() ->
     config:set("couchdb", "file_compression", "none", false),
     DbName = ?tempdb(),
@@ -170,45 +167,16 @@ refresh_index(DbName) ->
 compact_db(DbName) ->
     DiskSizeBefore = db_disk_size(DbName),
     {ok, Db} = couch_db:open_int(DbName, []),
-    {ok, CompactPid} = couch_db:start_compact(Db),
-    MonRef = erlang:monitor(process, CompactPid),
-    receive
-        {'DOWN', MonRef, process, CompactPid, normal} ->
-            ok;
-        {'DOWN', MonRef, process, CompactPid, Reason} ->
-            erlang:error({assertion_failed,
-                          [{module, ?MODULE},
-                           {line, ?LINE},
-                           {reason, "Error compacting database: "
-                                    ++ couch_util:to_list(Reason)}]})
-    after ?TIMEOUT ->
-        erlang:error({assertion_failed,
-                      [{module, ?MODULE},
-                       {line, ?LINE},
-                       {reason, "Timeout waiting for database compaction"}]})
-    end,
+    {ok, _CompactPid} = couch_db:start_compact(Db),
+    wait_compaction(DbName, "database", ?LINE),
     ok = couch_db:close(Db),
     DiskSizeAfter = db_disk_size(DbName),
     ?assert(DiskSizeBefore > DiskSizeAfter).
 
 compact_view(DbName) ->
     DiskSizeBefore = view_disk_size(DbName),
-    {ok, MonRef} = couch_mrview:compact(DbName, ?DDOC_ID, [monitor]),
-    receive
-        {'DOWN', MonRef, process, _CompactPid, normal} ->
-            ok;
-        {'DOWN', MonRef, process, _CompactPid, Reason} ->
-            erlang:error({assertion_failed,
-                          [{module, ?MODULE},
-                           {line, ?LINE},
-                           {reason, "Error compacting view group: "
-                                    ++ couch_util:to_list(Reason)}]})
-    after ?TIMEOUT ->
-        erlang:error({assertion_failed,
-                      [{module, ?MODULE},
-                       {line, ?LINE},
-                       {reason, "Timeout waiting for view group compaction"}]})
-    end,
+    {ok, _MonRef} = couch_mrview:compact(DbName, ?DDOC_ID, [monitor]),
+    wait_compaction(DbName, "view group", ?LINE),
     DiskSizeAfter = view_disk_size(DbName),
     ?assert(DiskSizeBefore > DiskSizeAfter).
 
@@ -216,13 +184,41 @@ db_disk_size(DbName) ->
     {ok, Db} = couch_db:open_int(DbName, []),
     {ok, Info} = couch_db:get_db_info(Db),
     ok = couch_db:close(Db),
-    couch_util:get_value(disk_size, Info).
+    active_size(Info).
 
 view_disk_size(DbName) ->
     {ok, Db} = couch_db:open_int(DbName, []),
     {ok, DDoc} = couch_db:open_doc(Db, ?DDOC_ID, [ejson_body]),
     {ok, Info} = couch_mrview:get_info(Db, DDoc),
     ok = couch_db:close(Db),
-    couch_util:get_value(disk_size, Info).
+    active_size(Info).
+
+active_size(Info) ->
+    couch_util:get_nested_json_value({Info}, [sizes, active]).
 
--endif.
+wait_compaction(DbName, Kind, Line) ->
+    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, "Timeout waiting for "
+                                    ++ Kind
+                                    ++ " database compaction"}]});
+        _ ->
+            ok
+    end.
+
+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, ?DDOC_ID),
+    couch_db:close(Db),
+    (couch_util:get_value(compact_running, ViewInfo) =:= true)
+        orelse (couch_util:get_value(compact_running, DbInfo) =:= true).


Mime
View raw message