You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2017/02/02 18:35:37 UTC

[2/2] couch commit: updated refs/heads/COUCHDB-3288-remove-public-db-record to 997bc61

Fix compaction daemon tests

There was a race condition in the compaction daemon tests where the
compaction daemon would think a compaction had finished but the test
would grab file size info before the compaction had swapped out which
breaks the assertion that fragmentation was reduced.

There was also a slight error in calculating the fragmentation in the
test suite by using the wrong size value.


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

Branch: refs/heads/COUCHDB-3288-remove-public-db-record
Commit: 5d8cd2b85b86f0e9f6d0e138a08a5cbeb044942b
Parents: 87b35c4
Author: Paul J. Davis <pa...@gmail.com>
Authored: Thu Feb 2 12:33:55 2017 -0600
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Feb 2 12:35:29 2017 -0600

----------------------------------------------------------------------
 test/couchdb_compaction_daemon_tests.erl | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/5d8cd2b8/test/couchdb_compaction_daemon_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_compaction_daemon_tests.erl b/test/couchdb_compaction_daemon_tests.erl
index 4c35fb7..3cd0821 100644
--- a/test/couchdb_compaction_daemon_tests.erl
+++ b/test/couchdb_compaction_daemon_tests.erl
@@ -26,6 +26,9 @@ start() ->
     Ctx.
 
 setup() ->
+    ok = meck:new(couch_db_updater, [passthrough]),
+    ok = meck:new(couch_mrview_compactor, [passthrough]),
+
     DbName = ?tempdb(),
     {ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]),
     create_design_doc(Db),
@@ -40,6 +43,10 @@ teardown(DbName) ->
         end,
         Configs),
     couch_server:delete(DbName, [?ADMIN_CTX]),
+
+    (catch meck:unload(couch_mrview_compactor)),
+    (catch meck:unload(couch_db_updater)),
+
     ok.
 
 
@@ -77,6 +84,7 @@ should_compact_by_default_rule(DbName) ->
 
         wait_compaction_started(DbName),
         wait_compaction_finished(DbName),
+        wait_for_compactor_swap(),
 
         with_config_change(DbName, fun() ->
             ok = config:delete("compactions", "_default", false)
@@ -111,6 +119,7 @@ should_compact_by_dbname_rule(DbName) ->
 
         wait_compaction_started(DbName),
         wait_compaction_finished(DbName),
+        wait_for_compactor_swap(),
 
         with_config_change(DbName, fun() ->
             ok = config:delete("compactions", ?b2l(DbName), false)
@@ -190,7 +199,7 @@ get_db_frag(DbName) ->
     {ok, Info} = couch_db:get_db_info(Db),
     couch_db:close(Db),
     FileSize = get_size(file, Info),
-    DataSize = get_size(external, Info),
+    DataSize = get_size(active, Info),
     {round((FileSize - DataSize) / FileSize * 100), FileSize}.
 
 get_view_frag(DbName) ->
@@ -198,7 +207,7 @@ get_view_frag(DbName) ->
     {ok, Info} = couch_mrview:get_info(Db, <<"_design/foo">>),
     couch_db:close(Db),
     FileSize = get_size(file, Info),
-    DataSize = get_size(external, Info),
+    DataSize = get_size(active, Info),
     {round((FileSize - DataSize) / FileSize * 100), FileSize}.
 
 get_size(Kind, Info) ->
@@ -238,6 +247,10 @@ wait_compaction_finished(DbName) ->
             ok
     end.
 
+wait_for_compactor_swap() ->
+    meck:wait(couch_db_updater, handle_cast, [{compact_done, '_'}, '_'], 1000),
+    meck:wait(couch_mrview_compactor, swap_compacted, ['_', '_'], 1000).
+
 is_compaction_running(_DbName) ->
     couch_compaction_daemon:in_progress() /= [].