You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2016/03/14 05:12:32 UTC

[1/5] couch commit: updated refs/heads/master to 9d28c57

Repository: couchdb-couch
Updated Branches:
  refs/heads/master 6ae90beec -> 9d28c5715


Remove couch_stats_tests

CouchDB 2.0 received completely new stats application which works
differently and requires completely different testing approach which
respects new features and folsom backend.


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

Branch: refs/heads/master
Commit: 2643866cebeeae81c07e8d6a908c839b8bf1bb31
Parents: ccb1d3c
Author: Alexander Shorin <kx...@apache.org>
Authored: Thu Nov 26 20:41:16 2015 +0300
Committer: Alexander Shorin <kx...@apache.org>
Committed: Mon Mar 14 06:24:31 2016 +0300

----------------------------------------------------------------------
 test/couch_stats_tests.erl | 398 ----------------------------------------
 1 file changed, 398 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2643866c/test/couch_stats_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_stats_tests.erl b/test/couch_stats_tests.erl
deleted file mode 100644
index 762953d..0000000
--- a/test/couch_stats_tests.erl
+++ /dev/null
@@ -1,398 +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.
-
--module(couch_stats_tests).
-
--include_lib("couch/include/couch_eunit.hrl").
--include_lib("couch/include/couch_db.hrl").
-
--define(STATS_CFG_FIXTURE,
-    filename:join([?FIXTURESDIR, "couch_stats_aggregates.cfg"])).
--define(STATS_INI_FIXTURE,
-    filename:join([?FIXTURESDIR, "couch_stats_aggregates.ini"])).
--define(TIMEOUT, 1000).
--define(TIMEWAIT, 500).
-
-
--ifdef(run_broken_tests).
-
-setup_collector() ->
-    couch_stats_collector:start(),
-    ok.
-
-setup_aggregator(_) ->
-    {ok, Pid} = config:start_link([?STATS_INI_FIXTURE]),
-    {ok, _} = couch_stats_collector:start(),
-    {ok, _} = couch_stats_aggregator:start(?STATS_CFG_FIXTURE),
-    Pid.
-
-teardown_collector(_) ->
-    couch_stats_collector:stop(),
-    ok.
-
-teardown_aggregator(_, Pid) ->
-    couch_stats_aggregator:stop(),
-    couch_stats_collector:stop(),
-    test_util:stop_config(Pid).
-
-
-couch_stats_collector_test_() ->
-    {
-        "CouchDB stats collector tests",
-        {
-            foreach,
-            fun setup_collector/0, fun teardown_collector/1,
-            [
-                should_increment_counter(),
-                should_decrement_counter(),
-                should_increment_and_decrement_counter(),
-                should_record_absolute_values(),
-                should_clear_absolute_values(),
-                should_track_process_count(),
-                should_increment_counter_multiple_times_per_pid(),
-                should_decrement_counter_on_process_exit(),
-                should_decrement_for_each_track_process_count_call_on_exit(),
-                should_return_all_counters_and_absolute_values(),
-                should_return_incremental_counters(),
-                should_return_absolute_values()
-            ]
-        }
-    }.
-
-couch_stats_aggregator_test_() ->
-    Funs = [
-        fun should_init_empty_aggregate/2,
-        fun should_get_empty_aggregate/2,
-        fun should_change_stats_on_values_add/2,
-        fun should_change_stats_for_all_times_on_values_add/2,
-        fun should_change_stats_on_values_change/2,
-        fun should_change_stats_for_all_times_on_values_change/2,
-        fun should_not_remove_data_after_some_time_for_0_sample/2,
-        fun should_remove_data_after_some_time_for_other_samples/2
-    ],
-    {
-        "CouchDB stats aggregator tests",
-        [
-            {
-                "Absolute values",
-                {
-                    foreachx,
-                    fun setup_aggregator/1, fun teardown_aggregator/2,
-                    [{absolute, Fun} || Fun <- Funs]
-                }
-            },
-            {
-                "Counters",
-                {
-                    foreachx,
-                    fun setup_aggregator/1, fun teardown_aggregator/2,
-                    [{counter, Fun} || Fun <- Funs]
-                }
-            }
-        ]
-    }.
-
-
-should_increment_counter() ->
-    ?_assertEqual(100,
-        begin
-            AddCount = fun() -> couch_stats_collector:increment(foo) end,
-            repeat(AddCount, 100),
-            couch_stats_collector:get(foo)
-        end).
-
-should_decrement_counter() ->
-    ?_assertEqual(67,
-        begin
-            AddCount = fun() -> couch_stats_collector:increment(foo) end,
-            RemCount = fun() -> couch_stats_collector:decrement(foo) end,
-            repeat(AddCount, 100),
-            repeat(RemCount, 33),
-            couch_stats_collector:get(foo)
-        end).
-
-should_increment_and_decrement_counter() ->
-    ?_assertEqual(0,
-        begin
-            AddCount = fun() -> couch_stats_collector:increment(foo) end,
-            RemCount = fun() -> couch_stats_collector:decrement(foo) end,
-            repeat(AddCount, 100),
-            repeat(RemCount, 25),
-            repeat(AddCount, 10),
-            repeat(RemCount, 5),
-            repeat(RemCount, 80),
-            couch_stats_collector:get(foo)
-        end).
-
-should_record_absolute_values() ->
-    ?_assertEqual(lists:seq(1, 15),
-        begin
-            lists:map(fun(Val) ->
-                couch_stats_collector:record(bar, Val)
-            end, lists:seq(1, 15)),
-            couch_stats_collector:get(bar)
-        end).
-
-should_clear_absolute_values() ->
-    ?_assertEqual(nil,
-        begin
-            lists:map(fun(Val) ->
-                couch_stats_collector:record(bar, Val)
-            end, lists:seq(1, 15)),
-            couch_stats_collector:clear(bar),
-            couch_stats_collector:get(bar)
-        end).
-
-should_track_process_count() ->
-    ?_assertMatch({_, 1}, spawn_and_count(1)).
-
-should_increment_counter_multiple_times_per_pid() ->
-    ?_assertMatch({_, 3}, spawn_and_count(3)).
-
-should_decrement_counter_on_process_exit() ->
-    ?_assertEqual(2,
-        begin
-            {Pid, 1} = spawn_and_count(1),
-            spawn_and_count(2),
-            test_util:stop_sync_throw(Pid,
-                fun() -> Pid ! sepuku end, timeout, ?TIMEOUT),
-            % sleep for awhile to let collector handle the updates
-            % suddenly, it couldn't notice process death instantly
-            timer:sleep(?TIMEWAIT),
-            couch_stats_collector:get(hoopla)
-        end).
-
-should_decrement_for_each_track_process_count_call_on_exit() ->
-    ?_assertEqual(2,
-        begin
-            {_, 2} = spawn_and_count(2),
-            {Pid, 6} = spawn_and_count(4),
-            test_util:stop_sync_throw(Pid,
-                fun() -> Pid ! sepuku end, timeout, ?TIMEOUT),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_collector:get(hoopla)
-        end).
-
-should_return_all_counters_and_absolute_values() ->
-    ?_assertEqual([{bar,[1.0,0.0]}, {foo,1}],
-        begin
-            couch_stats_collector:record(bar, 0.0),
-            couch_stats_collector:record(bar, 1.0),
-            couch_stats_collector:increment(foo),
-            lists:sort(couch_stats_collector:all())
-        end).
-
-should_return_incremental_counters() ->
-    ?_assertEqual([{foo,1}],
-        begin
-            couch_stats_collector:record(bar, 0.0),
-            couch_stats_collector:record(bar, 1.0),
-            couch_stats_collector:increment(foo),
-            lists:sort(couch_stats_collector:all(incremental))
-        end).
-
-should_return_absolute_values() ->
-    ?_assertEqual([{bar,[1.0,0.0]}, {zing, "Z"}],
-        begin
-            couch_stats_collector:record(bar, 0.0),
-            couch_stats_collector:record(bar, 1.0),
-            couch_stats_collector:record(zing, 90),
-            couch_stats_collector:increment(foo),
-            lists:sort(couch_stats_collector:all(absolute))
-        end).
-
-should_init_empty_aggregate(absolute, _) ->
-    {Aggs} = couch_stats_aggregator:all(),
-    ?_assertEqual({[{'11', make_agg(<<"randomosity">>,
-                                    null, null, null, null, null)}]},
-                  couch_util:get_value(number, Aggs));
-should_init_empty_aggregate(counter, _) ->
-    {Aggs} = couch_stats_aggregator:all(),
-    ?_assertEqual({[{stuff, make_agg(<<"yay description">>,
-                                     null, null, null, null, null)}]},
-                  couch_util:get_value(testing, Aggs)).
-
-should_get_empty_aggregate(absolute, _) ->
-    ?_assertEqual(make_agg(<<"randomosity">>, null, null, null, null, null),
-             couch_stats_aggregator:get_json({number, '11'}));
-should_get_empty_aggregate(counter, _) ->
-    ?_assertEqual(make_agg(<<"yay description">>, null, null, null, null, null),
-             couch_stats_aggregator:get_json({testing, stuff})).
-
-should_change_stats_on_values_add(absolute, _) ->
-    lists:foreach(fun(X) ->
-        couch_stats_collector:record({number, 11}, X)
-    end, lists:seq(0, 10)),
-    couch_stats_aggregator:collect_sample(),
-    ?_assertEqual(make_agg(<<"randomosity">>, 5.0, 5.0, null, 5.0, 5.0),
-                  couch_stats_aggregator:get_json({number, 11}));
-should_change_stats_on_values_add(counter, _) ->
-    lists:foreach(fun(_) ->
-        couch_stats_collector:increment({testing, stuff})
-    end, lists:seq(1, 100)),
-    couch_stats_aggregator:collect_sample(),
-    ?_assertEqual(make_agg(<<"yay description">>, 100.0, 100.0, null, 100, 100),
-                  couch_stats_aggregator:get_json({testing, stuff})).
-
-should_change_stats_for_all_times_on_values_add(absolute, _) ->
-    lists:foreach(fun(X) ->
-        couch_stats_collector:record({number, 11}, X)
-    end, lists:seq(0, 10)),
-    couch_stats_aggregator:collect_sample(),
-    ?_assertEqual(make_agg(<<"randomosity">>, 5.0, 5.0, null, 5.0, 5.0),
-                  couch_stats_aggregator:get_json({number, 11}, 1));
-should_change_stats_for_all_times_on_values_add(counter, _) ->
-    lists:foreach(fun(_) ->
-        couch_stats_collector:increment({testing, stuff})
-    end, lists:seq(1, 100)),
-    couch_stats_aggregator:collect_sample(),
-    ?_assertEqual(make_agg(<<"yay description">>, 100.0, 100.0, null, 100, 100),
-                  couch_stats_aggregator:get_json({testing, stuff}, 1)).
-
-should_change_stats_on_values_change(absolute, _) ->
-    ?_assertEqual(make_agg(<<"randomosity">>, 20.0, 10.0, 7.071, 5.0, 15.0),
-        begin
-            lists:foreach(fun(X) ->
-                couch_stats_collector:record({number, 11}, X)
-            end, lists:seq(0, 10)),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_collector:record({number, 11}, 15),
-            couch_stats_aggregator:collect_sample(),
-            couch_stats_aggregator:get_json({number, 11})
-        end);
-should_change_stats_on_values_change(counter, _) ->
-    ?_assertEqual(make_agg(<<"yay description">>, 100.0, 50.0, 70.711, 0, 100),
-        begin
-            lists:foreach(fun(_) ->
-                couch_stats_collector:increment({testing, stuff})
-            end, lists:seq(1, 100)),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_aggregator:collect_sample(),
-            couch_stats_aggregator:get_json({testing, stuff})
-        end).
-
-should_change_stats_for_all_times_on_values_change(absolute, _) ->
-    ?_assertEqual(make_agg(<<"randomosity">>, 20.0, 10.0, 7.071, 5.0, 15.0),
-        begin
-            lists:foreach(fun(X) ->
-                couch_stats_collector:record({number, 11}, X)
-            end, lists:seq(0, 10)),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_collector:record({number, 11}, 15),
-            couch_stats_aggregator:collect_sample(),
-            couch_stats_aggregator:get_json({number, 11}, 1)
-        end);
-should_change_stats_for_all_times_on_values_change(counter, _) ->
-    ?_assertEqual(make_agg(<<"yay description">>, 100.0, 50.0, 70.711, 0, 100),
-        begin
-            lists:foreach(fun(_) ->
-                couch_stats_collector:increment({testing, stuff})
-            end, lists:seq(1, 100)),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_aggregator:collect_sample(),
-            couch_stats_aggregator:get_json({testing, stuff}, 1)
-        end).
-
-should_not_remove_data_after_some_time_for_0_sample(absolute, _) ->
-    ?_assertEqual(make_agg(<<"randomosity">>, 20.0, 10.0, 7.071, 5.0, 15.0),
-        begin
-            lists:foreach(fun(X) ->
-                couch_stats_collector:record({number, 11}, X)
-            end, lists:seq(0, 10)),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_collector:record({number, 11}, 15),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_aggregator:collect_sample(),
-            couch_stats_aggregator:get_json({number, 11})
-        end);
-should_not_remove_data_after_some_time_for_0_sample(counter, _) ->
-    ?_assertEqual(make_agg(<<"yay description">>, 100.0, 33.333, 57.735, 0, 100),
-        begin
-            lists:foreach(fun(_) ->
-                couch_stats_collector:increment({testing, stuff})
-            end, lists:seq(1, 100)),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_aggregator:collect_sample(),
-            couch_stats_aggregator:get_json({testing, stuff})
-        end).
-
-should_remove_data_after_some_time_for_other_samples(absolute, _) ->
-    ?_assertEqual(make_agg(<<"randomosity">>, 15.0, 15.0, null, 15.0, 15.0),
-        begin
-            lists:foreach(fun(X) ->
-                couch_stats_collector:record({number, 11}, X)
-            end, lists:seq(0, 10)),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_collector:record({number, 11}, 15),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_aggregator:collect_sample(),
-            couch_stats_aggregator:get_json({number, 11}, 1)
-        end);
-should_remove_data_after_some_time_for_other_samples(counter, _) ->
-    ?_assertEqual(make_agg(<<"yay description">>, 0, 0.0, 0.0, 0, 0),
-        begin
-            lists:foreach(fun(_) ->
-                couch_stats_collector:increment({testing, stuff})
-            end, lists:seq(1, 100)),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_aggregator:collect_sample(),
-            timer:sleep(?TIMEWAIT),
-            couch_stats_aggregator:collect_sample(),
-            couch_stats_aggregator:get_json({testing, stuff}, 1)
-        end).
-
-
-spawn_and_count(N) ->
-    Self = self(),
-    Pid = spawn(fun() ->
-        lists:foreach(
-            fun(_) ->
-                couch_stats_collector:track_process_count(hoopla)
-            end, lists:seq(1,N)),
-        Self ! reporting,
-        receive
-            sepuku -> ok
-        end
-    end),
-    receive reporting -> ok end,
-    {Pid, couch_stats_collector:get(hoopla)}.
-
-repeat(_, 0) ->
-    ok;
-repeat(Fun, Count) ->
-    Fun(),
-    repeat(Fun, Count-1).
-
-make_agg(Desc, Sum, Mean, StdDev, Min, Max) ->
-    {[
-        {description, Desc},
-        {current, Sum},
-        {sum, Sum},
-        {mean, Mean},
-        {stddev, StdDev},
-        {min, Min},
-        {max, Max}
-    ]}.
-
--endif.


[2/5] couch commit: updated refs/heads/master to 9d28c57

Posted by kx...@apache.org.
Increase timeout value to tolerate slow CI hosts


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

Branch: refs/heads/master
Commit: ccb1d3c12bbb1bee3b62234e673188205f467a54
Parents: e3b73c7
Author: Alexander Shorin <kx...@apache.org>
Authored: Thu Nov 26 20:10:05 2015 +0300
Committer: Alexander Shorin <kx...@apache.org>
Committed: Mon Mar 14 06:24:31 2016 +0300

----------------------------------------------------------------------
 test/couchdb_compaction_daemon_tests.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/ccb1d3c1/test/couchdb_compaction_daemon_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_compaction_daemon_tests.erl b/test/couchdb_compaction_daemon_tests.erl
index def3bd5..3228031 100644
--- a/test/couchdb_compaction_daemon_tests.erl
+++ b/test/couchdb_compaction_daemon_tests.erl
@@ -15,7 +15,7 @@
 -include_lib("couch/include/couch_eunit.hrl").
 -include_lib("couch/include/couch_db.hrl").
 
--define(TIMEOUT, 30000).
+-define(TIMEOUT, 60000).
 -define(TIMEOUT_S, ?TIMEOUT div 1000).
 
 


[5/5] couch commit: updated refs/heads/master to 9d28c57

Posted by kx...@apache.org.
Merge remote-tracking branch 'github/pr/130'


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

Branch: refs/heads/master
Commit: 9d28c5715be292d6028848dabafb41646c29b742
Parents: 6ae90be 2643866
Author: Alexander Shorin <kx...@apache.org>
Authored: Mon Mar 14 07:12:16 2016 +0300
Committer: Alexander Shorin <kx...@apache.org>
Committed: Mon Mar 14 07:12:16 2016 +0300

----------------------------------------------------------------------
 src/couch_db_header.erl                  |  14 +-
 test/couch_stats_tests.erl               | 398 --------------------------
 test/couchdb_compaction_daemon.erl       | 261 -----------------
 test/couchdb_compaction_daemon_tests.erl | 258 +++++++++++++++++
 4 files changed, 260 insertions(+), 671 deletions(-)
----------------------------------------------------------------------



[3/5] couch commit: updated refs/heads/master to 9d28c57

Posted by kx...@apache.org.
Update db header now throws an database_disk_version_error error


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

Branch: refs/heads/master
Commit: 2a006077b9a9761c37d0f29095699907d2635702
Parents: 40adf24
Author: Alexander Shorin <kx...@apache.org>
Authored: Thu Nov 26 19:58:11 2015 +0300
Committer: Alexander Shorin <kx...@apache.org>
Committed: Mon Mar 14 06:24:31 2016 +0300

----------------------------------------------------------------------
 src/couch_db_header.erl | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2a006077/src/couch_db_header.erl
----------------------------------------------------------------------
diff --git a/src/couch_db_header.erl b/src/couch_db_header.erl
index 2f329c1..355364f 100644
--- a/src/couch_db_header.erl
+++ b/src/couch_db_header.erl
@@ -310,8 +310,6 @@ mk_header(Vsn) ->
     }.
 
 
--ifdef(run_broken_tests).
-
 upgrade_v3_test() ->
     Vsn3Header = mk_header(3),
     NewHeader = upgrade_tuple(Vsn3Header),
@@ -330,17 +328,9 @@ upgrade_v3_test() ->
     ?assertEqual(undefined, uuid(NewHeader)),
     ?assertEqual(undefined, epochs(NewHeader)),
 
-    % Security ptr isn't changed until upgrade_disk_version/1
-    NewNewHeader = upgrade_disk_version(NewHeader),
-    ?assert(is_record(NewNewHeader, db_header)),
-    ?assertEqual(nil, security_ptr(NewNewHeader)),
-
-    % Assert upgrade works on really old headers
-    NewestHeader = upgrade(Vsn3Header),
-    ?assertMatch(<<_:32/binary>>, uuid(NewestHeader)),
-    ?assertEqual([{node(), 0}], epochs(NewestHeader)).
+    ?assertThrow({database_disk_version_error, _},
+                 upgrade_disk_version(NewHeader)).
 
--endif.
 
 upgrade_v5_test() ->
     Vsn5Header = mk_header(5),


[4/5] couch commit: updated refs/heads/master to 9d28c57

Posted by kx...@apache.org.
Fix test suite name, remove broken tests guard


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

Branch: refs/heads/master
Commit: e3b73c7399e7f70189f5be87e2b0f5730dfdf4a1
Parents: 2a00607
Author: Alexander Shorin <kx...@apache.org>
Authored: Thu Nov 26 20:07:05 2015 +0300
Committer: Alexander Shorin <kx...@apache.org>
Committed: Mon Mar 14 06:24:31 2016 +0300

----------------------------------------------------------------------
 test/couchdb_compaction_daemon.erl       | 261 --------------------------
 test/couchdb_compaction_daemon_tests.erl | 258 +++++++++++++++++++++++++
 2 files changed, 258 insertions(+), 261 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/e3b73c73/test/couchdb_compaction_daemon.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_compaction_daemon.erl b/test/couchdb_compaction_daemon.erl
deleted file mode 100644
index 0598a5a..0000000
--- a/test/couchdb_compaction_daemon.erl
+++ /dev/null
@@ -1,261 +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.
-
--module(couchdb_compaction_daemon).
-
--include_lib("couch/include/couch_eunit.hrl").
--include_lib("couch/include/couch_db.hrl").
-
--define(TIMEOUT, 30000).
--define(TIMEOUT_S, ?TIMEOUT div 1000).
-
--ifdef(run_broken_tests).
-
-start() ->
-    Ctx = test_util:start_couch(),
-    config:set("compaction_daemon", "check_interval", "3", false),
-    config:set("compaction_daemon", "min_file_size", "100000", false),
-    Ctx.
-
-setup() ->
-    DbName = ?tempdb(),
-    {ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]),
-    create_design_doc(Db),
-    ok = couch_db:close(Db),
-    DbName.
-
-teardown(DbName) ->
-    Configs = config:get("compactions"),
-    lists:foreach(
-        fun({Key, _}) ->
-            ok = config:delete("compactions", Key, false)
-        end,
-        Configs),
-    couch_server:delete(DbName, [?ADMIN_CTX]),
-    ok.
-
-
-compaction_daemon_test_() ->
-    {
-        "Compaction daemon tests",
-        {
-            setup,
-            fun start/0, fun test_util:stop_couch/1,
-            {
-                foreach,
-                fun setup/0, fun teardown/1,
-                [
-                    fun should_compact_by_default_rule/1,
-                    fun should_compact_by_dbname_rule/1
-                ]
-            }
-        }
-    }.
-
-
-should_compact_by_default_rule(DbName) ->
-    {timeout, ?TIMEOUT_S, ?_test(begin
-        {ok, Db} = couch_db:open_int(DbName, []),
-        populate(DbName, 70, 70, 200 * 1024),
-
-        {_, DbFileSize} = get_db_frag(DbName),
-        {_, ViewFileSize} = get_view_frag(DbName),
-
-        with_config_change(DbName, fun() ->
-            ok = config:set("compactions", "_default",
-                "[{db_fragmentation, \"70%\"}, {view_fragmentation, \"70%\"}]",
-                false)
-        end),
-
-        wait_compaction_started(DbName),
-        wait_compaction_finished(DbName),
-
-        with_config_change(DbName, fun() ->
-            ok = config:delete("compactions", "_default", false)
-        end),
-
-        {DbFrag2, DbFileSize2} = get_db_frag(DbName),
-        {ViewFrag2, ViewFileSize2} = get_view_frag(DbName),
-
-        ?assert(DbFrag2 < 70),
-        ?assert(ViewFrag2 < 70),
-
-        ?assert(DbFileSize > DbFileSize2),
-        ?assert(ViewFileSize > ViewFileSize2),
-
-        ?assert(is_idle(DbName)),
-        ok = couch_db:close(Db)
-    end)}.
-
-should_compact_by_dbname_rule(DbName) ->
-    {timeout, ?TIMEOUT_S, ?_test(begin
-        {ok, Db} = couch_db:open_int(DbName, []),
-        populate(DbName, 70, 70, 200 * 1024),
-
-        {_, DbFileSize} = get_db_frag(DbName),
-        {_, ViewFileSize} = get_view_frag(DbName),
-
-        with_config_change(DbName, fun() ->
-            ok = config:set("compactions", ?b2l(DbName),
-                "[{db_fragmentation, \"70%\"}, {view_fragmentation, \"70%\"}]",
-                false)
-        end),
-
-        wait_compaction_started(DbName),
-        wait_compaction_finished(DbName),
-
-        with_config_change(DbName, fun() ->
-            ok = config:delete("compactions", ?b2l(DbName), false)
-        end),
-
-        {DbFrag2, DbFileSize2} = get_db_frag(DbName),
-        {ViewFrag2, ViewFileSize2} = get_view_frag(DbName),
-
-        ?assert(DbFrag2 < 70),
-        ?assert(ViewFrag2 < 70),
-
-        ?assert(DbFileSize > DbFileSize2),
-        ?assert(ViewFileSize > ViewFileSize2),
-
-        ?assert(is_idle(DbName)),
-        ok = couch_db:close(Db)
-    end)}.
-
-
-create_design_doc(Db) ->
-    DDoc = couch_doc:from_json_obj({[
-        {<<"_id">>, <<"_design/foo">>},
-        {<<"language">>, <<"javascript">>},
-        {<<"views">>, {[
-            {<<"foo">>, {[
-                {<<"map">>, <<"function(doc) { emit(doc._id, doc); }">>}
-            ]}},
-            {<<"foo2">>, {[
-                {<<"map">>, <<"function(doc) { emit(doc._id, doc); }">>}
-            ]}},
-            {<<"foo3">>, {[
-                {<<"map">>, <<"function(doc) { emit(doc._id, doc); }">>}
-            ]}}
-        ]}}
-    ]}),
-    {ok, _} = couch_db:update_docs(Db, [DDoc]),
-    {ok, _} = couch_db:ensure_full_commit(Db),
-    ok.
-
-populate(DbName, DbFrag, ViewFrag, MinFileSize) ->
-    {CurDbFrag, DbFileSize} = get_db_frag(DbName),
-    {CurViewFrag, ViewFileSize} = get_view_frag(DbName),
-    populate(DbName, DbFrag, ViewFrag, MinFileSize, CurDbFrag, CurViewFrag,
-             lists:min([DbFileSize, ViewFileSize])).
-
-populate(_Db, DbFrag, ViewFrag, MinFileSize, CurDbFrag, CurViewFrag, FileSize)
-    when CurDbFrag >= DbFrag, CurViewFrag >= ViewFrag, FileSize >= MinFileSize ->
-    ok;
-populate(DbName, DbFrag, ViewFrag, MinFileSize, _, _, _) ->
-    update(DbName),
-    {CurDbFrag, DbFileSize} = get_db_frag(DbName),
-    {CurViewFrag, ViewFileSize} = get_view_frag(DbName),
-    populate(DbName, DbFrag, ViewFrag, MinFileSize, CurDbFrag, CurViewFrag,
-             lists:min([DbFileSize, ViewFileSize])).
-
-update(DbName) ->
-    {ok, Db} = couch_db:open_int(DbName, []),
-    lists:foreach(fun(_) ->
-        Doc = couch_doc:from_json_obj({[{<<"_id">>, couch_uuids:new()}]}),
-        {ok, _} = couch_db:update_docs(Db, [Doc]),
-        query_view(Db#db.name)
-    end, lists:seq(1, 200)),
-    couch_db:close(Db).
-
-db_url(DbName) ->
-    Addr = config:get("httpd", "bind_address", "127.0.0.1"),
-    Port = integer_to_list(mochiweb_socket_server:get(couch_httpd, port)),
-    "http://" ++ Addr ++ ":" ++ Port ++ "/" ++ ?b2l(DbName).
-
-query_view(DbName) ->
-    {ok, Code, _Headers, _Body} = test_request:get(
-        db_url(DbName) ++ "/_design/foo/_view/foo"),
-    ?assertEqual(200, Code).
-
-get_db_frag(DbName) ->
-    {ok, Db} = couch_db:open_int(DbName, []),
-    {ok, Info} = couch_db:get_db_info(Db),
-    couch_db:close(Db),
-    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 = 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_started(DbName) ->
-    WaitFun = fun() ->
-        case is_compaction_running(DbName) of
-            false -> wait;
-            true ->  ok
-        end
-    end,
-    case test_util:wait(WaitFun, 10000) of
-        timeout ->
-            erlang:error({assertion_failed,
-                          [{module, ?MODULE},
-                           {line, ?LINE},
-                           {reason, "Compaction starting timeout"}]});
-        _ ->
-            ok
-    end.
-
-wait_compaction_finished(DbName) ->
-    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
-    end.
-
-is_compaction_running(_DbName) ->
-    couch_compaction_daemon:in_progress() /= [].
-
-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).
-
-with_config_change(DbName, Fun) ->
-    Current = ets:info(couch_compaction_daemon_config, size),
-    Fun(),
-    test_util:wait(fun() ->
-        case ets:info(couch_compaction_daemon_config, size) == Current of
-            false -> ok;
-            true -> wait
-        end
-    end).
-
--endif.

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/e3b73c73/test/couchdb_compaction_daemon_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_compaction_daemon_tests.erl b/test/couchdb_compaction_daemon_tests.erl
new file mode 100644
index 0000000..def3bd5
--- /dev/null
+++ b/test/couchdb_compaction_daemon_tests.erl
@@ -0,0 +1,258 @@
+% 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.
+
+-module(couchdb_compaction_daemon_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
+-define(TIMEOUT, 30000).
+-define(TIMEOUT_S, ?TIMEOUT div 1000).
+
+
+start() ->
+    Ctx = test_util:start_couch(),
+    config:set("compaction_daemon", "check_interval", "3", false),
+    config:set("compaction_daemon", "min_file_size", "100000", false),
+    Ctx.
+
+setup() ->
+    DbName = ?tempdb(),
+    {ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]),
+    create_design_doc(Db),
+    ok = couch_db:close(Db),
+    DbName.
+
+teardown(DbName) ->
+    Configs = config:get("compactions"),
+    lists:foreach(
+        fun({Key, _}) ->
+            ok = config:delete("compactions", Key, false)
+        end,
+        Configs),
+    couch_server:delete(DbName, [?ADMIN_CTX]),
+    ok.
+
+
+compaction_daemon_test_() ->
+    {
+        "Compaction daemon tests",
+        {
+            setup,
+            fun start/0, fun test_util:stop_couch/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_compact_by_default_rule/1,
+                    fun should_compact_by_dbname_rule/1
+                ]
+            }
+        }
+    }.
+
+
+should_compact_by_default_rule(DbName) ->
+    {timeout, ?TIMEOUT_S, ?_test(begin
+        {ok, Db} = couch_db:open_int(DbName, []),
+        populate(DbName, 70, 70, 200 * 1024),
+
+        {_, DbFileSize} = get_db_frag(DbName),
+        {_, ViewFileSize} = get_view_frag(DbName),
+
+        with_config_change(DbName, fun() ->
+            ok = config:set("compactions", "_default",
+                "[{db_fragmentation, \"70%\"}, {view_fragmentation, \"70%\"}]",
+                false)
+        end),
+
+        wait_compaction_started(DbName),
+        wait_compaction_finished(DbName),
+
+        with_config_change(DbName, fun() ->
+            ok = config:delete("compactions", "_default", false)
+        end),
+
+        {DbFrag2, DbFileSize2} = get_db_frag(DbName),
+        {ViewFrag2, ViewFileSize2} = get_view_frag(DbName),
+
+        ?assert(DbFrag2 < 70),
+        ?assert(ViewFrag2 < 70),
+
+        ?assert(DbFileSize > DbFileSize2),
+        ?assert(ViewFileSize > ViewFileSize2),
+
+        ?assert(is_idle(DbName)),
+        ok = couch_db:close(Db)
+    end)}.
+
+should_compact_by_dbname_rule(DbName) ->
+    {timeout, ?TIMEOUT_S, ?_test(begin
+        {ok, Db} = couch_db:open_int(DbName, []),
+        populate(DbName, 70, 70, 200 * 1024),
+
+        {_, DbFileSize} = get_db_frag(DbName),
+        {_, ViewFileSize} = get_view_frag(DbName),
+
+        with_config_change(DbName, fun() ->
+            ok = config:set("compactions", ?b2l(DbName),
+                "[{db_fragmentation, \"70%\"}, {view_fragmentation, \"70%\"}]",
+                false)
+        end),
+
+        wait_compaction_started(DbName),
+        wait_compaction_finished(DbName),
+
+        with_config_change(DbName, fun() ->
+            ok = config:delete("compactions", ?b2l(DbName), false)
+        end),
+
+        {DbFrag2, DbFileSize2} = get_db_frag(DbName),
+        {ViewFrag2, ViewFileSize2} = get_view_frag(DbName),
+
+        ?assert(DbFrag2 < 70),
+        ?assert(ViewFrag2 < 70),
+
+        ?assert(DbFileSize > DbFileSize2),
+        ?assert(ViewFileSize > ViewFileSize2),
+
+        ?assert(is_idle(DbName)),
+        ok = couch_db:close(Db)
+    end)}.
+
+
+create_design_doc(Db) ->
+    DDoc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/foo">>},
+        {<<"language">>, <<"javascript">>},
+        {<<"views">>, {[
+            {<<"foo">>, {[
+                {<<"map">>, <<"function(doc) { emit(doc._id, doc); }">>}
+            ]}},
+            {<<"foo2">>, {[
+                {<<"map">>, <<"function(doc) { emit(doc._id, doc); }">>}
+            ]}},
+            {<<"foo3">>, {[
+                {<<"map">>, <<"function(doc) { emit(doc._id, doc); }">>}
+            ]}}
+        ]}}
+    ]}),
+    {ok, _} = couch_db:update_docs(Db, [DDoc]),
+    {ok, _} = couch_db:ensure_full_commit(Db),
+    ok.
+
+populate(DbName, DbFrag, ViewFrag, MinFileSize) ->
+    {CurDbFrag, DbFileSize} = get_db_frag(DbName),
+    {CurViewFrag, ViewFileSize} = get_view_frag(DbName),
+    populate(DbName, DbFrag, ViewFrag, MinFileSize, CurDbFrag, CurViewFrag,
+             lists:min([DbFileSize, ViewFileSize])).
+
+populate(_Db, DbFrag, ViewFrag, MinFileSize, CurDbFrag, CurViewFrag, FileSize)
+    when CurDbFrag >= DbFrag, CurViewFrag >= ViewFrag, FileSize >= MinFileSize ->
+    ok;
+populate(DbName, DbFrag, ViewFrag, MinFileSize, _, _, _) ->
+    update(DbName),
+    {CurDbFrag, DbFileSize} = get_db_frag(DbName),
+    {CurViewFrag, ViewFileSize} = get_view_frag(DbName),
+    populate(DbName, DbFrag, ViewFrag, MinFileSize, CurDbFrag, CurViewFrag,
+             lists:min([DbFileSize, ViewFileSize])).
+
+update(DbName) ->
+    {ok, Db} = couch_db:open_int(DbName, []),
+    lists:foreach(fun(_) ->
+        Doc = couch_doc:from_json_obj({[{<<"_id">>, couch_uuids:new()}]}),
+        {ok, _} = couch_db:update_docs(Db, [Doc]),
+        query_view(Db#db.name)
+    end, lists:seq(1, 200)),
+    couch_db:close(Db).
+
+db_url(DbName) ->
+    Addr = config:get("httpd", "bind_address", "127.0.0.1"),
+    Port = integer_to_list(mochiweb_socket_server:get(couch_httpd, port)),
+    "http://" ++ Addr ++ ":" ++ Port ++ "/" ++ ?b2l(DbName).
+
+query_view(DbName) ->
+    {ok, Code, _Headers, _Body} = test_request:get(
+        db_url(DbName) ++ "/_design/foo/_view/foo"),
+    ?assertEqual(200, Code).
+
+get_db_frag(DbName) ->
+    {ok, Db} = couch_db:open_int(DbName, []),
+    {ok, Info} = couch_db:get_db_info(Db),
+    couch_db:close(Db),
+    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 = 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_started(DbName) ->
+    WaitFun = fun() ->
+        case is_compaction_running(DbName) of
+            false -> wait;
+            true ->  ok
+        end
+    end,
+    case test_util:wait(WaitFun, 10000) of
+        timeout ->
+            erlang:error({assertion_failed,
+                          [{module, ?MODULE},
+                           {line, ?LINE},
+                           {reason, "Compaction starting timeout"}]});
+        _ ->
+            ok
+    end.
+
+wait_compaction_finished(DbName) ->
+    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
+    end.
+
+is_compaction_running(_DbName) ->
+    couch_compaction_daemon:in_progress() /= [].
+
+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).
+
+with_config_change(_DbName, Fun) ->
+    Current = ets:info(couch_compaction_daemon_config, size),
+    Fun(),
+    test_util:wait(fun() ->
+        case ets:info(couch_compaction_daemon_config, size) == Current of
+            false -> ok;
+            true -> wait
+        end
+    end).