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 2015/04/05 01:28:56 UTC

[01/48] couch commit: updated refs/heads/master to 7776921

Repository: couchdb-couch
Updated Branches:
  refs/heads/master b6d8665f4 -> 7776921c6


Return context from test_util:start_couch

We are going to return some context from start_couch so we pass it
around

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

Branch: refs/heads/master
Commit: b510c2187c126681b81ff4d5fff33d3f2d33f5a0
Parents: aa36a18
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 07:23:23 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:27:27 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl                       | 5 ++---
 test/couch_db_tests.erl                 | 4 ++--
 test/couch_util_tests.erl               | 8 ++++----
 test/couchdb_attachments_tests.erl      | 4 ++--
 test/couchdb_compaction_daemon.erl      | 4 ++--
 test/couchdb_cors_tests.erl             | 4 ++--
 test/couchdb_http_proxy_tests.erl       | 4 ++--
 test/couchdb_os_proc_pool.erl           | 4 ++--
 test/couchdb_update_conflicts_tests.erl | 4 ++--
 9 files changed, 20 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b510c218/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index f5cee1c..60fa735 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -88,10 +88,9 @@ start_couch(ExtraApps) ->
 start_couch(IniFiles, ExtraApps) ->
     ok = application:set_env(config, ini_files, IniFiles),
     ok = lager:start(),
-    ok = start_applications([inets, ibrowse, ssl, config, couch] ++ ExtraApps),
+    Ctx = start_applications([inets, ibrowse, ssl, config, couch] ++ ExtraApps),
     couch_stats:reload(),
-    ok.
-
+    Ctx.
 
 stop_couch() ->
     ok = application:stop(couch),

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b510c218/test/couch_db_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_db_tests.erl b/test/couch_db_tests.erl
index 83d6a81..69fc9ef 100644
--- a/test/couch_db_tests.erl
+++ b/test/couch_db_tests.erl
@@ -18,9 +18,9 @@
 
 
 setup() ->
-    ok = test_util:start_couch(),
+    Ctx = test_util:start_couch(),
     config:set("log", "include_sasl", "false", false),
-    ok.
+    Ctx.
 
 
 create_delete_db_test_()->

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b510c218/test/couch_util_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_util_tests.erl b/test/couch_util_tests.erl
index 4c313a2..06fcf7e 100644
--- a/test/couch_util_tests.erl
+++ b/test/couch_util_tests.erl
@@ -23,13 +23,13 @@ setup() ->
     %% On other hand, we cannot unload driver here due to
     %% {error, not_loaded_by_this_process} while it is. Any ideas is welcome.
     %%
-    ok = test_util:start_couch(),
+    Ctx = test_util:start_couch(),
     %% config:start_link(?CONFIG_CHAIN),
     %% {ok, _} = couch_drv:start_link(),
-    ok.
+    Ctx.
 
-teardown(_) ->
-    ok = test_util:stop_couch(),
+teardown(Ctx) ->
+    ok = test_util:stop_couch(Ctx),
     %% config:stop(),
     %% erl_ddll:unload_driver(couch_icu_driver),
     ok.

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b510c218/test/couchdb_attachments_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_attachments_tests.erl b/test/couchdb_attachments_tests.erl
index 71d685a..9a43939 100644
--- a/test/couchdb_attachments_tests.erl
+++ b/test/couchdb_attachments_tests.erl
@@ -29,12 +29,12 @@
 -ifdef(run_broken_tests).
 
 start() ->
-    ok = test_util:start_couch(),
+    Ctx = test_util:start_couch(),
     % ensure in default compression settings for attachments_compression_tests
     config:set("attachments", "compression_level",
                      ?i2l(?COMPRESSION_LEVEL), false),
     config:set("attachments", "compressible_types", "text/*", false),
-    ok.
+    Ctx.
 
 setup() ->
     DbName = ?tempdb(),

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b510c218/test/couchdb_compaction_daemon.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_compaction_daemon.erl b/test/couchdb_compaction_daemon.erl
index b6eee2a..c9e0c38 100644
--- a/test/couchdb_compaction_daemon.erl
+++ b/test/couchdb_compaction_daemon.erl
@@ -23,10 +23,10 @@
 -ifdef(run_broken_tests).
 
 start() ->
-    ok = test_util:start_couch(),
+    Ctx = test_util:start_couch(),
     config:set("compaction_daemon", "check_interval", "3", false),
     config:set("compaction_daemon", "min_file_size", "100000", false),
-    ok.
+    Ctx.
 
 setup() ->
     DbName = ?tempdb(),

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b510c218/test/couchdb_cors_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_cors_tests.erl b/test/couchdb_cors_tests.erl
index 9fd9d58..5d4bc83 100644
--- a/test/couchdb_cors_tests.erl
+++ b/test/couchdb_cors_tests.erl
@@ -22,10 +22,10 @@
 
 
 start() ->
-    ok = test_util:start_couch(),
+    Ctx = test_util:start_couch(),
     ok = config:set("httpd", "enable_cors", "true", false),
     ok = config:set("vhosts", "example.com", "/", false),
-    ok.
+    Ctx.
 
 setup() ->
     DbName = ?tempdb(),

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b510c218/test/couchdb_http_proxy_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_http_proxy_tests.erl b/test/couchdb_http_proxy_tests.erl
index 733494a..7302425 100644
--- a/test/couchdb_http_proxy_tests.erl
+++ b/test/couchdb_http_proxy_tests.erl
@@ -33,12 +33,12 @@ start() ->
     % we have to write any config changes to temp ini file to not loose them
     % when supervisor will kill all children due to reaching restart threshold
     % (each httpd_global_handlers changes causes couch_httpd restart)
-    ok = test_util:start_couch(?CONFIG_CHAIN ++ [?CONFIG_FIXTURE_TEMP], []),
+    Ctx = test_util:start_couch(?CONFIG_CHAIN ++ [?CONFIG_FIXTURE_TEMP], []),
     % 49151 is IANA Reserved, let's assume no one is listening there
     config:set("httpd_global_handlers", "_error",
         "{couch_httpd_proxy, handle_proxy_req, <<\"http://127.0.0.1:49151/\">>}"
     ),
-    ok.
+    Ctx.
 
 setup() ->
     {ok, Pid} = test_web:start_link(),

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b510c218/test/couchdb_os_proc_pool.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_os_proc_pool.erl b/test/couchdb_os_proc_pool.erl
index 7f245e8..afa400b 100644
--- a/test/couchdb_os_proc_pool.erl
+++ b/test/couchdb_os_proc_pool.erl
@@ -21,9 +21,9 @@
 -ifdef(run_broken_tests).
 
 start() ->
-    ok = test_util:start_couch(),
+    Ctx = test_util:start_couch(),
     config:set("query_server_config", "os_process_limit", "3", false),
-    ok.
+    Ctx.
 
 
 os_proc_pool_test_() ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b510c218/test/couchdb_update_conflicts_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_update_conflicts_tests.erl b/test/couchdb_update_conflicts_tests.erl
index b8bb189..3409f83 100644
--- a/test/couchdb_update_conflicts_tests.erl
+++ b/test/couchdb_update_conflicts_tests.erl
@@ -24,9 +24,9 @@
 -ifdef(run_broken_tests).
 
 start() ->
-    ok = test_util:start_couch(),
+    Ctx = test_util:start_couch(),
     config:set("couchdb", "delayed_commits", "true", false),
-    ok.
+    Ctx.
 
 setup() ->
     DbName = ?tempdb(),


[27/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
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 <ii...@ca.ibm.com>
Authored: Tue Feb 3 12:23:36 2015 -0800
Committer: ILYA Khlopotov <ii...@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).


[28/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Define metric [couchdb, httpd_status_codes, 406]

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

Branch: refs/heads/master
Commit: 0b3e8966a41399eefc78858a714a69e45ccf722e
Parents: c51247d
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 3 12:24:22 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:05:38 2015 -0800

----------------------------------------------------------------------
 priv/stats_descriptions.cfg | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/0b3e8966/priv/stats_descriptions.cfg
----------------------------------------------------------------------
diff --git a/priv/stats_descriptions.cfg b/priv/stats_descriptions.cfg
index 8eea746..dad3347 100644
--- a/priv/stats_descriptions.cfg
+++ b/priv/stats_descriptions.cfg
@@ -150,6 +150,10 @@
     {type, counter},
     {desc, <<"number of HTTP 405 Method Not Allowed responses">>}
 ]}.
+{[couchdb, httpd_status_codes, 406], [
+    {type, counter},
+    {desc, <<"number of HTTP 406 Not Acceptable responses">>}
+]}.
 {[couchdb, httpd_status_codes, 409], [
     {type, counter},
     {desc, <<"number of HTTP 409 Conflict responses">>}


[13/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Implement test_util:stop_applications/1

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

Branch: refs/heads/master
Commit: 74f539a3cfd6f35f40aedc84b701ec5caaf3d749
Parents: b5d8e09
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 10 10:45:42 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:45:42 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/74f539a3/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index 0fbf1de..0b96095 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -20,7 +20,7 @@
 
 -export([start_couch/0, start_couch/1, start_couch/2, stop_couch/0, stop_couch/1]).
 -export([start_config/1, stop_config/1]).
--export([start_applications/1]).
+-export([start_applications/1, stop_applications/1]).
 
 -export([stop_sync/1, stop_sync/2, stop_sync/3]).
 
@@ -69,16 +69,9 @@ start_couch(IniFiles, ExtraApps) ->
     Ctx.
 
 stop_couch() ->
-    ok = application:stop(couch),
-    ok = application:stop(lager),
-    ok = application:stop(goldrush),
-    ok = application:stop(config),
-    ok = application:stop(ssl),
-    ok = application:stop(ibrowse),
-    ok = application:stop(inets),
+    ok = stop_applications([inets, ibrowse, ssl, config, goldrush, lager, couch]),
     ok.
 
-
 stop_couch(_) ->
     stop_couch().
 
@@ -100,6 +93,10 @@ start_applications([App|Apps], Acc) ->
             start_applications(Apps, [App|Acc])
     end.
 
+stop_applications(Apps) ->
+    [application:stop(App) || App <- lists:reverse(Apps)],
+    ok.
+
 start_config(Chain) ->
     case config:start_link(Chain) of
         {ok, Pid} ->


[05/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Use test_util:stop_sync in test_util:stop_config

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

Branch: refs/heads/master
Commit: f66255f83975128c6fdf33e043e2418772165c36
Parents: cacca04
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 08:46:27 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:37:42 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f66255f8/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index 219cf6b..1ac9794 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -108,13 +108,11 @@ start_config(Chain) ->
 
 stop_config(Pid) ->
     Timeout = 1000,
-    erlang:monitor(process, Pid),
-    config:stop(),
-    receive
-        {'DOWN', _, _, Pid, _} ->
+    case stop_sync(Pid, fun() -> config:stop() end, Timeout) of
+        timeout ->
+            throw({timeout_error, config_stop});
+        _Else ->
             ok
-    after Timeout ->
-        throw({timeout_error, config_stop})
     end.
 
 stop_sync(Name) ->


[14/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Add test_util:start/stop for minimal setup

The idea is to use test_util:start to setup minimal environment which
starts or mocks necessary dependencies. test_util:start returns
`#test_context{}` to be passed to test_util:stop/1.

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

Branch: refs/heads/master
Commit: 9e76a39369fcd1405d7f4b3b0da025a08cb5b2e0
Parents: 74f539a
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 13:38:40 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:46:59 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9e76a393/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index 0b96095..a4ab007 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -29,6 +29,10 @@
 -export([with_process_restart/1, with_process_restart/2, with_process_restart/3]).
 -export([wait_process/1, wait_process/2]).
 
+-export([start/1, start/2, start/3, stop/1]).
+
+-record(test_context, {mocked = [], started = [], module}).
+
 srcdir() ->
     code:priv_dir(couch) ++ "/../../".
 
@@ -189,6 +193,39 @@ wait_process(Name, Timeout, Started, _Prev) ->
         Pid
     end.
 
+start(Module) ->
+    start(Module, [], []).
+
+start(Module, ExtraApps) ->
+    start(Module, ExtraApps, []).
+
+start(Module, ExtraApps, Options) ->
+    Apps = start_applications([config, ioq|ExtraApps]),
+    ToMock = [config, couch_stats] -- proplists:get_value(dont_mock, Options, []),
+    mock(ToMock),
+    #test_context{module = Module, mocked = ToMock, started = Apps}.
+
+stop(#test_context{mocked = Mocked, started = Apps}) ->
+    meck:unload(Mocked),
+    stop_applications(Apps).
+
 now_us() ->
     {MegaSecs, Secs, MicroSecs} = now(),
     (MegaSecs * 1000000 + Secs) * 1000000 + MicroSecs.
+
+mock(Modules) when is_list(Modules) ->
+    [mock(Module) || Module <- Modules];
+mock(config) ->
+    meck:new(config, [passthrough]),
+    meck:expect(config, get, fun(_, _) -> undefined end),
+    meck:expect(config, get, fun(_, _, Default) -> Default end),
+    ok;
+mock(couch_stats) ->
+    meck:new(couch_stats, [passthrough]),
+    meck:expect(couch_stats, increment_counter, fun(_) -> ok end),
+    meck:expect(couch_stats, increment_counter, fun(_, _) -> ok end),
+    meck:expect(couch_stats, decrement_counter, fun(_) -> ok end),
+    meck:expect(couch_stats, decrement_counter, fun(_, _) -> ok end),
+    meck:expect(couch_stats, update_histogram, fun(_, _) -> ok end),
+    meck:expect(couch_stats, update_gauge, fun(_, _) -> ok end),
+    ok.


[15/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Use test_util:start in couch_file_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/72c313da
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/72c313da
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/72c313da

Branch: refs/heads/master
Commit: 72c313daea250998d577821e36f6f003761d00a1
Parents: 9e76a39
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 13:43:01 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:47:14 2015 -0800

----------------------------------------------------------------------
 test/couch_file_tests.erl | 81 ++++++++++++++++++++++++------------------
 1 file changed, 46 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/72c313da/test/couch_file_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_file_tests.erl b/test/couch_file_tests.erl
index 9b167ca..4d0bbac 100644
--- a/test/couch_file_tests.erl
+++ b/test/couch_file_tests.erl
@@ -26,17 +26,20 @@ setup() ->
 teardown(Fd) ->
     ok = couch_file:close(Fd).
 
-
 open_close_test_() ->
     {
         "Test for proper file open and close",
-        [
-            should_return_enoent_if_missed(),
-            should_ignore_invalid_flags_with_open(),
-            ?setup(fun should_return_pid_on_file_open/1),
-            should_close_file_properly(),
-            ?setup(fun should_create_empty_new_files/1)
-        ]
+        {
+            setup,
+            fun() -> test_util:start(?MODULE, [ioq]) end, fun test_util:stop/1,
+            [
+                should_return_enoent_if_missed(),
+                should_ignore_invalid_flags_with_open(),
+                ?setup(fun should_return_pid_on_file_open/1),
+                should_close_file_properly(),
+                ?setup(fun should_create_empty_new_files/1)
+            ]
+        }
     }.
 
 should_return_enoent_if_missed() ->
@@ -61,19 +64,23 @@ should_create_empty_new_files(Fd) ->
 read_write_test_() ->
     {
         "Common file read/write tests",
-        ?foreach([
-            fun should_increase_file_size_on_write/1,
-            fun should_return_current_file_size_on_write/1,
-            fun should_write_and_read_term/1,
-            fun should_write_and_read_binary/1,
-            fun should_write_and_read_large_binary/1,
-            fun should_return_term_as_binary_for_reading_binary/1,
-            fun should_read_term_written_as_binary/1,
-            fun should_read_iolist/1,
-            fun should_fsync/1,
-            fun should_not_read_beyond_eof/1,
-            fun should_truncate/1
-        ])
+        {
+            setup,
+            fun() -> test_util:start(?MODULE, [ioq]) end, fun test_util:stop/1,
+            ?foreach([
+                fun should_increase_file_size_on_write/1,
+                fun should_return_current_file_size_on_write/1,
+                fun should_write_and_read_term/1,
+                fun should_write_and_read_binary/1,
+                fun should_write_and_read_large_binary/1,
+                fun should_return_term_as_binary_for_reading_binary/1,
+                fun should_read_term_written_as_binary/1,
+                fun should_read_iolist/1,
+                fun should_fsync/1,
+                fun should_not_read_beyond_eof/1,
+                fun should_truncate/1
+            ])
+        }
     }.
 
 
@@ -134,20 +141,24 @@ should_truncate(Fd) ->
 header_test_() ->
     {
         "File header read/write tests",
-        [
-            ?foreach([
-                fun should_write_and_read_atom_header/1,
-                fun should_write_and_read_tuple_header/1,
-                fun should_write_and_read_second_header/1,
-                fun should_truncate_second_header/1,
-                fun should_produce_same_file_size_on_rewrite/1,
-                fun should_save_headers_larger_than_block_size/1
-            ]),
-            should_recover_header_marker_corruption(),
-            should_recover_header_size_corruption(),
-            should_recover_header_md5sig_corruption(),
-            should_recover_header_data_corruption()
-        ]
+        {
+            setup,
+            fun() -> test_util:start(?MODULE, [ioq]) end, fun test_util:stop/1,
+            [
+                ?foreach([
+                    fun should_write_and_read_atom_header/1,
+                    fun should_write_and_read_tuple_header/1,
+                    fun should_write_and_read_second_header/1,
+                    fun should_truncate_second_header/1,
+                    fun should_produce_same_file_size_on_rewrite/1,
+                    fun should_save_headers_larger_than_block_size/1
+                ]),
+                should_recover_header_marker_corruption(),
+                should_recover_header_size_corruption(),
+                should_recover_header_md5sig_corruption(),
+                should_recover_header_data_corruption()
+            ]
+        }
     }.
 
 


[07/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Use test_util:stop_sync_throw in 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/cd6aed00
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/cd6aed00
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/cd6aed00

Branch: refs/heads/master
Commit: cd6aed00d5ec09e98de703e8586571d3b05fbed5
Parents: fa159b1
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 10:17:56 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:39:34 2015 -0800

----------------------------------------------------------------------
 test/couch_stats_tests.erl        | 18 ++++--------------
 test/couch_task_status_tests.erl  | 12 +++---------
 test/couch_work_queue_tests.erl   | 11 +++--------
 test/couchdb_http_proxy_tests.erl | 12 +++---------
 test/couchdb_os_daemons_tests.erl | 11 +++--------
 5 files changed, 16 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/cd6aed00/test/couch_stats_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_stats_tests.erl b/test/couch_stats_tests.erl
index fd4c8e1..2175f07 100644
--- a/test/couch_stats_tests.erl
+++ b/test/couch_stats_tests.erl
@@ -171,13 +171,8 @@ should_decrement_counter_on_process_exit() ->
         begin
             {Pid, 1} = spawn_and_count(1),
             spawn_and_count(2),
-            RefMon = erlang:monitor(process, Pid),
-            Pid ! sepuku,
-            receive
-                {'DOWN', RefMon, _, _, _} -> ok
-            after ?TIMEOUT ->
-                throw(timeout)
-            end,
+            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),
@@ -189,13 +184,8 @@ should_decrement_for_each_track_process_count_call_on_exit() ->
         begin
             {_, 2} = spawn_and_count(2),
             {Pid, 6} = spawn_and_count(4),
-            RefMon = erlang:monitor(process, Pid),
-            Pid ! sepuku,
-            receive
-                {'DOWN', RefMon, _, _, _} -> ok
-            after ?TIMEOUT ->
-                throw(timeout)
-            end,
+            test_util:stop_sync_throw(Pid,
+                fun() -> Pid ! sepuku end, timeout, ?TIMEOUT),
             timer:sleep(?TIMEWAIT),
             couch_stats_collector:get(hoopla)
         end).

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/cd6aed00/test/couch_task_status_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_task_status_tests.erl b/test/couch_task_status_tests.erl
index 465b6b9..76196f1 100644
--- a/test/couch_task_status_tests.erl
+++ b/test/couch_task_status_tests.erl
@@ -24,15 +24,9 @@ setup() ->
     {TaskStatusPid, TaskUpdaterPid}.
 
 teardown({TaskStatusPid, _}) ->
-    erlang:monitor(process, TaskStatusPid),
-    couch_task_status:stop(),
-    receive
-        {'DOWN', _, _, TaskStatusPid, _} ->
-            ok
-    after ?TIMEOUT ->
-        throw(timeout_error)
-    end.
-
+    test_util:stop_sync_throw(TaskStatusPid, fun() ->
+        couch_task_status:stop()
+    end, timeout_error, ?TIMEOUT).
 
 couch_task_status_test_() ->
     {

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/cd6aed00/test/couch_work_queue_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_work_queue_tests.erl b/test/couch_work_queue_tests.erl
index c94dc00..86ea1b9 100644
--- a/test/couch_work_queue_tests.erl
+++ b/test/couch_work_queue_tests.erl
@@ -300,14 +300,9 @@ should_be_closed({Q, _, Consumer}) ->
 
 
 close_queue(Q) ->
-    ok = couch_work_queue:close(Q),
-    MonRef = erlang:monitor(process, Q),
-    receive
-        {'DOWN', MonRef, process, Q, _Reason} -> ok
-    after ?TIMEOUT ->
-        erlang:demonitor(MonRef),
-        timeout
-    end.
+    test_util:stop_sync(Q, fun() ->
+        ok = couch_work_queue:close(Q)
+    end, ?TIMEOUT).
 
 spawn_consumer(Q) ->
     Parent = self(),

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/cd6aed00/test/couchdb_http_proxy_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_http_proxy_tests.erl b/test/couchdb_http_proxy_tests.erl
index 7302425..9b640da 100644
--- a/test/couchdb_http_proxy_tests.erl
+++ b/test/couchdb_http_proxy_tests.erl
@@ -51,15 +51,9 @@ setup() ->
     Pid.
 
 teardown(Pid) ->
-    erlang:monitor(process, Pid),
-    test_web:stop(),
-    receive
-        {'DOWN', _, _, Pid, _} ->
-            ok
-    after ?TIMEOUT ->
-        throw({timeout, test_web_stop})
-    end.
-
+    test_util:stop_sync_throw(Pid, fun() ->
+        test_web:stop()
+    end, {timeout, test_web_stop}, ?TIMEOUT).
 
 http_proxy_test_() ->
     {

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/cd6aed00/test/couchdb_os_daemons_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_os_daemons_tests.erl b/test/couchdb_os_daemons_tests.erl
index 6aea39c..0b6383e 100644
--- a/test/couchdb_os_daemons_tests.erl
+++ b/test/couchdb_os_daemons_tests.erl
@@ -56,14 +56,9 @@ teardown(_, {CfgPid, OsDPid}) ->
         throw({timeout, config_stop})
     end,
 
-    erlang:monitor(process, OsDPid),
-    exit(OsDPid, normal),
-    receive
-        {'DOWN', _, _, OsDPid, _} ->
-            ok
-    after ?TIMEOUT ->
-        throw({timeout, os_daemon_stop})
-    end.
+    test_util:stop_sync_throw(OsPid, fun() ->
+        exit(OsDPid, normal)
+    end, {timeout, os_daemon_stop}, ?TIMEOUT).
 
 
 os_daemons_test_() ->


[48/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Merge remote-tracking branch 'iilyak/2547-fix-broken-tests'

This closes #35

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

Branch: refs/heads/master
Commit: 7776921c651f091259adbf0addb0779fed381dcc
Parents: b6d8665 17fa585
Author: Alexander Shorin <kx...@apache.org>
Authored: Sat Apr 4 18:06:50 2015 +0300
Committer: Alexander Shorin <kx...@apache.org>
Committed: Sat Apr 4 18:06:50 2015 +0300

----------------------------------------------------------------------
 include/couch_eunit.hrl                  |   6 +
 priv/stats_descriptions.cfg              |   4 +
 src/couch.app.src                        |   1 +
 src/couch_auth_cache.erl                 |  18 +-
 src/couch_compaction_daemon.erl          |  23 +-
 src/couch_db.erl                         |  19 +-
 src/couch_doc.erl                        |  21 +-
 src/couch_proc_manager.erl               |  12 +-
 src/couch_sup.erl                        |   2 +-
 src/test_util.erl                        | 244 ++++++++++++++++------
 test/couch_auth_cache_tests.erl          |  33 ++-
 test/couch_btree_tests.erl               |  94 +++++----
 test/couch_changes_tests.erl             |  41 ++--
 test/couch_db_tests.erl                  |   4 +-
 test/couch_doc_json_tests.erl            | 108 +++++-----
 test/couch_file_tests.erl                |  81 ++++----
 test/couch_key_tree_tests.erl            | 166 ++++++++-------
 test/couch_stats_tests.erl               |  28 +--
 test/couch_stream_tests.erl              |  32 +--
 test/couch_task_status_tests.erl         |  32 ++-
 test/couch_util_tests.erl                |   8 +-
 test/couch_uuids_tests.erl               |  22 +-
 test/couch_work_queue_tests.erl          |  73 ++++---
 test/couchdb_attachments_tests.erl       |  42 ++--
 test/couchdb_compaction_daemon.erl       | 121 +++++++----
 test/couchdb_cors_tests.erl              |   4 +-
 test/couchdb_file_compression_tests.erl  |  74 ++++---
 test/couchdb_http_proxy_tests.erl        |  35 ++--
 test/couchdb_modules_load_tests.erl      |  62 ------
 test/couchdb_os_daemons_tests.erl        |  33 +--
 test/couchdb_os_proc_pool.erl            |  33 +--
 test/couchdb_update_conflicts_tests.erl  |  13 +-
 test/couchdb_vhosts_tests.erl            |  43 ++--
 test/couchdb_views_tests.erl             | 288 ++++++++++++++------------
 test/fixtures/os_daemon_configer.escript |  13 +-
 35 files changed, 1012 insertions(+), 821 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/7776921c/test/couch_util_tests.erl
----------------------------------------------------------------------


[32/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Assign waiter on return_proc in couch_proc_manager

There is a case when we return_proc while waiters exist. We should
assign returned proc to one of them. Effectively we unfreeze the waiter.

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

Branch: refs/heads/master
Commit: 80f8330a8dd99c29f0bcc8d2d776ee04a54815b9
Parents: b59a4b2
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed Feb 4 13:25:45 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:06:44 2015 -0800

----------------------------------------------------------------------
 src/couch_proc_manager.erl | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/80f8330a/src/couch_proc_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_proc_manager.erl b/src/couch_proc_manager.erl
index f0fc6fa..20514cc 100644
--- a/src/couch_proc_manager.erl
+++ b/src/couch_proc_manager.erl
@@ -449,13 +449,23 @@ return_proc(#state{} = State, #proc_int{} = ProcInt) ->
                 true = ets:update_element(?PROCS, Pid, [
                     {#proc_int.client, undefined}
                 ]),
-                State
+                maybe_assign_proc(State, ProcInt)
         end;
     false ->
         remove_proc(State, ProcInt)
     end,
     flush_waiters(NewState, Lang).
 
+maybe_assign_proc(#state{} = State, ProcInt) ->
+    #proc_int{pid = Pid, lang = Lang} = ProcInt,
+    case get_waiting_client(Lang) of
+        #client{from = From} = Client ->
+            Proc = assign_proc(Client, ProcInt#proc_int{client=undefined}),
+            gen_server:reply(From, {ok, Proc, State#state.config}),
+            State;
+        undefined ->
+            State
+    end.
 
 remove_proc(State, #proc_int{}=Proc) ->
     ets:delete(?PROCS, Proc#proc_int.pid),


[08/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Use shutdown reason instead of normal for exit/2

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

Branch: refs/heads/master
Commit: bc1963fa0337843aa45832f76a9c5dafdbd4d05c
Parents: cd6aed0
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 10:19:36 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:39:54 2015 -0800

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/bc1963fa/test/couchdb_os_daemons_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_os_daemons_tests.erl b/test/couchdb_os_daemons_tests.erl
index 0b6383e..f788e25 100644
--- a/test/couchdb_os_daemons_tests.erl
+++ b/test/couchdb_os_daemons_tests.erl
@@ -57,7 +57,7 @@ teardown(_, {CfgPid, OsDPid}) ->
     end,
 
     test_util:stop_sync_throw(OsPid, fun() ->
-        exit(OsDPid, normal)
+        exit(OsDPid, shutdown)
     end, {timeout, os_daemon_stop}, ?TIMEOUT).
 
 


[25/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable couchdb_attachments_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/5e95b1a4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/5e95b1a4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/5e95b1a4

Branch: refs/heads/master
Commit: 5e95b1a4cafd8e807467b5a1ce8947c5e79352ff
Parents: c2d3d45
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 3 09:39:53 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:04:44 2015 -0800

----------------------------------------------------------------------
 include/couch_eunit.hrl            |  5 +++++
 test/couchdb_attachments_tests.erl | 18 +++++++-----------
 2 files changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/5e95b1a4/include/couch_eunit.hrl
----------------------------------------------------------------------
diff --git a/include/couch_eunit.hrl b/include/couch_eunit.hrl
index 41957e8..c48442a 100644
--- a/include/couch_eunit.hrl
+++ b/include/couch_eunit.hrl
@@ -31,6 +31,11 @@
     filename:join([?BUILDDIR(), "src", "couch", "test", "fixtures"])).
 -define(TEMPDIR,
     filename:join([?BUILDDIR(), "tmp", "tmp_data"])).
+-define(ABS_PATH(File),
+    filename:join([
+        filename:dirname(
+            filename:dirname(
+                filename:dirname(filename:absname(File)))), File])).
 
 -define(tempfile,
     fun() ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/5e95b1a4/test/couchdb_attachments_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_attachments_tests.erl b/test/couchdb_attachments_tests.erl
index 083efc7..4822987 100644
--- a/test/couchdb_attachments_tests.erl
+++ b/test/couchdb_attachments_tests.erl
@@ -19,15 +19,13 @@
 -define(ATT_BIN_NAME, <<"logo.png">>).
 -define(ATT_TXT_NAME, <<"file.erl">>).
 -define(FIXTURE_PNG, filename:join([?FIXTURESDIR, "logo.png"])).
--define(FIXTURE_TXT, ?FILE).
+-define(FIXTURE_TXT, ?ABS_PATH(?FILE)).
 -define(TIMEOUT, 1000).
 -define(TIMEOUT_EUNIT, 10).
 -define(TIMEWAIT, 100).
 -define(i2l(I), integer_to_list(I)).
 
 
--ifdef(run_broken_tests).
-
 start() ->
     Ctx = test_util:start_couch(),
     % ensure in default compression settings for attachments_compression_tests
@@ -191,7 +189,7 @@ should_upload_attachment_by_chunks_without_md5({Host, DbName}) ->
         AttUrl = string:join(["", DbName, ?docid(), "readme.txt"], "/"),
         AttData = <<"We all live in a yellow submarine!">>,
         <<Part1:21/binary, Part2:13/binary>> = AttData,
-        Body = chunked_body([Part1, Part2]),
+        Body = [chunked_body([Part1, Part2]), "\r\n"],
         Headers = [
             {"Content-Type", "text/plain"},
             {"Transfer-Encoding", "chunked"},
@@ -222,7 +220,7 @@ should_upload_attachment_by_chunks_with_valid_md5_header({Host, DbName}) ->
         AttUrl = string:join(["", DbName, ?docid(), "readme.txt"], "/"),
         AttData = <<"We all live in a yellow submarine!">>,
         <<Part1:21/binary, Part2:13/binary>> = AttData,
-        Body = chunked_body([Part1, Part2]),
+        Body = [chunked_body([Part1, Part2]), "\r\n"],
         Headers = [
             {"Content-Type", "text/plain"},
             {"Content-MD5", ?b2l(base64:encode(couch_util:md5(AttData)))},
@@ -241,7 +239,7 @@ should_upload_attachment_by_chunks_with_valid_md5_trailer({Host, DbName}) ->
         <<Part1:21/binary, Part2:13/binary>> = AttData,
         Body = [chunked_body([Part1, Part2]),
                 "Content-MD5: ", base64:encode(couch_util:md5(AttData)),
-                "\r\n"],
+                "\r\n\r\n"],
         Headers = [
             {"Content-Type", "text/plain"},
             {"Host", Host},
@@ -275,7 +273,7 @@ should_reject_chunked_attachment_with_invalid_md5({Host, DbName}) ->
         AttUrl = string:join(["", DbName, ?docid(), "readme.txt"], "/"),
         AttData = <<"We all live in a yellow submarine!">>,
         <<Part1:21/binary, Part2:13/binary>> = AttData,
-        Body = chunked_body([Part1, Part2]),
+        Body = [chunked_body([Part1, Part2]), "\r\n"],
         Headers = [
             {"Content-Type", "text/plain"},
             {"Content-MD5", ?b2l(base64:encode(<<"foobar!">>))},
@@ -295,7 +293,7 @@ should_reject_chunked_attachment_with_invalid_md5_trailer({Host, DbName}) ->
         <<Part1:21/binary, Part2:13/binary>> = AttData,
         Body = [chunked_body([Part1, Part2]),
                 "Content-MD5: ", base64:encode(<<"foobar!">>),
-                "\r\n"],
+                "\r\n\r\n"],
         Headers = [
             {"Content-Type", "text/plain"},
             {"Host", Host},
@@ -556,7 +554,7 @@ request(Method, Url, Headers, Body) ->
     RequestHead = [Method, " ", Url, " HTTP/1.1"],
     RequestHeaders = [[string:join([Key, Value], ": "), "\r\n"]
                       || {Key, Value} <- Headers],
-    Request = [RequestHead, "\r\n", RequestHeaders, "\r\n", Body, "\r\n"],
+    Request = [RequestHead, "\r\n", RequestHeaders, "\r\n", Body],
     Sock = get_socket(),
     gen_tcp:send(Sock, list_to_binary(lists:flatten(Request))),
     timer:sleep(?TIMEWAIT),  % must wait to receive complete response
@@ -633,5 +631,3 @@ gzip(Data) ->
     ok = zlib:deflateEnd(Z),
     ok = zlib:close(Z),
     Last.
-
--endif.


[18/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Remove obsolete modules_loaded_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/7d498600
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/7d498600
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/7d498600

Branch: refs/heads/master
Commit: 7d4986008bd7c7e81cb91c33ed5a41f7eb98d21b
Parents: 061c530
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Feb 2 07:00:30 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:03:34 2015 -0800

----------------------------------------------------------------------
 test/couchdb_modules_load_tests.erl | 62 --------------------------------
 1 file changed, 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/7d498600/test/couchdb_modules_load_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_modules_load_tests.erl b/test/couchdb_modules_load_tests.erl
deleted file mode 100644
index 331b22b..0000000
--- a/test/couchdb_modules_load_tests.erl
+++ /dev/null
@@ -1,62 +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_modules_load_tests).
-
--include("couch_eunit.hrl").
-
-
-modules_load_test_() ->
-    {
-        "Verify that all modules loads",
-        should_load_modules()
-    }.
-
-
-should_load_modules() ->
-    Modules = [
-        couch_auth_cache,
-        couch_btree,
-        couch_changes,
-        couch_compress,
-        config,
-        config_writer,
-        couch_db,
-        couch_db_updater,
-        couch_doc,
-        % Fails unless couch_config gen_server is started.
-        % couch_ejson_compare,
-        couch_event_sup,
-        couch_external_manager,
-        couch_external_server,
-        couch_file,
-        couch_httpd,
-        couch_httpd_db,
-        couch_httpd_external,
-        couch_httpd_misc_handlers,
-        couch_httpd_rewrite,
-        couch_key_tree,
-        couch_log,
-        couch_os_process,
-        couch_query_servers,
-        couch_server,
-        couch_sup,
-        couch_stream,
-        couch_task_status,
-        couch_util,
-        couch_work_queue,
-        json_stream_parse
-    ],
-    [should_load_module(Mod) || Mod <- Modules].
-
-should_load_module(Mod) ->
-    {atom_to_list(Mod), ?_assertMatch({module, _}, code:load_file(Mod))}.


[39/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable couch_changes_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/2f51245e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/2f51245e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/2f51245e

Branch: refs/heads/master
Commit: 2f51245e7cc69a69c3f77d81c3675ed01e9a2271
Parents: ca6607a
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 10 08:46:23 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:07:36 2015 -0800

----------------------------------------------------------------------
 test/couch_changes_tests.erl | 43 +++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2f51245e/test/couch_changes_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_changes_tests.erl b/test/couch_changes_tests.erl
index 7c5d487..315b8dc 100644
--- a/test/couch_changes_tests.erl
+++ b/test/couch_changes_tests.erl
@@ -24,9 +24,6 @@
     deleted = false
 }).
 
-
--ifdef(run_broken_tests).
-
 setup() ->
     DbName = ?tempdb(),
     {ok, Db} = create_db(DbName),
@@ -38,13 +35,18 @@ setup() ->
         save_doc(Db, {[{<<"_id">>, <<"doc5">>}]})
     ]],
     Rev = lists:nth(3, Revs),
-    {ok, Rev1} = save_doc(Db, {[{<<"_id">>, <<"doc3">>}, {<<"_rev">>, Rev}]}),
+    couch_db:ensure_full_commit(Db),
+    {ok, Db1} = couch_db:reopen(Db),
+
+    Doc = couch_db:open_doc(Db1, <<"doc3">>),
+
+    {ok, Rev1} = save_doc(Db1, {[{<<"_id">>, <<"doc3">>}, {<<"_rev">>, Rev}]}),
     Revs1 = Revs ++ [Rev1],
     Revs2 = Revs1 ++ [R || {ok, R} <- [
-        save_doc(Db, {[{<<"_id">>, <<"doc6">>}]}),
-        save_doc(Db, {[{<<"_id">>, <<"_design/foo">>}]}),
-        save_doc(Db, {[{<<"_id">>, <<"doc7">>}]}),
-        save_doc(Db, {[{<<"_id">>, <<"doc8">>}]})
+        save_doc(Db1, {[{<<"_id">>, <<"doc6">>}]}),
+        save_doc(Db1, {[{<<"_id">>, <<"_design/foo">>}]}),
+        save_doc(Db1, {[{<<"_id">>, <<"doc7">>}]}),
+        save_doc(Db1, {[{<<"_id">>, <<"doc8">>}]})
     ]],
     {DbName, list_to_tuple(Revs2)}.
 
@@ -258,7 +260,7 @@ should_filter_continuous_feed_by_specific_doc_ids({DbName, Revs}) ->
             DocIds = [<<"doc3">>, <<"doc4">>, <<"doc9999">>],
             Req = {json_req, {[{<<"doc_ids">>, DocIds}]}},
             Consumer = spawn_consumer(DbName, ChangesArgs, Req),
-            pause(Consumer),
+            ok = pause(Consumer),
 
             Rows = get_rows(Consumer),
             ?assertEqual(2, length(Rows)),
@@ -271,8 +273,9 @@ should_filter_continuous_feed_by_specific_doc_ids({DbName, Revs}) ->
             clear_rows(Consumer),
             {ok, _Rev9} = save_doc(Db, {[{<<"_id">>, <<"doc9">>}]}),
             {ok, _Rev10} = save_doc(Db, {[{<<"_id">>, <<"doc10">>}]}),
-            unpause(Consumer),
-            pause(Consumer),
+            ok = unpause(Consumer),
+            timer:sleep(100),
+            ok = pause(Consumer),
             ?assertEqual([], get_rows(Consumer)),
 
             Rev4 = element(4, Revs),
@@ -285,8 +288,9 @@ should_filter_continuous_feed_by_specific_doc_ids({DbName, Revs}) ->
             {ok, _} = save_doc(Db, {[{<<"_id">>, <<"doc12">>}]}),
             {ok, Rev3_3} = save_doc(Db, {[{<<"_id">>, <<"doc3">>},
                                           {<<"_rev">>, Rev3_2}]}),
-            unpause(Consumer),
-            pause(Consumer),
+            ok = unpause(Consumer),
+            timer:sleep(100),
+            ok = pause(Consumer),
 
             NewRows = get_rows(Consumer),
             ?assertEqual(2, length(NewRows)),
@@ -299,12 +303,13 @@ should_filter_continuous_feed_by_specific_doc_ids({DbName, Revs}) ->
             clear_rows(Consumer),
             {ok, _Rev3_4} = save_doc(Db, {[{<<"_id">>, <<"doc3">>},
                                            {<<"_rev">>, Rev3_3}]}),
-            unpause(Consumer),
-            pause(Consumer),
+            ok = unpause(Consumer),
+            timer:sleep(100),
+            ok = pause(Consumer),
 
             FinalRows = get_rows(Consumer),
 
-            unpause(Consumer),
+            ok = unpause(Consumer),
             stop_consumer(Consumer),
 
             ?assertMatch([#row{seq = 18, id = <<"doc3">>}], FinalRows)
@@ -530,7 +535,7 @@ spawn_consumer(DbName, ChangesArgs0, Req) ->
             false ->
                 ChangesArgs0
         end,
-        FeedFun = couch_changes:handle_changes(ChangesArgs, Req, Db),
+        FeedFun = couch_changes:handle_db_changes(ChangesArgs, Req, Db),
         try
             FeedFun({Callback, []})
         catch throw:{stop, _} ->
@@ -556,7 +561,7 @@ maybe_pause(Parent, Acc) ->
         {stop, Ref} ->
             Parent ! {ok, Ref},
             throw({stop, Acc});
-        V ->
+        V when V /= updated ->
             erlang:error({assertion_failed,
                       [{module, ?MODULE},
                        {line, ?LINE},
@@ -597,5 +602,3 @@ create_db(DbName) ->
 
 delete_db(DbName) ->
     ok = couch_server:delete(DbName, [?ADMIN_CTX]).
-
--endif.


[43/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Comment out test case for disabled functionality

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

Branch: refs/heads/master
Commit: c448b142e0f02660862d856f4bcd8cc243e8168b
Parents: b41d8ba
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Feb 19 10:05:21 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Thu Feb 19 10:05:21 2015 -0800

----------------------------------------------------------------------
 src/couch_auth_cache.erl         |  2 +-
 src/couch_proc_manager.erl       |  2 +-
 src/test_util.erl                | 19 +++++++++----------
 test/couch_changes_tests.erl     |  2 --
 test/couch_task_status_tests.erl | 20 ++++++++++----------
 5 files changed, 21 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/c448b142/src/couch_auth_cache.erl
----------------------------------------------------------------------
diff --git a/src/couch_auth_cache.erl b/src/couch_auth_cache.erl
index a8fdab8..c936535 100644
--- a/src/couch_auth_cache.erl
+++ b/src/couch_auth_cache.erl
@@ -232,7 +232,7 @@ handle_info(restart_event_listener, State) ->
             ?MODULE, handle_db_event, nil, [{dbname, AuthDbName}]
         ),
     {noreply, State#state{event_listener=NewListener}};
-handle_info({'DOWN', Ref, _, _, shutdown}, State) ->
+handle_info({'DOWN', _Ref, _, _, shutdown}, State) ->
     {stop, shutdown, State};
 handle_info({'DOWN', Ref, _, _, _Reason}, #state{db_mon_ref = Ref} = State) ->
     {noreply, reinit_cache(State)};

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/c448b142/src/couch_proc_manager.erl
----------------------------------------------------------------------
diff --git a/src/couch_proc_manager.erl b/src/couch_proc_manager.erl
index 20514cc..b3ca69a 100644
--- a/src/couch_proc_manager.erl
+++ b/src/couch_proc_manager.erl
@@ -457,7 +457,7 @@ return_proc(#state{} = State, #proc_int{} = ProcInt) ->
     flush_waiters(NewState, Lang).
 
 maybe_assign_proc(#state{} = State, ProcInt) ->
-    #proc_int{pid = Pid, lang = Lang} = ProcInt,
+    #proc_int{lang = Lang} = ProcInt,
     case get_waiting_client(Lang) of
         #client{from = From} = Client ->
             Proc = assign_proc(Client, ProcInt#proc_int{client=undefined}),

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/c448b142/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index 829fc36..f0ef82a 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -92,16 +92,15 @@ start_applications(Apps) ->
 start_applications([], Acc) ->
     lists:reverse(Acc);
 start_applications([App|Apps], Acc) ->
-    NewAcc =
-        case application:start(App) of
-        {error, {already_started, _}} ->
-            start_applications(Apps, Acc);
-        {error, {not_started, Dep}} ->
-            start_applications([Dep, App | Apps], Acc);
-        {error, {not_running, Dep}} ->
-            start_applications([Dep, App | Apps], Acc);
-        ok ->
-            start_applications(Apps, [App|Acc])
+    case application:start(App) of
+    {error, {already_started, _}} ->
+        start_applications(Apps, Acc);
+    {error, {not_started, Dep}} ->
+        start_applications([Dep, App | Apps], Acc);
+    {error, {not_running, Dep}} ->
+        start_applications([Dep, App | Apps], Acc);
+    ok ->
+        start_applications(Apps, [App|Acc])
     end.
 
 stop_applications(Apps) ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/c448b142/test/couch_changes_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_changes_tests.erl b/test/couch_changes_tests.erl
index 315b8dc..589cccc 100644
--- a/test/couch_changes_tests.erl
+++ b/test/couch_changes_tests.erl
@@ -38,8 +38,6 @@ setup() ->
     couch_db:ensure_full_commit(Db),
     {ok, Db1} = couch_db:reopen(Db),
 
-    Doc = couch_db:open_doc(Db1, <<"doc3">>),
-
     {ok, Rev1} = save_doc(Db1, {[{<<"_id">>, <<"doc3">>}, {<<"_rev">>, Rev}]}),
     Revs1 = Revs ++ [Rev1],
     Revs2 = Revs1 ++ [R || {ok, R} <- [

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/c448b142/test/couch_task_status_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_task_status_tests.erl b/test/couch_task_status_tests.erl
index 76196f1..f97a376 100644
--- a/test/couch_task_status_tests.erl
+++ b/test/couch_task_status_tests.erl
@@ -93,16 +93,16 @@ should_update_time_changes_on_task_progress({_, Pid}) ->
             get_task_prop(Pid, updated_on) > get_task_prop(Pid, started_on)
         end).
 
-should_control_update_frequency({_, Pid}) ->
-    ?_assertEqual(66,
-        begin
-            ok = call(Pid, add, [{type, replication}, {progress, 0}]),
-            call(Pid, update, [{progress, 50}]),
-            call(Pid, update_frequency, 500),
-            call(Pid, update, [{progress, 66}]),
-            call(Pid, update, [{progress, 77}]),
-            get_task_prop(Pid, progress)
-        end).
+%%should_control_update_frequency({_, Pid}) ->
+%%    ?_assertEqual(66,
+%%        begin
+%%            ok = call(Pid, add, [{type, replication}, {progress, 0}]),
+%%            call(Pid, update, [{progress, 50}]),
+%%            call(Pid, update_frequency, 500),
+%%            call(Pid, update, [{progress, 66}]),
+%%            call(Pid, update, [{progress, 77}]),
+%%            get_task_prop(Pid, progress)
+%%        end).
 
 should_reset_control_update_frequency({_, Pid}) ->
     ?_assertEqual(87,


[42/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Simplify ABS_PATH macro

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

Branch: refs/heads/master
Commit: b41d8ba93f2edb5e80d9efa07755535409e8d3fe
Parents: d8d1a3c
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed Feb 18 11:16:54 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Wed Feb 18 11:16:54 2015 -0800

----------------------------------------------------------------------
 include/couch_eunit.hrl | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b41d8ba9/include/couch_eunit.hrl
----------------------------------------------------------------------
diff --git a/include/couch_eunit.hrl b/include/couch_eunit.hrl
index c48442a..390f03a 100644
--- a/include/couch_eunit.hrl
+++ b/include/couch_eunit.hrl
@@ -31,11 +31,12 @@
     filename:join([?BUILDDIR(), "src", "couch", "test", "fixtures"])).
 -define(TEMPDIR,
     filename:join([?BUILDDIR(), "tmp", "tmp_data"])).
--define(ABS_PATH(File),
-    filename:join([
-        filename:dirname(
-            filename:dirname(
-                filename:dirname(filename:absname(File)))), File])).
+
+-define(APPDIR, filename:dirname(element(2, file:get_cwd()))).
+%% Account for the fact that source files are in src/<app>/.eunit/<module>.erl
+%% when run from eunit
+-define(ABS_PATH(File), %% src/<app>/.eunit/<module>.erl
+    filename:join([?APPDIR, File])).
 
 -define(tempfile,
     fun() ->


[21/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Add test should_close_old_db_on_auth_db_change

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

Branch: refs/heads/master
Commit: 533105688d199bdac372fac516ba40ff6446015a
Parents: 72981ec
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Feb 2 11:58:52 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:04:12 2015 -0800

----------------------------------------------------------------------
 src/couch_db.erl                | 15 ++++++++++-----
 test/couch_auth_cache_tests.erl | 16 +++++++++++++++-
 2 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/53310568/src/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_db.erl b/src/couch_db.erl
index 0d4857f..63aef55 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -32,6 +32,7 @@
 -export([reopen/1, is_system_db/1, compression/1, make_doc/5]).
 -export([load_validation_funs/1]).
 -export([check_md5/2, with_stream/3]).
+-export([monitored_by/1]).
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -122,15 +123,19 @@ close(#db{fd_monitor=RefCntr}) ->
     ok.
 
 is_idle(#db{compactor_pid=nil, waiting_delayed_commit=nil} = Db) ->
+    monitored_by(Db) == [];
+is_idle(_Db) ->
+    false.
+
+monitored_by(Db) ->
     case erlang:process_info(Db#db.fd, monitored_by) of
     undefined ->
-        true;
+        [];
     {monitored_by, Pids} ->
         PidTracker = whereis(couch_stats_process_tracker),
-        (Pids -- [Db#db.main_pid, PidTracker]) =:= []
-    end;
-is_idle(_Db) ->
-    false.
+        Pids -- [Db#db.main_pid, PidTracker]
+    end.
+
 
 monitor(#db{main_pid=MainPid}) ->
     erlang:monitor(process, MainPid).

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/53310568/test/couch_auth_cache_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_auth_cache_tests.erl b/test/couch_auth_cache_tests.erl
index 4223319..cba77ed 100644
--- a/test/couch_auth_cache_tests.erl
+++ b/test/couch_auth_cache_tests.erl
@@ -51,7 +51,8 @@ couch_auth_cache_test_() ->
                     fun should_restore_cache_after_userdoc_recreation/1,
                     fun should_drop_cache_on_auth_db_change/1,
                     fun should_restore_cache_on_auth_db_change/1,
-                    fun should_recover_cache_after_shutdown/1
+                    fun should_recover_cache_after_shutdown/1,
+                    fun should_close_old_db_on_auth_db_change/1
                 ]
             }
         }
@@ -153,6 +154,13 @@ should_recover_cache_after_shutdown(DbName) ->
         ?assertEqual(PasswordHash, get_user_doc_password_sha(DbName, "joe"))
     end).
 
+should_close_old_db_on_auth_db_change(DbName) ->
+    ?_test(begin
+        ?assert(is_opened(DbName)),
+        config:set("couch_httpd_auth", "authentication_db",
+                         ?b2l(?tempdb()), false),
+        ?assertNot(is_opened(DbName))
+    end).
 
 update_user_doc(DbName, UserName, Password) ->
     update_user_doc(DbName, UserName, Password, nil).
@@ -224,3 +232,9 @@ full_commit(DbName) ->
     {ok, AuthDb} = couch_db:open_int(DbName, [?ADMIN_CTX]),
     {ok, _} = couch_db:ensure_full_commit(AuthDb),
     ok = couch_db:close(AuthDb).
+
+is_opened(DbName) ->
+    {ok, AuthDb} = couch_db:open_int(DbName, [?ADMIN_CTX]),
+    Monitors = couch_db:monitored_by(AuthDb) -- [self()],
+    ok = couch_db:close(AuthDb),
+    Monitors /= [].


[41/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Make sure we load all applications with stats defs

couch_stats app relies on application:loaded_applications.
While in the test suite we have to load the apps manually
prior to start couch_stats app.
Note: We are just loading deps but not starting them.
The commit is also needed for COUCHDB-2552.

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

Branch: refs/heads/master
Commit: d8d1a3ca0e3fe7ba6cdeced111f868a8e20fbccf
Parents: d48664f
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 10 11:39:00 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:39:00 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/d8d1a3ca/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index 48b57f0..829fc36 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -67,6 +67,7 @@ start_couch(ExtraApps) ->
     start_couch(?CONFIG_CHAIN, ExtraApps).
 
 start_couch(IniFiles, ExtraApps) ->
+    load_applications_with_stats(),
     ok = application:set_env(config, ini_files, IniFiles),
     ok = lager:start(),
 
@@ -74,7 +75,6 @@ start_couch(IniFiles, ExtraApps) ->
         [inets, ibrowse, ssl, config, couch_event, couch]
         ++ ExtraApps),
 
-    couch_stats:reload(),
     #test_context{started = Apps}.
 
 stop_couch() ->
@@ -254,3 +254,12 @@ mock(couch_stats) ->
     meck:expect(couch_stats, update_histogram, fun(_, _) -> ok end),
     meck:expect(couch_stats, update_gauge, fun(_, _) -> ok end),
     ok.
+
+load_applications_with_stats() ->
+    Wildcard = filename:join([?BUILDDIR(), "src/*/priv/stats_descriptions.cfg"]),
+    [application:load(stats_file_to_app(File)) || File <- filelib:wildcard(Wildcard)],
+    ok.
+
+stats_file_to_app(File) ->
+    [_Desc, _Priv, App|_] = lists:reverse(filename:split(File)),
+    erlang:list_to_atom(App).


[38/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Fix couch_sup:handle_config_change

Since couch_server_sup is gone for a long time we need to use different
supervisor name in handle_config_change.

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

Branch: refs/heads/master
Commit: ca6607a9eee8570256cd051c7beb155a3462640c
Parents: 65c88d2
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Feb 5 11:31:11 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:07:29 2015 -0800

----------------------------------------------------------------------
 src/couch_sup.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/ca6607a9/src/couch_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_sup.erl b/src/couch_sup.erl
index 2498a80..8dfa011 100644
--- a/src/couch_sup.erl
+++ b/src/couch_sup.erl
@@ -66,7 +66,7 @@ init(_Args) ->
 
 
 handle_config_change("daemons", _, _, _, _) ->
-    exit(whereis(couch_server_sup), shutdown),
+    exit(whereis(?MODULE), shutdown),
     remove_handler;
 handle_config_change("couchdb", "util_driver_dir", _, _, _) ->
     [Pid] = [P || {collation_driver, P, _, _}


[16/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Return #test_context{} from test_util:start_couch

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

Branch: refs/heads/master
Commit: a78267ba9f844197159491e844921c5a1c23b15e
Parents: 72c313d
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Feb 2 06:50:20 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:03:00 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/a78267ba/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index a4ab007..ec2029d 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -68,14 +68,20 @@ start_couch(ExtraApps) ->
 start_couch(IniFiles, ExtraApps) ->
     ok = application:set_env(config, ini_files, IniFiles),
     ok = lager:start(),
-    Ctx = start_applications([inets, ibrowse, ssl, config, couch] ++ ExtraApps),
+
+    Apps = start_applications(
+        [inets, ibrowse, ssl, config, couch_event, couch]
+        ++ ExtraApps),
+
     couch_stats:reload(),
-    Ctx.
+    #test_context{started = Apps}.
 
 stop_couch() ->
     ok = stop_applications([inets, ibrowse, ssl, config, goldrush, lager, couch]),
     ok.
 
+stop_couch(#test_context{started = Apps}) ->
+    stop_applications(Apps);
 stop_couch(_) ->
     stop_couch().
 


[29/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
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 <ii...@ca.ibm.com>
Authored: Tue Feb 3 13:14:20 2015 -0800
Committer: ILYA Khlopotov <ii...@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).


[12/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Replace s/ejson:/jiffy:/g

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

Branch: refs/heads/master
Commit: b5d8e09e725e4480e0ccd073eec7a7161d4adcc6
Parents: f568893
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 10:51:29 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:41:04 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl                  |  2 +-
 test/couchdb_attachments_tests.erl | 20 ++++++++++----------
 test/couchdb_vhosts_tests.erl      | 28 ++++++++++++++--------------
 test/couchdb_views_tests.erl       |  4 ++--
 4 files changed, 27 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b5d8e09e/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index d4eb882..0fbf1de 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -39,7 +39,7 @@ init_code_path() ->
     Paths = [
         "etap",
         "couchdb",
-        "ejson",
+        "jiffy",
         "oauth",
         "ibrowse",
         "mochiweb",

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b5d8e09e/test/couchdb_attachments_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_attachments_tests.erl b/test/couchdb_attachments_tests.erl
index 9a43939..083efc7 100644
--- a/test/couchdb_attachments_tests.erl
+++ b/test/couchdb_attachments_tests.erl
@@ -365,7 +365,7 @@ should_get_doc_with_att_data(compressed, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = jiffy:decode(Body),
         AttJson = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_TXT_NAME]),
         AttData = couch_util:get_nested_json_value(
@@ -381,7 +381,7 @@ should_get_doc_with_att_data({text, _}, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = jiffy:decode(Body),
         AttJson = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_TXT_NAME]),
         AttData = couch_util:get_nested_json_value(
@@ -397,7 +397,7 @@ should_get_doc_with_att_data({binary, _}, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = jiffy:decode(Body),
         AttJson = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_BIN_NAME]),
         AttData = couch_util:get_nested_json_value(
@@ -414,7 +414,7 @@ should_get_doc_with_att_data_stub(compressed, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = jiffy:decode(Body),
         {AttJson} = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_TXT_NAME]),
         ?assertEqual(<<"gzip">>,
@@ -430,7 +430,7 @@ should_get_doc_with_att_data_stub({text, _}, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = jiffy:decode(Body),
         {AttJson} = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_TXT_NAME]),
         ?assertEqual(<<"gzip">>,
@@ -447,7 +447,7 @@ should_get_doc_with_att_data_stub({binary, _}, {Data, {_, DocUrl, _}}) ->
         {ok, Code, _, Body} = test_request:get(
             Url, [{"Accept", "application/json"}]),
         ?assertEqual(200, Code),
-        Json = ejson:decode(Body),
+        Json = jiffy:decode(Body),
         {AttJson} = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_BIN_NAME]),
         ?assertEqual(undefined,
@@ -504,7 +504,7 @@ should_create_compressible_att_with_ctype_params({Host, DbName}) ->
         {ok, Code1, _, Body} = test_request:get(
             DocUrl ++ "?att_encoding_info=true"),
         ?assertEqual(200, Code1),
-        Json = ejson:decode(Body),
+        Json = jiffy:decode(Body),
         {AttJson} = couch_util:get_nested_json_value(
             Json, [<<"_attachments">>, ?ATT_TXT_NAME]),
         ?assertEqual(<<"gzip">>,
@@ -565,7 +565,7 @@ request(Method, Url, Headers, Body) ->
     [Header, Body1] = re:split(R, "\r\n\r\n", [{return, binary}]),
     {ok, {http_response, _, Code, _}, _} =
         erlang:decode_packet(http, Header, []),
-    Json = ejson:decode(Body1),
+    Json = jiffy:decode(Body1),
     {ok, Code, Json}.
 
 create_standalone_text_att(Host, DbName) ->
@@ -596,7 +596,7 @@ create_inline_text_att(Host, DbName) ->
         }]}}
     ]},
     {ok, Code, _Headers, _Body} = test_request:put(
-        Url, [{"Content-Type", "application/json"}], ejson:encode(Doc)),
+        Url, [{"Content-Type", "application/json"}], jiffy:encode(Doc)),
     ?assertEqual(201, Code),
     string:join([Url, ?b2l(?ATT_TXT_NAME)], "/").
 
@@ -612,7 +612,7 @@ create_inline_png_att(Host, DbName) ->
         }]}}
     ]},
     {ok, Code, _Headers, _Body} = test_request:put(
-        Url, [{"Content-Type", "application/json"}], ejson:encode(Doc)),
+        Url, [{"Content-Type", "application/json"}], jiffy:encode(Doc)),
     ?assertEqual(201, Code),
     string:join([Url, ?b2l(?ATT_BIN_NAME)], "/").
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b5d8e09e/test/couchdb_vhosts_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_vhosts_tests.erl b/test/couchdb_vhosts_tests.erl
index e2e8cbf..aea00ec 100644
--- a/test/couchdb_vhosts_tests.erl
+++ b/test/couchdb_vhosts_tests.erl
@@ -144,7 +144,7 @@ should_return_database_info({Url, DbName}) ->
         ok = config:set("vhosts", "example.com", "/" ++ DbName, false),
         case test_request:get(Url, [], [{host_header, "example.com"}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = jiffy:decode(Body),
                 ?assert(proplists:is_defined(<<"db_name">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -160,7 +160,7 @@ should_return_revs_info({Url, DbName}) ->
         case test_request:get(Url ++ "/doc1?revs_info=true", [],
                               [{host_header, "example.com"}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = jiffy:decode(Body),
                 ?assert(proplists:is_defined(<<"_revs_info">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -192,7 +192,7 @@ should_return_virtual_request_path_field_in_request({Url, DbName}) ->
                               false),
         case test_request:get(Url, [], [{host_header, "example1.com"}]) of
             {ok, _, _, Body} ->
-                {Json} = ejson:decode(Body),
+                {Json} = jiffy:decode(Body),
                 ?assertEqual(<<"/">>,
                              proplists:get_value(<<"requested_path">>, Json));
             Else ->
@@ -210,7 +210,7 @@ should_return_real_request_path_field_in_request({Url, DbName}) ->
                               false),
         case test_request:get(Url, [], [{host_header, "example1.com"}]) of
             {ok, _, _, Body} ->
-                {Json} = ejson:decode(Body),
+                {Json} = jiffy:decode(Body),
                 Path = ?l2b("/" ++ DbName ++ "/_design/doc1/_show/test"),
                 ?assertEqual(Path, proplists:get_value(<<"path">>, Json));
             Else ->
@@ -227,7 +227,7 @@ should_match_wildcard_vhost({Url, DbName}) ->
                               "/" ++ DbName ++ "/_design/doc1/_rewrite", false),
         case test_request:get(Url, [], [{host_header, "test.example.com"}]) of
             {ok, _, _, Body} ->
-                {Json} = ejson:decode(Body),
+                {Json} = jiffy:decode(Body),
                 Path = ?l2b("/" ++ DbName ++ "/_design/doc1/_show/test"),
                 ?assertEqual(Path, proplists:get_value(<<"path">>, Json));
             Else ->
@@ -245,7 +245,7 @@ should_return_db_info_for_wildcard_vhost_for_custom_db({Url, DbName}) ->
         Host = DbName ++ ".example1.com",
         case test_request:get(Url, [], [{host_header, Host}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = jiffy:decode(Body),
                 ?assert(proplists:is_defined(<<"db_name">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -262,7 +262,7 @@ should_replace_rewrite_variables_for_db_and_doc({Url, DbName}) ->
         Host = "doc1." ++ DbName ++ ".example1.com",
         case test_request:get(Url, [], [{host_header, Host}]) of
             {ok, _, _, Body} ->
-                {Json} = ejson:decode(Body),
+                {Json} = jiffy:decode(Body),
                 Path = ?l2b("/" ++ DbName ++ "/_design/doc1/_show/test"),
                 ?assertEqual(Path, proplists:get_value(<<"path">>, Json));
             Else ->
@@ -280,7 +280,7 @@ should_return_db_info_for_vhost_with_resource({Url, DbName}) ->
         ReqUrl = Url ++ "/test",
         case test_request:get(ReqUrl, [], [{host_header, "example.com"}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = jiffy:decode(Body),
                 ?assert(proplists:is_defined(<<"db_name">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -298,7 +298,7 @@ should_return_revs_info_for_vhost_with_resource({Url, DbName}) ->
         ReqUrl = Url ++ "/test/doc1?revs_info=true",
         case test_request:get(ReqUrl, [], [{host_header, "example.com"}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = jiffy:decode(Body),
                 ?assert(proplists:is_defined(<<"_revs_info">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -315,7 +315,7 @@ should_return_db_info_for_vhost_with_wildcard_resource({Url, DbName}) ->
         Host = DbName ++ ".example2.com",
         case test_request:get(ReqUrl, [], [{host_header, Host}]) of
             {ok, _, _, Body} ->
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = jiffy:decode(Body),
                 ?assert(proplists:is_defined(<<"db_name">>, JsonBody));
             Else ->
                 erlang:error({assertion_failed,
@@ -332,7 +332,7 @@ should_return_path_for_vhost_with_wildcard_host({Url, DbName}) ->
                               false),
         case test_request:get(Url ++ "/test1") of
             {ok, _, _, Body} ->
-                {Json} = ejson:decode(Body),
+                {Json} = jiffy:decode(Body),
                 Path = ?l2b("/" ++ DbName ++ "/_design/doc1/_show/test"),
                 ?assertEqual(Path, proplists:get_value(<<"path">>, Json));
             Else ->
@@ -348,7 +348,7 @@ should_require_auth({Url, _}) ->
         case test_request:get(Url, [], [{host_header, "oauth-example.com"}]) of
             {ok, Code, _, Body} ->
                 ?assertEqual(401, Code),
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = jiffy:decode(Body),
                 ?assertEqual(<<"unauthorized">>,
                              couch_util:get_value(<<"error">>, JsonBody));
             Else ->
@@ -382,7 +382,7 @@ should_succeed_oauth({Url, _}) ->
         case test_request:get(OAuthUrl, [], [{host_header, Host}]) of
             {ok, Code, _, Body} ->
                 ?assertEqual(200, Code),
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = jiffy:decode(Body),
                 ?assertEqual(<<"test">>,
                              couch_util:get_value(<<"name">>, JsonBody));
             Else ->
@@ -416,7 +416,7 @@ should_fail_oauth_with_wrong_credentials({Url, _}) ->
         case test_request:get(OAuthUrl, [], [{host_header, Host}]) of
             {ok, Code, _, Body} ->
                 ?assertEqual(401, Code),
-                {JsonBody} = ejson:decode(Body),
+                {JsonBody} = jiffy:decode(Body),
                 ?assertEqual(<<"unauthorized">>,
                              couch_util:get_value(<<"error">>, JsonBody));
             Else ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b5d8e09e/test/couchdb_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_views_tests.erl b/test/couchdb_views_tests.erl
index 6282be6..436e625 100644
--- a/test/couchdb_views_tests.erl
+++ b/test/couchdb_views_tests.erl
@@ -479,7 +479,7 @@ query_view(DbName, DDoc, View, Stale) ->
                _ -> "?stale=" ++ atom_to_list(Stale)
            end),
     ?assertEqual(200, Code),
-    {Props} = ejson:decode(Body),
+    {Props} = jiffy:decode(Body),
     couch_util:get_value(<<"rows">>, Props, []).
 
 check_rows_value(Rows, Value) ->
@@ -568,7 +568,7 @@ wait_view_compact_done(DbName, DDocId, N) ->
     {ok, Code, _Headers, Body} = test_request:get(
         db_url(DbName) ++ "/" ++ ?b2l(DDocId) ++ "/_info"),
     ?assertEqual(200, Code),
-    {Info} = ejson:decode(Body),
+    {Info} = jiffy:decode(Body),
     {IndexInfo} = couch_util:get_value(<<"view_index">>, Info),
     CompactRunning = couch_util:get_value(<<"compact_running">>, IndexInfo),
     case CompactRunning of


[23/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable couch_key_tree_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/9985c2c9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/9985c2c9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/9985c2c9

Branch: refs/heads/master
Commit: 9985c2c9dc3635d215b3193743b1c64e9f56ae86
Parents: b59b529
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 3 07:06:13 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:04:30 2015 -0800

----------------------------------------------------------------------
 test/couch_key_tree_tests.erl | 166 +++++++++++++++++++++----------------
 1 file changed, 94 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9985c2c9/test/couch_key_tree_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_key_tree_tests.erl b/test/couch_key_tree_tests.erl
index 2a3551a..431391f 100644
--- a/test/couch_key_tree_tests.erl
+++ b/test/couch_key_tree_tests.erl
@@ -16,107 +16,131 @@
 
 -define(DEPTH, 10).
 
-
--ifdef(fix_broken_tests).
+setup() ->
+    test_util:start(?MODULE, [], [{dont_mock, [config]}]).
 
 key_tree_merge_test_()->
     {
         "Key tree merge",
-        [
-            should_merge_with_empty_tree(),
-            should_merge_reflexive(),
-            should_merge_prefix_of_a_tree_with_tree(),
-            should_produce_conflict_on_merge_with_unrelated_branch(),
-            should_merge_reflexive_for_child_nodes(),
-            should_merge_tree_to_itself(),
-            should_merge_tree_of_odd_length(),
-            should_merge_tree_with_stem(),
-            should_merge_with_stem_at_deeper_level(),
-            should_merge_with_stem_at_deeper_level_with_deeper_paths(),
-            should_merge_single_tree_with_deeper_stem(),
-            should_merge_tree_with_large_stem(),
-            should_merge_stems(),
-            should_create_conflicts_on_merge(),
-            should_create_no_conflicts_on_merge(),
-            should_ignore_conflicting_branch()
-        ]
+        {
+            setup,
+            fun setup/0, fun test_util:stop/1,
+            [
+                should_merge_with_empty_tree(),
+                should_merge_reflexive(),
+                should_merge_prefix_of_a_tree_with_tree(),
+                should_produce_conflict_on_merge_with_unrelated_branch(),
+                should_merge_reflexive_for_child_nodes(),
+                should_merge_tree_to_itself(),
+                should_merge_tree_of_odd_length(),
+                should_merge_tree_with_stem(),
+                should_merge_with_stem_at_deeper_level(),
+                should_merge_with_stem_at_deeper_level_with_deeper_paths(),
+                should_merge_single_tree_with_deeper_stem(),
+                should_merge_tree_with_large_stem(),
+                should_merge_stems(),
+                should_create_conflicts_on_merge(),
+                should_create_no_conflicts_on_merge(),
+                should_ignore_conflicting_branch()
+            ]
+        }
     }.
 
 key_tree_missing_leaves_test_()->
     {
         "Missing tree leaves",
-        [
-            should_not_find_missing_leaves(),
-            should_find_missing_leaves()
-        ]
+        {
+            setup,
+            fun setup/0, fun test_util:stop/1,
+            [
+                should_not_find_missing_leaves(),
+                should_find_missing_leaves()
+            ]
+        }
     }.
 
 key_tree_remove_leaves_test_()->
     {
         "Remove tree leaves",
-        [
-            should_have_no_effect_on_removing_no_leaves(),
-            should_have_no_effect_on_removing_non_existant_branch(),
-            should_remove_leaf(),
-            should_produce_empty_tree_on_removing_all_leaves(),
-            should_have_no_effect_on_removing_non_existant_node(),
-            should_produce_empty_tree_on_removing_last_leaf()
-        ]
+        {
+            setup,
+            fun setup/0, fun test_util:stop/1,
+            [
+                should_have_no_effect_on_removing_no_leaves(),
+                should_have_no_effect_on_removing_non_existant_branch(),
+                should_remove_leaf(),
+                should_produce_empty_tree_on_removing_all_leaves(),
+                should_have_no_effect_on_removing_non_existant_node(),
+                should_produce_empty_tree_on_removing_last_leaf()
+            ]
+        }
     }.
 
 key_tree_get_leaves_test_()->
     {
         "Leaves retrieving",
-        [
-            should_extract_subtree(),
-            should_extract_subsubtree(),
-            should_gather_non_existant_leaf(),
-            should_gather_leaf(),
-            shoul_gather_multiple_leaves(),
-            should_retrieve_full_key_path(),
-            should_retrieve_full_key_path_for_node(),
-            should_retrieve_leaves_with_parent_node(),
-            should_retrieve_all_leaves()
-        ]
+        {
+            setup,
+            fun setup/0, fun test_util:stop/1,
+            [
+                should_extract_subtree(),
+                should_extract_subsubtree(),
+                should_gather_non_existant_leaf(),
+                should_gather_leaf(),
+                shoul_gather_multiple_leaves(),
+                should_retrieve_full_key_path(),
+                should_retrieve_full_key_path_for_node(),
+                should_retrieve_leaves_with_parent_node(),
+                should_retrieve_all_leaves()
+            ]
+        }
     }.
 
 key_tree_leaf_counting_test_()->
     {
         "Leaf counting",
-        [
-            should_have_no_leaves_for_empty_tree(),
-            should_have_single_leaf_for_tree_with_single_node(),
-            should_have_two_leaves_for_tree_with_chindler_siblings(),
-            should_not_affect_on_leaf_counting_for_stemmed_tree()
-        ]
+        {
+            setup,
+            fun setup/0, fun test_util:stop/1,
+            [
+                should_have_no_leaves_for_empty_tree(),
+                should_have_single_leaf_for_tree_with_single_node(),
+                should_have_two_leaves_for_tree_with_chindler_siblings(),
+                should_not_affect_on_leaf_counting_for_stemmed_tree()
+            ]
+        }
     }.
 
 key_tree_stemming_test_()->
     {
         "Stemming",
-        [
-            should_have_no_effect_for_stemming_more_levels_than_exists(),
-            should_return_one_deepest_node(),
-            should_return_two_deepest_nodes()
-        ]
+        {
+            setup,
+            fun setup/0, fun test_util:stop/1,
+            [
+                should_have_no_effect_for_stemming_more_levels_than_exists(),
+                should_return_one_deepest_node(),
+                should_return_two_deepest_nodes()
+            ]
+        }
     }.
 
 
 should_merge_with_empty_tree()->
     One = {1, {"1","foo",[]}},
-    ?_assertEqual({[One], no_conflicts},
+    ?_assertEqual({[One], new_leaf},
                   couch_key_tree:merge([], One, ?DEPTH)).
 
 should_merge_reflexive()->
     One = {1, {"1","foo",[]}},
-    ?_assertEqual({[One], no_conflicts},
+    ?_assertEqual({[One], internal_node},
                   couch_key_tree:merge([One], One, ?DEPTH)).
 
 should_merge_prefix_of_a_tree_with_tree()->
     One = {1, {"1","foo",[]}},
     TwoSibs = [{1, {"1","foo",[]}},
                {1, {"2","foo",[]}}],
-    ?_assertEqual({TwoSibs, no_conflicts},
+    ?_assertEqual({TwoSibs, internal_node},
                   couch_key_tree:merge(TwoSibs, One, ?DEPTH)).
 
 should_produce_conflict_on_merge_with_unrelated_branch()->
@@ -126,18 +150,18 @@ should_produce_conflict_on_merge_with_unrelated_branch()->
     ThreeSibs = [{1, {"1","foo",[]}},
                  {1, {"2","foo",[]}},
                  {1, {"3","foo",[]}}],
-    ?_assertEqual({ThreeSibs, conflicts},
+    ?_assertEqual({ThreeSibs, new_branch},
                   couch_key_tree:merge(TwoSibs, Three, ?DEPTH)).
 
 should_merge_reflexive_for_child_nodes()->
     TwoChild = {1, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]}]}},
-    ?_assertEqual({[TwoChild], no_conflicts},
+    ?_assertEqual({[TwoChild], internal_node},
                   couch_key_tree:merge([TwoChild], TwoChild, ?DEPTH)).
 
 should_merge_tree_to_itself()->
     TwoChildSibs = {1, {"1","foo", [{"1a", "bar", []},
                                     {"1b", "bar", []}]}},
-    ?_assertEqual({[TwoChildSibs], no_conflicts},
+    ?_assertEqual({[TwoChildSibs], new_branch},
                   couch_key_tree:merge([TwoChildSibs], TwoChildSibs, ?DEPTH)).
 
 should_merge_tree_of_odd_length()->
@@ -147,7 +171,7 @@ should_merge_tree_of_odd_length()->
     TwoChildPlusSibs = {1, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]},
                                         {"1b", "bar", []}]}},
 
-    ?_assertEqual({[TwoChildPlusSibs], no_conflicts},
+    ?_assertEqual({[TwoChildPlusSibs], new_branch},
                   couch_key_tree:merge([TwoChild], TwoChildSibs, ?DEPTH)).
 
 should_merge_tree_with_stem()->
@@ -155,52 +179,52 @@ should_merge_tree_with_stem()->
     TwoChildSibs = {1, {"1","foo", [{"1a", "bar", []},
                                     {"1b", "bar", []}]}},
 
-    ?_assertEqual({[TwoChildSibs], no_conflicts},
+    ?_assertEqual({[TwoChildSibs], internal_node},
                   couch_key_tree:merge([TwoChildSibs], Stemmed, ?DEPTH)).
 
 should_merge_with_stem_at_deeper_level()->
     Stemmed = {3, {"1bb", "boo", []}},
     TwoChildSibs = {1, {"1","foo", [{"1a", "bar", []},
                                     {"1b", "bar", [{"1bb", "boo", []}]}]}},
-    ?_assertEqual({[TwoChildSibs], no_conflicts},
+    ?_assertEqual({[TwoChildSibs], internal_node},
                   couch_key_tree:merge([TwoChildSibs], Stemmed, ?DEPTH)).
 
 should_merge_with_stem_at_deeper_level_with_deeper_paths()->
     Stemmed = {3, {"1bb", "boo", []}},
     StemmedTwoChildSibs = [{2,{"1a", "bar", []}},
                            {2,{"1b", "bar", [{"1bb", "boo", []}]}}],
-    ?_assertEqual({StemmedTwoChildSibs, no_conflicts},
+    ?_assertEqual({StemmedTwoChildSibs, internal_node},
                   couch_key_tree:merge(StemmedTwoChildSibs, Stemmed, ?DEPTH)).
 
 should_merge_single_tree_with_deeper_stem()->
     Stemmed = {3, {"1aa", "bar", []}},
     TwoChild = {1, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]}]}},
-    ?_assertEqual({[TwoChild], no_conflicts},
+    ?_assertEqual({[TwoChild], internal_node},
                   couch_key_tree:merge([TwoChild], Stemmed, ?DEPTH)).
 
 should_merge_tree_with_large_stem()->
     Stemmed = {2, {"1a", "bar", [{"1aa", "bar", []}]}},
     TwoChild = {1, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]}]}},
-    ?_assertEqual({[TwoChild], no_conflicts},
+    ?_assertEqual({[TwoChild], internal_node},
                   couch_key_tree:merge([TwoChild], Stemmed, ?DEPTH)).
 
 should_merge_stems()->
     StemmedA = {2, {"1a", "bar", [{"1aa", "bar", []}]}},
     StemmedB = {3, {"1aa", "bar", []}},
-    ?_assertEqual({[StemmedA], no_conflicts},
+    ?_assertEqual({[StemmedA], internal_node},
                   couch_key_tree:merge([StemmedA], StemmedB, ?DEPTH)).
 
 should_create_conflicts_on_merge()->
     OneChild = {1, {"1","foo",[{"1a", "bar", []}]}},
     Stemmed = {3, {"1aa", "bar", []}},
-    ?_assertEqual({[OneChild, Stemmed], conflicts},
+    ?_assertEqual({[OneChild, Stemmed], new_branch},
                   couch_key_tree:merge([OneChild], Stemmed, ?DEPTH)).
 
 should_create_no_conflicts_on_merge()->
     OneChild = {1, {"1","foo",[{"1a", "bar", []}]}},
     Stemmed = {3, {"1aa", "bar", []}},
     TwoChild = {1, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]}]}},
-    ?_assertEqual({[TwoChild], no_conflicts},
+    ?_assertEqual({[TwoChild], new_leaf},
                   couch_key_tree:merge([OneChild, Stemmed], TwoChild, ?DEPTH)).
 
 should_ignore_conflicting_branch()->
@@ -229,7 +253,7 @@ should_ignore_conflicting_branch()->
                ]}},
     {
         "COUCHDB-902",
-        ?_assertEqual({[FooBar], no_conflicts},
+        ?_assertEqual({[FooBar], new_leaf},
                       couch_key_tree:merge([Foo], Bar, ?DEPTH))
     }.
 
@@ -380,5 +404,3 @@ should_return_two_deepest_nodes()->
     TwoChild = [{0, {"1","foo", [{"1a", "bar", [{"1aa", "bar", []}]}]}}],
     Stemmed = [{1, {"1a", "bar", [{"1aa", "bar", []}]}}],
     ?_assertEqual(Stemmed, couch_key_tree:stem(TwoChild, 2)).
-
--endif.


[34/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable couchdb_vhosts_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/7cc94fa8
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/7cc94fa8
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/7cc94fa8

Branch: refs/heads/master
Commit: 7cc94fa8e261464e948aee440348c5b245a7ee72
Parents: 47ccf6e
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed Feb 4 14:32:26 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:06:59 2015 -0800

----------------------------------------------------------------------
 test/couchdb_vhosts_tests.erl | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/7cc94fa8/test/couchdb_vhosts_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_vhosts_tests.erl b/test/couchdb_vhosts_tests.erl
index aea00ec..13b69bb 100644
--- a/test/couchdb_vhosts_tests.erl
+++ b/test/couchdb_vhosts_tests.erl
@@ -19,8 +19,6 @@
 -define(iofmt(S, A), lists:flatten(io_lib:format(S, A))).
 
 
--ifdef(run_broken_tests).
-
 setup() ->
     DbName = ?tempdb(),
     {ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]),
@@ -48,6 +46,14 @@ setup() ->
     couch_db:ensure_full_commit(Db),
     couch_db:close(Db),
 
+    test_util:with_process_restart(couch_httpd, fun() ->
+        config:set("httpd_global_handlers", "_utils",
+            "{couch_httpd_misc_handlers, handle_utils_dir_req, <<\""
+                ++ ?TEMPDIR
+                ++ "\">>}"
+        )
+    end),
+
     Addr = config:get("httpd", "bind_address", "127.0.0.1"),
     Port = integer_to_list(mochiweb_socket_server:get(couch_httpd, port)),
     Url = "http://" ++ Addr ++ ":" ++ Port,
@@ -173,6 +179,7 @@ should_return_revs_info({Url, DbName}) ->
 should_serve_utils_for_vhost({Url, DbName}) ->
     ?_test(begin
         ok = config:set("vhosts", "example.com", "/" ++ DbName, false),
+        ensure_index_file(),
         case test_request:get(Url ++ "/_utils/index.html", [],
                               [{host_header, "example.com"}]) of
             {ok, _, _, Body} ->
@@ -427,4 +434,6 @@ should_fail_oauth_with_wrong_credentials({Url, _}) ->
         end
     end).
 
--endif.
+ensure_index_file() ->
+    Body = <<"<!DOCTYPE html>\n<html>\n<body>\nHello world\n</body>\n</html>">>,
+    file:write_file(filename:join([?TEMPDIR, "index.html"]), Body).


[36/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Fix bulk_delete_create

Fix the case when document with the same id is deleted and created in
a single bulk transaction.

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

Branch: refs/heads/master
Commit: 3776aa3bd55a5f39d402992c9a58ed5c06413c96
Parents: 51eec4a
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Feb 5 11:26:41 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:07:13 2015 -0800

----------------------------------------------------------------------
 src/couch_doc.erl | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/3776aa3b/src/couch_doc.erl
----------------------------------------------------------------------
diff --git a/src/couch_doc.erl b/src/couch_doc.erl
index 6fc9b09..d152a2a 100644
--- a/src/couch_doc.erl
+++ b/src/couch_doc.erl
@@ -273,12 +273,7 @@ max_seq(Tree, UpdateSeq) ->
 
 to_doc_info_path(#full_doc_info{id=Id,rev_tree=Tree,update_seq=FDISeq}) ->
     RevInfosAndPath = [
-        {#rev_info{
-            deleted = Leaf#leaf.deleted,
-            body_sp = Leaf#leaf.ptr,
-            seq = Leaf#leaf.seq,
-            rev = {Pos, RevId}
-        }, Path} || {Leaf, {Pos, [RevId | _]} = Path} <-
+        {rev_info(Node), Path} || {_Leaf, Path} = Node <-
             couch_key_tree:get_all_leafs(Tree)
     ],
     SortedRevInfosAndPath = lists:sort(
@@ -291,6 +286,20 @@ to_doc_info_path(#full_doc_info{id=Id,rev_tree=Tree,update_seq=FDISeq}) ->
     RevInfos = [RevInfo || {RevInfo, _Path} <- SortedRevInfosAndPath],
     {#doc_info{id=Id, high_seq=max_seq(Tree, FDISeq), revs=RevInfos}, WinPath}.
 
+rev_info({#leaf{} = Leaf, {Pos, [RevId | _]}}) ->
+    #rev_info{
+        deleted = Leaf#leaf.deleted,
+        body_sp = Leaf#leaf.ptr,
+        seq = Leaf#leaf.seq,
+        rev = {Pos, RevId}
+    };
+rev_info({#doc{} = Doc, {Pos, [RevId | _]}}) ->
+    #rev_info{
+        deleted = Doc#doc.deleted,
+        body_sp = undefined,
+        seq = undefined,
+        rev = {Pos, RevId}
+    }.
 
 is_deleted(#full_doc_info{rev_tree=Tree}) ->
     is_deleted(Tree);


[10/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Use test_util:with_process_restart in 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/93d48aa8
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/93d48aa8
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/93d48aa8

Branch: refs/heads/master
Commit: 93d48aa8f640252b92c0eef0975893833a734bd0
Parents: a60b88f
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 10:33:38 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:40:35 2015 -0800

----------------------------------------------------------------------
 test/couchdb_http_proxy_tests.erl | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/93d48aa8/test/couchdb_http_proxy_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_http_proxy_tests.erl b/test/couchdb_http_proxy_tests.erl
index 9b640da..f8b3645 100644
--- a/test/couchdb_http_proxy_tests.erl
+++ b/test/couchdb_http_proxy_tests.erl
@@ -35,9 +35,11 @@ start() ->
     % (each httpd_global_handlers changes causes couch_httpd restart)
     Ctx = test_util:start_couch(?CONFIG_CHAIN ++ [?CONFIG_FIXTURE_TEMP], []),
     % 49151 is IANA Reserved, let's assume no one is listening there
-    config:set("httpd_global_handlers", "_error",
-        "{couch_httpd_proxy, handle_proxy_req, <<\"http://127.0.0.1:49151/\">>}"
-    ),
+    test_util:with_process_restart(couch_httpd, fun() ->
+        config:set("httpd_global_handlers", "_error",
+            "{couch_httpd_proxy, handle_proxy_req, <<\"http://127.0.0.1:49151/\">>}"
+        )
+    end),
     Ctx.
 
 setup() ->
@@ -45,9 +47,9 @@ setup() ->
     Value = lists:flatten(io_lib:format(
         "{couch_httpd_proxy, handle_proxy_req, ~p}",
         [list_to_binary(proxy_url())])),
-    config:set("httpd_global_handlers", "_test", Value),
-    % let couch_httpd restart
-    timer:sleep(100),
+    test_util:with_process_restart(couch_httpd, fun() ->
+        config:set("httpd_global_handlers", "_test", Value)
+    end),
     Pid.
 
 teardown(Pid) ->


[44/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Use ?assertNot instead of ?_assertNot

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

Branch: refs/heads/master
Commit: 7d7e039ea41187c19ee12f8e7bda02c7bf82e7b9
Parents: c448b14
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Feb 19 10:05:59 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Thu Feb 19 10:05:59 2015 -0800

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


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/7d7e039e/test/couch_stream_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_stream_tests.erl b/test/couch_stream_tests.erl
index e842c86..3d7bf09 100644
--- a/test/couch_stream_tests.erl
+++ b/test/couch_stream_tests.erl
@@ -110,7 +110,7 @@ should_stop_on_normal_exit_of_stream_opener({Fd, _}) ->
         {pid, StreamPid0} -> StreamPid0
     end,
     % Confirm the validity of the test by verifying the stream opener has died
-    ?_assertNot(is_process_alive(OpenerPid)),
+    ?assertNot(is_process_alive(OpenerPid)),
     % Verify the stream itself has also died
     ?_assertNot(is_process_alive(StreamPid)).
 


[31/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable couchdb_http_proxy_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/b59a4b28
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/b59a4b28
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/b59a4b28

Branch: refs/heads/master
Commit: b59a4b28a43e68371165ab7cda7268c622750d89
Parents: 9589b63
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed Feb 4 09:18:50 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:06:20 2015 -0800

----------------------------------------------------------------------
 test/couchdb_http_proxy_tests.erl | 5 -----
 1 file changed, 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b59a4b28/test/couchdb_http_proxy_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_http_proxy_tests.erl b/test/couchdb_http_proxy_tests.erl
index f8b3645..d54ff15 100644
--- a/test/couchdb_http_proxy_tests.erl
+++ b/test/couchdb_http_proxy_tests.erl
@@ -27,8 +27,6 @@
 -define(TIMEOUT, 5000).
 
 
--ifdef(run_broken_tests).
-
 start() ->
     % we have to write any config changes to temp ini file to not loose them
     % when supervisor will kill all children due to reaching restart threshold
@@ -454,6 +452,3 @@ recv_body(ReqId, Acc) ->
     after ?TIMEOUT ->
         throw({error, timeout})
     end.
-
--endif.
-


[11/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Use test_util:stop_config in 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/f5688937
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/f5688937
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/f5688937

Branch: refs/heads/master
Commit: f568893721deeb94956ec1e75a24e5cf1b4fe358
Parents: 93d48aa
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 10:40:51 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:40:50 2015 -0800

----------------------------------------------------------------------
 test/couch_stats_tests.erl        | 10 +---------
 test/couch_uuids_tests.erl        |  8 +-------
 test/couchdb_os_daemons_tests.erl | 10 +---------
 3 files changed, 3 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f5688937/test/couch_stats_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_stats_tests.erl b/test/couch_stats_tests.erl
index 2175f07..762953d 100644
--- a/test/couch_stats_tests.erl
+++ b/test/couch_stats_tests.erl
@@ -42,15 +42,7 @@ teardown_collector(_) ->
 teardown_aggregator(_, Pid) ->
     couch_stats_aggregator:stop(),
     couch_stats_collector:stop(),
-    erlang:monitor(process, Pid),
-    config:stop(),
-    receive
-        {'DOWN', _, _, Pid, _} ->
-            ok
-    after ?TIMEOUT ->
-        throw({timeout, config_stop})
-    end,
-    ok.
+    test_util:stop_config(Pid).
 
 
 couch_stats_collector_test_() ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f5688937/test/couch_uuids_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_uuids_tests.erl b/test/couch_uuids_tests.erl
index 6d91b4c..defea4f 100644
--- a/test/couch_uuids_tests.erl
+++ b/test/couch_uuids_tests.erl
@@ -21,7 +21,6 @@
 
 setup() ->
     {ok, Pid} = config:start_link(?CONFIG_CHAIN),
-    erlang:monitor(process, Pid),
     couch_uuids:start(),
     Pid.
 
@@ -35,12 +34,7 @@ setup(Opts) ->
 
 teardown(Pid) ->
     couch_uuids:stop(),
-    config:stop(),
-    receive
-        {'DOWN', _, _, Pid, _} -> ok
-    after
-        1000 -> throw({timeout_error, config_stop})
-    end.
+    test_util:stop_config(Pid).
 
 teardown(_, Pid) ->
     teardown(Pid).

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f5688937/test/couchdb_os_daemons_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_os_daemons_tests.erl b/test/couchdb_os_daemons_tests.erl
index f788e25..b978e38 100644
--- a/test/couchdb_os_daemons_tests.erl
+++ b/test/couchdb_os_daemons_tests.erl
@@ -47,15 +47,7 @@ setup(DName) ->
     {CfgPid, OsDPid}.
 
 teardown(_, {CfgPid, OsDPid}) ->
-    erlang:monitor(process, CfgPid),
-    config:stop(),
-    receive
-        {'DOWN', _, _, CfgPid, _} ->
-            ok
-    after ?TIMEOUT ->
-        throw({timeout, config_stop})
-    end,
-
+    test_util:stop_config(CfgPid),
     test_util:stop_sync_throw(OsPid, fun() ->
         exit(OsDPid, shutdown)
     end, {timeout, os_daemon_stop}, ?TIMEOUT).


[24/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable couch_uuid_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/c2d3d457
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/c2d3d457
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/c2d3d457

Branch: refs/heads/master
Commit: c2d3d4571b38ddb7499681d694ae5f03f69417f7
Parents: 9985c2c
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 3 07:08:24 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:04:36 2015 -0800

----------------------------------------------------------------------
 test/couch_uuids_tests.erl | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/c2d3d457/test/couch_uuids_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_uuids_tests.erl b/test/couch_uuids_tests.erl
index defea4f..a836ecc 100644
--- a/test/couch_uuids_tests.erl
+++ b/test/couch_uuids_tests.erl
@@ -17,12 +17,10 @@
 -define(TIMEOUT_S, 20).
 
 
--ifdef(run_broken_tests).
-
 setup() ->
-    {ok, Pid} = config:start_link(?CONFIG_CHAIN),
+    Ctx = test_util:start(?MODULE, [], [{dont_mock, [config]}]),
     couch_uuids:start(),
-    Pid.
+    Ctx.
 
 setup(Opts) ->
     Pid = setup(),
@@ -32,12 +30,12 @@ setup(Opts) ->
         end, Opts),
     Pid.
 
-teardown(Pid) ->
+teardown(Ctx) ->
     couch_uuids:stop(),
-    test_util:stop_config(Pid).
+    test_util:stop(Ctx).
 
-teardown(_, Pid) ->
-    teardown(Pid).
+teardown(_, Ctx) ->
+    teardown(Ctx).
 
 
 default_test_() ->
@@ -155,5 +153,3 @@ test_same_suffix(N, Suffix) ->
         Suffix -> test_same_suffix(N - 1, Suffix);
         _ -> false
     end.
-
--endif.


[46/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Disable some tests

Disabled tests fail sometimes due to timeout and race conditions

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

Branch: refs/heads/master
Commit: 15db2b4ed67a7926b79a367bd8cff81e4165cdd0
Parents: 17937d5
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Feb 26 15:19:45 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Thu Feb 26 15:19:45 2015 -0800

----------------------------------------------------------------------
 test/couch_changes_tests.erl       | 4 ++++
 test/couchdb_compaction_daemon.erl | 3 +++
 2 files changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/15db2b4e/test/couch_changes_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_changes_tests.erl b/test/couch_changes_tests.erl
index 589cccc..c28394b 100644
--- a/test/couch_changes_tests.erl
+++ b/test/couch_changes_tests.erl
@@ -18,6 +18,8 @@
 -define(TIMEOUT, 3000).
 -define(TEST_TIMEOUT, 10000).
 
+-ifdef(run_broken_tests).
+
 -record(row, {
     id,
     seq,
@@ -600,3 +602,5 @@ create_db(DbName) ->
 
 delete_db(DbName) ->
     ok = couch_server:delete(DbName, [?ADMIN_CTX]).
+
+-endif.

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/15db2b4e/test/couchdb_compaction_daemon.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_compaction_daemon.erl b/test/couchdb_compaction_daemon.erl
index 92ed8ac..0598a5a 100644
--- a/test/couchdb_compaction_daemon.erl
+++ b/test/couchdb_compaction_daemon.erl
@@ -18,6 +18,7 @@
 -define(TIMEOUT, 30000).
 -define(TIMEOUT_S, ?TIMEOUT div 1000).
 
+-ifdef(run_broken_tests).
 
 start() ->
     Ctx = test_util:start_couch(),
@@ -256,3 +257,5 @@ with_config_change(DbName, Fun) ->
             true -> wait
         end
     end).
+
+-endif.


[33/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable couchdb_os_proc_pool 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/47ccf6ea
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/47ccf6ea
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/47ccf6ea

Branch: refs/heads/master
Commit: 47ccf6eac56d0a4b8885bbd7fa9ad5b1e07a9716
Parents: 80f8330
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed Feb 4 13:32:54 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:06:53 2015 -0800

----------------------------------------------------------------------
 test/couchdb_os_proc_pool.erl | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/47ccf6ea/test/couchdb_os_proc_pool.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_os_proc_pool.erl b/test/couchdb_os_proc_pool.erl
index afa400b..a698070 100644
--- a/test/couchdb_os_proc_pool.erl
+++ b/test/couchdb_os_proc_pool.erl
@@ -18,11 +18,10 @@
 -define(TIMEOUT, 3000).
 
 
--ifdef(run_broken_tests).
-
 start() ->
     Ctx = test_util:start_couch(),
     config:set("query_server_config", "os_process_limit", "3", false),
+    timer:sleep(100), %% we need to wait to let gen_server:cast finish
     Ctx.
 
 
@@ -65,13 +64,16 @@ should_block_new_proc_on_full_pool() ->
         ?assertEqual(ok, ping_client(Client4)),
 
         Proc4 = get_client_proc(Client4, "4"),
-        ?assertEqual(Proc1, Proc4),
+
+        ?assertEqual(Proc1#proc.pid, Proc4#proc.pid),
+        ?assertNotEqual(Proc1#proc.client, Proc4#proc.client),
 
         lists:map(fun(C) ->
             ?assertEqual(ok, stop_client(C))
         end, [Client2, Client3, Client4])
     end).
 
+
 should_free_slot_on_proc_unexpected_exit() ->
     ?_test(begin
         Client1 = spawn_client(),
@@ -86,9 +88,12 @@ should_free_slot_on_proc_unexpected_exit() ->
         Proc2 = get_client_proc(Client2, "2"),
         Proc3 = get_client_proc(Client3, "3"),
 
-        ?assertNotEqual(Proc1, Proc2),
-        ?assertNotEqual(Proc2, Proc3),
-        ?assertNotEqual(Proc3, Proc1),
+        ?assertNotEqual(Proc1#proc.pid, Proc2#proc.pid),
+        ?assertNotEqual(Proc1#proc.client, Proc2#proc.client),
+        ?assertNotEqual(Proc2#proc.pid, Proc3#proc.pid),
+        ?assertNotEqual(Proc2#proc.client, Proc3#proc.client),
+        ?assertNotEqual(Proc3#proc.pid, Proc1#proc.pid),
+        ?assertNotEqual(Proc3#proc.client, Proc1#proc.client),
 
         ?assertEqual(ok, kill_client(Client1)),
 
@@ -96,9 +101,13 @@ should_free_slot_on_proc_unexpected_exit() ->
         ?assertEqual(ok, ping_client(Client4)),
 
         Proc4 = get_client_proc(Client4, "4"),
-        ?assertNotEqual(Proc4, Proc1),
-        ?assertNotEqual(Proc2, Proc4),
-        ?assertNotEqual(Proc3, Proc4),
+
+        ?assertEqual(Proc4#proc.pid, Proc1#proc.pid),
+        ?assertNotEqual(Proc4#proc.client, Proc1#proc.client),
+        ?assertNotEqual(Proc2#proc.pid, Proc4#proc.pid),
+        ?assertNotEqual(Proc2#proc.client, Proc4#proc.client),
+        ?assertNotEqual(Proc3#proc.pid, Proc4#proc.pid),
+        ?assertNotEqual(Proc3#proc.client, Proc4#proc.client),
 
         lists:map(fun(C) ->
             ?assertEqual(ok, stop_client(C))
@@ -169,5 +178,3 @@ loop(Parent, Ref, Proc) ->
             Parent ! {die, Ref},
             exit(some_error)
     end.
-
--endif.


[09/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Implement with_process_restart and wait_process

Implement additional helper functions for test suite to follow DRY.

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

Branch: refs/heads/master
Commit: a60b88ff9d5b58597bf0a21382d51bda5d0ade5d
Parents: bc1963f
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 10:24:33 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:40:15 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/a60b88ff/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index 1c3c93f..d4eb882 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -26,6 +26,9 @@
 
 -export([stop_sync_throw/2, stop_sync_throw/3, stop_sync_throw/4]).
 
+-export([with_process_restart/1, with_process_restart/2, with_process_restart/3]).
+-export([wait_process/1, wait_process/2]).
+
 srcdir() ->
     code:priv_dir(couch) ++ "/../../".
 
@@ -155,3 +158,40 @@ stop_sync_throw(Pid, Fun, Error, Timeout) ->
         Else ->
             Else
     end.
+
+with_process_restart(Name) ->
+    {Pid, true} = with_process_restart(
+        fun() -> exit(whereis(Name), shutdown) end, Name),
+    Pid.
+
+with_process_restart(Name, Fun) ->
+    with_process_restart(Name, Fun, 5000).
+
+with_process_restart(Name, Fun, Timeout) ->
+    ok = stop_sync(Name, Fun),
+    case wait_process(Name, Timeout) of
+    timeout ->
+        timeout;
+    Pid ->
+        Pid
+    end.
+
+wait_process(Name) ->
+    wait_process(Name, 5000).
+wait_process(Name, Timeout) ->
+    Now = now_us(),
+    wait_process(Name, Timeout * 1000, Now, Now).
+
+wait_process(_Name, Timeout, Started, Prev) when Prev - Started > Timeout ->
+    timeout;
+wait_process(Name, Timeout, Started, _Prev) ->
+    case whereis(Name) of
+    undefined ->
+        wait_process(Name, Timeout, Started, now_us());
+    Pid ->
+        Pid
+    end.
+
+now_us() ->
+    {MegaSecs, Secs, MicroSecs} = now(),
+    (MegaSecs * 1000000 + Secs) * 1000000 + MicroSecs.


[30/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable couchdb_os_daemons_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/9589b63b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/9589b63b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/9589b63b

Branch: refs/heads/master
Commit: 9589b63bfbcba8e16d34bc900949a55ec16f0c62
Parents: d4d726c
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed Feb 4 08:41:21 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:06:16 2015 -0800

----------------------------------------------------------------------
 test/couchdb_os_daemons_tests.erl        | 14 +++++---------
 test/fixtures/os_daemon_configer.escript | 13 +++++--------
 2 files changed, 10 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9589b63b/test/couchdb_os_daemons_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_os_daemons_tests.erl b/test/couchdb_os_daemons_tests.erl
index b978e38..fe59005 100644
--- a/test/couchdb_os_daemons_tests.erl
+++ b/test/couchdb_os_daemons_tests.erl
@@ -36,19 +36,17 @@
 -define(TIMEOUT, 1000).
 
 
--ifdef(run_broken_tests).
-
 setup(DName) ->
-    {ok, CfgPid} = config:start_link(?CONFIG_CHAIN),
+    Ctx = test_util:start(?MODULE, [], [{dont_mock, [config]}]),
     {ok, OsDPid} = couch_os_daemons:start_link(),
     config:set("os_daemons", DName,
                      filename:join([?FIXTURESDIR, DName]), false),
     timer:sleep(?DELAY),  % sleep a bit to let daemon set kill flag
-    {CfgPid, OsDPid}.
+    {Ctx, OsDPid}.
 
-teardown(_, {CfgPid, OsDPid}) ->
-    test_util:stop_config(CfgPid),
-    test_util:stop_sync_throw(OsPid, fun() ->
+teardown(_, {Ctx, OsDPid}) ->
+    test_util:stop(Ctx),
+    test_util:stop_sync_throw(OsDPid, fun() ->
         exit(OsDPid, shutdown)
     end, {timeout, os_daemon_stop}, ?TIMEOUT).
 
@@ -215,5 +213,3 @@ check_dead(D, Name) ->
     ?assertEqual(halted, D#daemon.status),
     ?assertEqual(nil, D#daemon.errors),
     ?assertEqual(nil, D#daemon.buf).
-
--endif.

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9589b63b/test/fixtures/os_daemon_configer.escript
----------------------------------------------------------------------
diff --git a/test/fixtures/os_daemon_configer.escript b/test/fixtures/os_daemon_configer.escript
index 0074fc0..3e02ef9 100755
--- a/test/fixtures/os_daemon_configer.escript
+++ b/test/fixtures/os_daemon_configer.escript
@@ -12,19 +12,18 @@
 % License for the specific language governing permissions and limitations under
 % the License.
 
--include("../couch_eunit.hrl").
-
+-include("../../include/couch_eunit.hrl").
 
 read() ->
     case io:get_line('') of
         eof ->
             stop;
         Data ->
-            ejson:decode(Data)
+            jiffy:decode(Data)
     end.
 
 write(Mesg) ->
-    Data = iolist_to_binary(ejson:encode(Mesg)),
+    Data = iolist_to_binary(jiffy:encode(Mesg)),
     io:format(binary_to_list(Data) ++ "\n", []).
 
 get_cfg(Section) ->
@@ -83,19 +82,17 @@ loop({error, _Reason}) ->
 
 main([]) ->
     init_code_path(),
-    config:start_link(?CONFIG_CHAIN),
-    couch_drv:start_link(),
     do_tests().
 
 init_code_path() ->
     Paths = [
         "couchdb",
-        "ejson",
+        "jiffy",
         "erlang-oauth",
         "ibrowse",
         "mochiweb",
         "snappy"
     ],
     lists:foreach(fun(Name) ->
-        code:add_patha(filename:join([?BUILDDIR, "src", Name]))
+        code:add_patha(filename:join([?BUILDDIR(), "src", Name, "ebin"]))
     end, Paths).


[19/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Handle couch_auth_terminate gracefully

In the case when `authentication_db` is changed we will get DOWN message
with the Ref we already forgot. So we keep a list of monitors which we
close but didn't receive DOWN message.

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

Branch: refs/heads/master
Commit: 70049c443098d2f747c6fd5b218092f4eda9a65e
Parents: 7d49860
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Feb 2 11:48:39 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:03:45 2015 -0800

----------------------------------------------------------------------
 src/couch_auth_cache.erl | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/70049c44/src/couch_auth_cache.erl
----------------------------------------------------------------------
diff --git a/src/couch_auth_cache.erl b/src/couch_auth_cache.erl
index 0b15489..a8fdab8 100644
--- a/src/couch_auth_cache.erl
+++ b/src/couch_auth_cache.erl
@@ -38,6 +38,7 @@
     cache_size = 0,
     db_notifier = nil,
     db_mon_ref = nil,
+    closed = [],
     event_listener = nil
 }).
 
@@ -231,8 +232,18 @@ handle_info(restart_event_listener, State) ->
             ?MODULE, handle_db_event, nil, [{dbname, AuthDbName}]
         ),
     {noreply, State#state{event_listener=NewListener}};
+handle_info({'DOWN', Ref, _, _, shutdown}, State) ->
+    {stop, shutdown, State};
 handle_info({'DOWN', Ref, _, _, _Reason}, #state{db_mon_ref = Ref} = State) ->
-    {noreply, reinit_cache(State)}.
+    {noreply, reinit_cache(State)};
+handle_info({'DOWN', Ref, _, _, Reason}, #state{closed = Closed} = State) ->
+    case lists:delete(Ref, Closed) of
+        Closed ->
+            {stop, Reason, State};
+        NewClosed ->
+            {noreply, reinit_cache(State#state{closed = NewClosed})}
+    end.
+
 
 terminate(_Reason, #state{event_listener = Listener}) ->
     couch_event:stop_listener(Listener),
@@ -268,13 +279,14 @@ clear_cache(State) ->
     State#state{cache_size = 0}.
 
 
-reinit_cache(State) ->
+reinit_cache(#state{db_mon_ref = Ref, closed = Closed} = State) ->
     NewState = clear_cache(State),
     AuthDbName = ?l2b(config:get("couch_httpd_auth", "authentication_db")),
     true = ets:insert(?STATE, {auth_db_name, AuthDbName}),
     AuthDb = open_auth_db(),
     true = ets:insert(?STATE, {auth_db, AuthDb}),
-    NewState#state{db_mon_ref = erlang:monitor(process, AuthDb#db.main_pid)}.
+    NewState#state{closed = [Ref|Closed],
+                   db_mon_ref = erlang:monitor(process, AuthDb#db.main_pid)}.
 
 
 add_cache_entry(_, _, _, #state{max_cache_size = 0} = State) ->


[20/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable test suite for couch_auth_cache

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

Branch: refs/heads/master
Commit: 72981ec1be9d6fb5201cc7e8b87d9292219c5fb7
Parents: 70049c4
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Feb 2 11:53:26 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:03:57 2015 -0800

----------------------------------------------------------------------
 test/couch_auth_cache_tests.erl | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/72981ec1/test/couch_auth_cache_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_auth_cache_tests.erl b/test/couch_auth_cache_tests.erl
index dd8fcc9..4223319 100644
--- a/test/couch_auth_cache_tests.erl
+++ b/test/couch_auth_cache_tests.erl
@@ -18,8 +18,9 @@
 -define(SALT, <<"SALT">>).
 -define(TIMEOUT, 1000).
 
+start() ->
+    test_util:start_couch([ioq]).
 
--ifdef(run_broken_tests).
 
 setup() ->
     DbName = ?tempdb(),
@@ -37,7 +38,7 @@ couch_auth_cache_test_() ->
         "CouchDB auth cache tests",
         {
             setup,
-            fun test_util:start_couch/0, fun test_util:stop_couch/1,
+            fun start/0, fun test_util:stop_couch/1,
             {
                 foreach,
                 fun setup/0, fun teardown/1,
@@ -64,7 +65,7 @@ should_get_right_password_hash(DbName) ->
     ?_test(begin
         PasswordHash = hash_password("pass1"),
         {ok, _} = update_user_doc(DbName, "joe", "pass1"),
-        Creds = couch_auth_cache:get_user_creds("joe"),
+        {ok, Creds, _} = couch_auth_cache:get_user_creds("joe"),
         ?assertEqual(PasswordHash,
                       couch_util:get_value(<<"password_sha">>, Creds))
     end).
@@ -72,7 +73,7 @@ should_get_right_password_hash(DbName) ->
 should_ensure_doc_hash_equals_cached_one(DbName) ->
     ?_test(begin
         {ok, _} = update_user_doc(DbName, "joe", "pass1"),
-        Creds = couch_auth_cache:get_user_creds("joe"),
+        {ok, Creds, _} = couch_auth_cache:get_user_creds("joe"),
 
         CachedHash = couch_util:get_value(<<"password_sha">>, Creds),
         StoredHash = get_user_doc_password_sha(DbName, "joe"),
@@ -84,7 +85,7 @@ should_update_password(DbName) ->
         PasswordHash = hash_password("pass2"),
         {ok, Rev} = update_user_doc(DbName, "joe", "pass1"),
         {ok, _} = update_user_doc(DbName, "joe", "pass2", Rev),
-        Creds = couch_auth_cache:get_user_creds("joe"),
+        {ok, Creds, _} = couch_auth_cache:get_user_creds("joe"),
         ?assertEqual(PasswordHash,
                       couch_util:get_value(<<"password_sha">>, Creds))
     end).
@@ -104,7 +105,7 @@ should_restore_cache_after_userdoc_recreation(DbName) ->
         ?assertEqual(nil, couch_auth_cache:get_user_creds("joe")),
 
         {ok, _} = update_user_doc(DbName, "joe", "pass5"),
-        Creds = couch_auth_cache:get_user_creds("joe"),
+        {ok, Creds, _} = couch_auth_cache:get_user_creds("joe"),
 
         ?assertEqual(PasswordHash,
                       couch_util:get_value(<<"password_sha">>, Creds))
@@ -123,7 +124,7 @@ should_restore_cache_on_auth_db_change(DbName) ->
     ?_test(begin
         PasswordHash = hash_password("pass1"),
         {ok, _} = update_user_doc(DbName, "joe", "pass1"),
-        Creds = couch_auth_cache:get_user_creds("joe"),
+        {ok, Creds, _} = couch_auth_cache:get_user_creds("joe"),
         full_commit(DbName),
 
         DbName1 = ?tempdb(),
@@ -136,7 +137,7 @@ should_restore_cache_on_auth_db_change(DbName) ->
         config:set("couch_httpd_auth", "authentication_db",
                          ?b2l(DbName), false),
 
-        Creds = couch_auth_cache:get_user_creds("joe"),
+        {ok, Creds, _} = couch_auth_cache:get_user_creds("joe"),
         ?assertEqual(PasswordHash,
                       couch_util:get_value(<<"password_sha">>, Creds))
     end).
@@ -223,5 +224,3 @@ full_commit(DbName) ->
     {ok, AuthDb} = couch_db:open_int(DbName, [?ADMIN_CTX]),
     {ok, _} = couch_db:ensure_full_commit(AuthDb),
     ok = couch_db:close(AuthDb).
-
--endif.


[37/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable couchdb_update_conflicts_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/65c88d2d
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/65c88d2d
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/65c88d2d

Branch: refs/heads/master
Commit: 65c88d2dfb386cc0a13df26a59b8e89b93e440c0
Parents: 3776aa3
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Feb 5 11:30:15 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:07:22 2015 -0800

----------------------------------------------------------------------
 test/couchdb_update_conflicts_tests.erl | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/65c88d2d/test/couchdb_update_conflicts_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_update_conflicts_tests.erl b/test/couchdb_update_conflicts_tests.erl
index 3409f83..1f810f3 100644
--- a/test/couchdb_update_conflicts_tests.erl
+++ b/test/couchdb_update_conflicts_tests.erl
@@ -20,9 +20,6 @@
 -define(NUM_CLIENTS, [100, 500, 1000, 2000, 5000, 10000]).
 -define(TIMEOUT, 10000).
 
-
--ifdef(run_broken_tests).
-
 start() ->
     Ctx = test_util:start_couch(),
     config:set("couchdb", "delayed_commits", "true", false),
@@ -213,8 +210,8 @@ bulk_delete_create(DbName, InitRev) ->
 
     %% Deleted revision has position 2
     ?assertEqual(2, element(1, Rev1)),
-    %% New leaf revision has position 1
-    ?assertEqual(1, element(1, Rev2)).
+    %% New leaf revision has position 3
+    ?assertEqual(3, element(1, Rev2)).
 
 
 spawn_client(DbName, Doc) ->
@@ -232,5 +229,3 @@ spawn_client(DbName, Doc) ->
         ok = couch_db:close(Db),
         exit(Result)
     end).
-
--endif.


[47/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Fix race in couch_work_queue_test

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

Branch: refs/heads/master
Commit: 17fa5856ab12d9853e3155419c887b69db1559a9
Parents: 15db2b4
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Fri Mar 6 14:29:58 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Fri Mar 6 14:29:58 2015 -0800

----------------------------------------------------------------------
 test/couch_work_queue_tests.erl | 62 ++++++++++++++++++++++--------------
 1 file changed, 38 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/17fa5856/test/couch_work_queue_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_work_queue_tests.erl b/test/couch_work_queue_tests.erl
index 86ea1b9..96be7da 100644
--- a/test/couch_work_queue_tests.erl
+++ b/test/couch_work_queue_tests.erl
@@ -157,17 +157,17 @@ should_block_consumer_on_dequeue_from_empty_queue({_, _, Consumer}) ->
 should_consume_right_item({Q, Producer, Consumers}) when is_list(Consumers) ->
     [consume(C, 3) || C <- Consumers],
 
-    Item1 = produce(Producer, 10),
+    Item1 = produce(Q, Producer, 10, false),
     ok = ping(Producer),
     ?assertEqual(0, couch_work_queue:item_count(Q)),
     ?assertEqual(0, couch_work_queue:size(Q)),
 
-    Item2 = produce(Producer, 10),
+    Item2 = produce(Q, Producer, 10, false),
     ok = ping(Producer),
     ?assertEqual(0, couch_work_queue:item_count(Q)),
     ?assertEqual(0, couch_work_queue:size(Q)),
 
-    Item3 = produce(Producer, 10),
+    Item3 = produce(Q, Producer, 10, false),
     ok = ping(Producer),
     ?assertEqual(0, couch_work_queue:item_count(Q)),
     ?assertEqual(0, couch_work_queue:size(Q)),
@@ -176,60 +176,60 @@ should_consume_right_item({Q, Producer, Consumers}) when is_list(Consumers) ->
          || {C, Item} <- lists:zip(Consumers, [Item1, Item2, Item3])],
 
     ?_assertEqual([{ok, Item1}, {ok, Item2}, {ok, Item3}], R);
-should_consume_right_item({_, Producer, Consumer}) ->
+should_consume_right_item({Q, Producer, Consumer}) ->
     consume(Consumer, 1),
-    Item = produce(Producer, 10),
-    produce(Producer, 20),
+    Item = produce(Q, Producer, 10, false),
+    produce(Q, Producer, 20, true),
     ok = ping(Producer),
     ok = ping(Consumer),
     {ok, Items} = last_consumer_items(Consumer),
     ?_assertEqual([Item], Items).
 
 should_increase_queue_size_on_produce({Q, Producer, _}) ->
-    produce(Producer, 50),
+    produce(Q, Producer, 50, true),
     ok = ping(Producer),
     Count1 = couch_work_queue:item_count(Q),
     Size1 = couch_work_queue:size(Q),
 
-    produce(Producer, 10),
+    produce(Q, Producer, 10, true),
     Count2 = couch_work_queue:item_count(Q),
     Size2 = couch_work_queue:size(Q),
 
     ?_assertEqual([{Count1, Size1}, {Count2, Size2}], [{1, 50}, {2, 60}]).
 
 should_block_producer_on_full_queue_count({Q, Producer, _}) ->
-    produce(Producer, 10),
+    produce(Q, Producer, 10, true),
     ?assertEqual(1, couch_work_queue:item_count(Q)),
     ok = ping(Producer),
 
-    produce(Producer, 15),
+    produce(Q, Producer, 15, true),
     ?assertEqual(2, couch_work_queue:item_count(Q)),
     ok = ping(Producer),
 
-    produce(Producer, 20),
+    produce(Q, Producer, 20, false),
     ?assertEqual(3, couch_work_queue:item_count(Q)),
     Pong = ping(Producer),
 
     ?_assertEqual(timeout, Pong).
 
 should_block_producer_on_full_queue_size({Q, Producer, _}) ->
-    produce(Producer, 100),
+    produce(Q, Producer, 100, true),
     ok = ping(Producer),
     ?assertEqual(1, couch_work_queue:item_count(Q)),
     ?assertEqual(100, couch_work_queue:size(Q)),
 
-    produce(Producer, 110),
+    produce(Q, Producer, 110, false),
     Pong = ping(Producer),
     ?assertEqual(2, couch_work_queue:item_count(Q)),
     ?assertEqual(210, couch_work_queue:size(Q)),
 
     ?_assertEqual(timeout, Pong).
 
-should_consume_multiple_items({_, Producer, Consumer}) ->
-    Item1 = produce(Producer, 10),
+should_consume_multiple_items({Q, Producer, Consumer}) ->
+    Item1 = produce(Q, Producer, 10, true),
     ok = ping(Producer),
 
-    Item2 = produce(Producer, 15),
+    Item2 = produce(Q, Producer, 15, true),
     ok = ping(Producer),
 
     consume(Consumer, 2),
@@ -241,7 +241,7 @@ should_receive_first_queued_item({Q, Producer, Consumer}) ->
     consume(Consumer, 100),
     timeout = ping(Consumer),
 
-    Item = produce(Producer, 11),
+    Item = produce(Q, Producer, 11, false),
     ok = ping(Producer),
 
     ok = ping(Consumer),
@@ -250,10 +250,10 @@ should_receive_first_queued_item({Q, Producer, Consumer}) ->
     {ok, Items} = last_consumer_items(Consumer),
     ?_assertEqual([Item], Items).
 
-should_consume_all({_, Producer, Consumer}) ->
-    Item1 = produce(Producer, 10),
-    Item2 = produce(Producer, 15),
-    Item3 = produce(Producer, 20),
+should_consume_all({Q, Producer, Consumer}) ->
+    Item1 = produce(Q, Producer, 10, true),
+    Item2 = produce(Q, Producer, 15, true),
+    Item3 = produce(Q, Producer, 20, true),
 
     consume(Consumer, all),
 
@@ -261,13 +261,13 @@ should_consume_all({_, Producer, Consumer}) ->
     ?_assertEqual([Item1, Item2, Item3], Items).
 
 should_timeout_on_close_non_empty_queue({Q, Producer, _}) ->
-    produce(Producer, 1),
+    produce(Q, Producer, 1, true),
     Status = close_queue(Q),
 
     ?_assertEqual(timeout, Status).
 
 should_not_block_producer_for_non_empty_queue_after_close({Q, Producer, _}) ->
-    produce(Producer, 1),
+    produce(Q, Producer, 1, true),
     close_queue(Q),
     Pong = ping(Producer),
     Size = couch_work_queue:size(Q),
@@ -354,10 +354,14 @@ last_consumer_items(Consumer) ->
         timeout
     end.
 
-produce(Producer, Size) ->
+produce(Q, Producer, Size, Wait) ->
     Ref = make_ref(),
+    ItemsCount = couch_work_queue:item_count(Q),
     Producer ! {produce, Ref, Size},
     receive
+        {item, Ref, Item} when Wait ->
+            ok = wait_increment(Q, ItemsCount),
+            Item;
         {item, Ref, Item} ->
             Item
     after ?TIMEOUT ->
@@ -386,3 +390,13 @@ stop(Pid, Name) ->
         ?debugMsg("Timeout stopping " ++ Name),
         timeout
     end.
+
+wait_increment(Q, ItemsCount) ->
+    test_util:wait(fun() ->
+       case couch_work_queue:item_count(Q) > ItemsCount of
+           true ->
+               ok;
+           false ->
+               wait
+       end
+    end).


[02/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Return started from test_util:start_applications

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

Branch: refs/heads/master
Commit: 9af979fea817d27c53dc7200469889b27ab7cf7d
Parents: b510c21
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 08:26:00 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:31:40 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9af979fe/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index 60fa735..07bbeb0 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -106,22 +106,23 @@ stop_couch() ->
 stop_couch(_) ->
     stop_couch().
 
-
-start_applications([]) ->
-    ok;
-start_applications([App|Apps]) ->
-    case application:start(App) of
+start_applications(Apps) ->
+    start_applications(Apps, []).
+
+start_applications([], Acc) ->
+    lists:reverse(Acc);
+start_applications([App|Apps], Acc) ->
+    NewAcc =
+        case application:start(App) of
         {error, {already_started, _}} ->
-            ok;
+            start_applications(Apps, Acc);
         {error, {not_started, Dep}} ->
-            start_applications([Dep, App | Apps]);
+            start_applications([Dep, App | Apps], Acc);
         {error, {not_running, Dep}} ->
-            start_applications([Dep, App | Apps]);
+            start_applications([Dep, App | Apps], Acc);
         ok ->
-            ok
-    end,
-    start_applications(Apps).
-
+            start_applications(Apps, [App|Acc])
+    end.
 
 start_config(Chain) ->
     case config:start_link(Chain) of


[35/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Rename function arguments for clarity.

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

Branch: refs/heads/master
Commit: 51eec4a2f3d4dd529e8336ff42650f1095222c1e
Parents: 7cc94fa
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Feb 5 11:25:46 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:07:06 2015 -0800

----------------------------------------------------------------------
 src/couch_db.erl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/51eec4a2/src/couch_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_db.erl b/src/couch_db.erl
index 63aef55..ae80123 100644
--- a/src/couch_db.erl
+++ b/src/couch_db.erl
@@ -118,8 +118,8 @@ ensure_full_commit(Db, RequiredSeq) ->
     ok = gen_server:call(Pid, {full_commit, RequiredSeq}, infinity),
     {ok, StartTime}.
 
-close(#db{fd_monitor=RefCntr}) ->
-    erlang:demonitor(RefCntr, [flush]),
+close(#db{fd_monitor=Ref}) ->
+    erlang:demonitor(Ref, [flush]),
     ok.
 
 is_idle(#db{compactor_pid=nil, waiting_delayed_commit=nil} = Db) ->


[40/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable couchdb_views_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/d48664f4
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/d48664f4
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/d48664f4

Branch: refs/heads/master
Commit: d48664f4cd9f9c73f0173fcaaef942aa1bf394da
Parents: 2f51245
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 10 10:01:59 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:07:43 2015 -0800

----------------------------------------------------------------------
 test/couchdb_views_tests.erl | 284 +++++++++++++++++++++-----------------
 1 file changed, 158 insertions(+), 126 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/d48664f4/test/couchdb_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_views_tests.erl b/test/couchdb_views_tests.erl
index 436e625..f4764bf 100644
--- a/test/couchdb_views_tests.erl
+++ b/test/couchdb_views_tests.erl
@@ -19,9 +19,6 @@
 -define(DELAY, 100).
 -define(TIMEOUT, 1000).
 
-
--ifdef(run_broken_tests).
-
 setup() ->
     DbName = ?tempdb(),
     {ok, Db} = couch_db:create(DbName, [?ADMIN_CTX]),
@@ -40,12 +37,45 @@ setup_with_docs() ->
     create_design_doc(DbName, <<"_design/foo">>, <<"bar">>),
     DbName.
 
+setup_legacy() ->
+    DbName = <<"test">>,
+    DbFileName = "test.couch",
+    OldDbFilePath = filename:join([?FIXTURESDIR, DbFileName]),
+    OldViewName = "3b835456c235b1827e012e25666152f3.view",
+    FixtureViewFilePath = filename:join([?FIXTURESDIR, OldViewName]),
+    NewViewName = "6cf2c2f766f87b618edf6630b00f8736.view",
+
+    DbDir = config:get("couchdb", "database_dir"),
+    ViewDir = config:get("couchdb", "view_index_dir"),
+    OldViewFilePath = filename:join([ViewDir, ".test_design", OldViewName]),
+    NewViewFilePath = filename:join([ViewDir, ".test_design", "mrview",
+                                     NewViewName]),
+
+    NewDbFilePath = filename:join([DbDir, DbFileName]),
+
+    Files = [NewDbFilePath, OldViewFilePath, NewViewFilePath],
+
+    %% make sure there is no left over
+    lists:foreach(fun(File) -> file:delete(File) end, Files),
+
+    % copy old db file into db dir
+    {ok, _} = file:copy(OldDbFilePath, NewDbFilePath),
+
+    % copy old view file into view dir
+    ok = filelib:ensure_dir(OldViewFilePath),
+
+    {ok, _} = file:copy(FixtureViewFilePath, OldViewFilePath),
+
+    {DbName, Files}.
+
 teardown({DbName, _}) ->
     teardown(DbName);
 teardown(DbName) when is_binary(DbName) ->
     couch_server:delete(DbName, [?ADMIN_CTX]),
     ok.
 
+teardown_legacy({_DbName, Files}) ->
+    lists:foreach(fun(File) -> file:delete(File) end, Files).
 
 view_indexes_cleanup_test_() ->
     {
@@ -92,93 +122,91 @@ view_group_shutdown_test_() ->
         }
     }.
 
+backup_restore_test_() ->
+    {
+        "Upgrade and bugs related tests",
+        {
+            setup,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
+            {
+                foreach,
+                fun setup_with_docs/0, fun teardown/1,
+                [
+                    fun should_not_remember_docs_in_index_after_backup_restore/1
+                ]
+            }
+        }
+    }.
 
-should_not_remember_docs_in_index_after_backup_restore_test() ->
-    %% COUCHDB-640
-    start(),
-    DbName = setup_with_docs(),
-
-    ok = backup_db_file(DbName),
-    create_doc(DbName, "doc666"),
-
-    Rows0 = query_view(DbName, "foo", "bar"),
-    ?assert(has_doc("doc1", Rows0)),
-    ?assert(has_doc("doc2", Rows0)),
-    ?assert(has_doc("doc3", Rows0)),
-    ?assert(has_doc("doc666", Rows0)),
-
-    restore_backup_db_file(DbName),
-
-    Rows1 = query_view(DbName, "foo", "bar"),
-    ?assert(has_doc("doc1", Rows1)),
-    ?assert(has_doc("doc2", Rows1)),
-    ?assert(has_doc("doc3", Rows1)),
-    ?assertNot(has_doc("doc666", Rows1)),
-
-    teardown(DbName),
-    stop(whereis(couch_server_sup)).
-
-
-should_upgrade_legacy_view_files_test() ->
-    start(),
 
-    ok = config:set("query_server_config", "commit_freq", "0", false),
+upgrade_test_() ->
+    {
+        "Upgrade tests",
+        {
+            setup,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
+            {
+                foreach,
+                fun setup_legacy/0, fun teardown_legacy/1,
+                [
+                    fun should_upgrade_legacy_view_files/1
+                ]
+            }
+        }
+    }.
 
-    DbName = <<"test">>,
-    DbFileName = "test.couch",
-    DbFilePath = filename:join([?FIXTURESDIR, DbFileName]),
-    OldViewName = "3b835456c235b1827e012e25666152f3.view",
-    FixtureViewFilePath = filename:join([?FIXTURESDIR, OldViewName]),
-    NewViewName = "a1c5929f912aca32f13446122cc6ce50.view",
+should_not_remember_docs_in_index_after_backup_restore(DbName) ->
+    ?_test(begin
+        %% COUCHDB-640
 
-    DbDir = config:get("couchdb", "database_dir"),
-    ViewDir = config:get("couchdb", "view_index_dir"),
-    OldViewFilePath = filename:join([ViewDir, ".test_design", OldViewName]),
-    NewViewFilePath = filename:join([ViewDir, ".test_design", "mrview",
-                                     NewViewName]),
+        ok = backup_db_file(DbName),
+        create_doc(DbName, "doc666"),
 
-    % cleanup
-    Files = [
-        filename:join([DbDir, DbFileName]),
-        OldViewFilePath,
-        NewViewFilePath
-    ],
-    lists:foreach(fun(File) -> file:delete(File) end, Files),
+        Rows0 = query_view(DbName, "foo", "bar"),
+        ?assert(has_doc("doc1", Rows0)),
+        ?assert(has_doc("doc2", Rows0)),
+        ?assert(has_doc("doc3", Rows0)),
+        ?assert(has_doc("doc666", Rows0)),
 
-    % copy old db file into db dir
-    {ok, _} = file:copy(DbFilePath, filename:join([DbDir, DbFileName])),
+        restore_backup_db_file(DbName),
 
-    % copy old view file into view dir
-    ok = filelib:ensure_dir(filename:join([ViewDir, ".test_design"])),
-    {ok, _} = file:copy(FixtureViewFilePath, OldViewFilePath),
+        Rows1 = query_view(DbName, "foo", "bar"),
+        ?assert(has_doc("doc1", Rows1)),
+        ?assert(has_doc("doc2", Rows1)),
+        ?assert(has_doc("doc3", Rows1)),
+        ?assertNot(has_doc("doc666", Rows1))
+      end).
 
-    % ensure old header
-    OldHeader = read_header(OldViewFilePath),
-    ?assertMatch(#index_header{}, OldHeader),
+should_upgrade_legacy_view_files({DbName, Files}) ->
+    ?_test(begin
+        [_NewDbFilePath, OldViewFilePath, NewViewFilePath] = Files,
+        ok = config:set("query_server_config", "commit_freq", "0", false),
 
-    % query view for expected results
-    Rows0 = query_view(DbName, "test", "test"),
-    ?assertEqual(2, length(Rows0)),
+        % ensure old header
+        OldHeader = read_header(OldViewFilePath),
+        ?assertMatch(#index_header{}, OldHeader),
 
-    % ensure old file gone
-    ?assertNot(filelib:is_regular(OldViewFilePath)),
+        % query view for expected results
+        Rows0 = query_view(DbName, "test", "test"),
+        ?assertEqual(2, length(Rows0)),
 
-    % add doc to trigger update
-    DocUrl = db_url(DbName) ++ "/boo",
-    {ok, _, _, _} = test_request:put(
-        DocUrl, [{"Content-Type", "application/json"}], <<"{\"a\":3}">>),
+        % ensure old file gone
+        ?assertNot(filelib:is_regular(OldViewFilePath)),
 
-    % query view for expected results
-    Rows1 = query_view(DbName, "test", "test"),
-    ?assertEqual(3, length(Rows1)),
+        % add doc to trigger update
+        DocUrl = db_url(DbName) ++ "/boo",
+        {ok, _, _, _} = test_request:put(
+            DocUrl, [{"Content-Type", "application/json"}], <<"{\"a\":3}">>),
 
-    % ensure new header
-    timer:sleep(2000),  % have to wait for awhile to upgrade the index
-    NewHeader = read_header(NewViewFilePath),
-    ?assertMatch(#mrheader{}, NewHeader),
+        % query view for expected results
+        Rows1 = query_view(DbName, "test", "test"),
+        ?assertEqual(3, length(Rows1)),
 
-    teardown(DbName),
-    stop(whereis(couch_server_sup)).
+        % ensure new header
+        timer:sleep(2000),  % have to wait for awhile to upgrade the index
+        NewHeader = read_header(NewViewFilePath),
+        ?assertMatch(#mrheader{}, NewHeader)
+    end).
 
 
 should_have_two_indexes_alive_before_deletion({DbName, _}) ->
@@ -202,37 +230,35 @@ couchdb_1138(DbName) ->
             couch_mrview_index, DbName, <<"_design/foo">>),
         ?assert(is_pid(IndexerPid)),
         ?assert(is_process_alive(IndexerPid)),
-        ?assertEqual(2, count_db_refs(DbName)),
+        ?assertEqual(2, count_users(DbName)),
+
+        wait_indexer(IndexerPid),
 
         Rows0 = query_view(DbName, "foo", "bar"),
         ?assertEqual(3, length(Rows0)),
-        ?assertEqual(2, count_db_refs(DbName)),
+        ?assertEqual(2, count_users(DbName)),
         ?assert(is_process_alive(IndexerPid)),
 
         create_doc(DbName, "doc1000"),
         Rows1 = query_view(DbName, "foo", "bar"),
         ?assertEqual(4, length(Rows1)),
-        ?assertEqual(2, count_db_refs(DbName)),
+        ?assertEqual(2, count_users(DbName)),
+
         ?assert(is_process_alive(IndexerPid)),
 
-        Ref1 = get_db_ref_counter(DbName),
         compact_db(DbName),
-        Ref2 = get_db_ref_counter(DbName),
-        ?assertEqual(2, couch_ref_counter:count(Ref2)),
-        ?assertNotEqual(Ref2, Ref1),
-        ?assertNot(is_process_alive(Ref1)),
         ?assert(is_process_alive(IndexerPid)),
 
         compact_view_group(DbName, "foo"),
-        ?assertEqual(2, count_db_refs(DbName)),
-        Ref3 = get_db_ref_counter(DbName),
-        ?assertEqual(Ref3, Ref2),
+        ?assertEqual(2, count_users(DbName)),
+
         ?assert(is_process_alive(IndexerPid)),
 
         create_doc(DbName, "doc1001"),
         Rows2 = query_view(DbName, "foo", "bar"),
         ?assertEqual(5, length(Rows2)),
-        ?assertEqual(2, count_db_refs(DbName)),
+        ?assertEqual(2, count_users(DbName)),
+
         ?assert(is_process_alive(IndexerPid))
     end).
 
@@ -242,13 +268,16 @@ couchdb_1309(DbName) ->
             couch_mrview_index, DbName, <<"_design/foo">>),
         ?assert(is_pid(IndexerPid)),
         ?assert(is_process_alive(IndexerPid)),
-        ?assertEqual(2, count_db_refs(DbName)),
+        ?assertEqual(2, count_users(DbName)),
+
+        wait_indexer(IndexerPid),
 
         create_doc(DbName, "doc1001"),
         Rows0 = query_view(DbName, "foo", "bar"),
         check_rows_value(Rows0, null),
         ?assertEqual(4, length(Rows0)),
-        ?assertEqual(2, count_db_refs(DbName)),
+        ?assertEqual(2, count_users(DbName)),
+
         ?assert(is_process_alive(IndexerPid)),
 
         update_design_doc(DbName,  <<"_design/foo">>, <<"bar">>),
@@ -257,7 +286,7 @@ couchdb_1309(DbName) ->
         ?assert(is_pid(NewIndexerPid)),
         ?assert(is_process_alive(NewIndexerPid)),
         ?assertNotEqual(IndexerPid, NewIndexerPid),
-        ?assertEqual(2, count_db_refs(DbName)),
+        ?assertEqual(2, count_users(DbName)),
 
         Rows1 = query_view(DbName, "foo", "bar", ok),
         ?assertEqual(0, length(Rows1)),
@@ -265,28 +294,15 @@ couchdb_1309(DbName) ->
         check_rows_value(Rows2, 1),
         ?assertEqual(4, length(Rows2)),
 
-        MonRef0 = erlang:monitor(process, IndexerPid),
-        receive
-            {'DOWN', MonRef0, _, _, _} ->
-                ok
-        after ?TIMEOUT ->
-            erlang:error(
-                {assertion_failed,
-                 [{module, ?MODULE}, {line, ?LINE},
-                  {reason, "old view group is not dead after ddoc update"}]})
-        end,
+        ok = stop_indexer( %% FIXME we need to grab monitor earlier
+               fun() -> ok end,
+               IndexerPid, ?LINE,
+               "old view group is not dead after ddoc update"),
 
-        MonRef1 = erlang:monitor(process, NewIndexerPid),
-        ok = couch_server:delete(DbName, [?ADMIN_CTX]),
-        receive
-            {'DOWN', MonRef1, _, _, _} ->
-                ok
-        after ?TIMEOUT ->
-            erlang:error(
-                {assertion_failed,
-                 [{module, ?MODULE}, {line, ?LINE},
-                  {reason, "new view group did not die after DB deletion"}]})
-        end
+        ok = stop_indexer(
+               fun() -> couch_server:delete(DbName, [?ADMIN_USER]) end,
+               NewIndexerPid, ?LINE,
+               "new view group did not die after DB deletion")
     end).
 
 couchdb_1283() ->
@@ -493,18 +509,11 @@ view_cleanup(DbName) ->
     couch_mrview:cleanup(Db),
     couch_db:close(Db).
 
-get_db_ref_counter(DbName) ->
-    {ok, #db{fd_ref_counter = Ref} = Db} = couch_db:open_int(DbName, []),
+count_users(DbName) ->
+    {ok, Db} = couch_db:open_int(DbName, [?ADMIN_CTX]),
+    {monitored_by, Monitors} = erlang:process_info(Db#db.main_pid, monitored_by),
     ok = couch_db:close(Db),
-    Ref.
-
-count_db_refs(DbName) ->
-    Ref = get_db_ref_counter(DbName),
-    % have to sleep a bit to let couchdb cleanup all refs and leave only
-    % active ones. otherwise the related tests will randomly fail due to
-    % count number mismatch
-    timer:sleep(200),
-    couch_ref_counter:count(Ref).
+    length(lists:usort(Monitors) -- [self()]).
 
 count_index_files(DbName) ->
     % call server to fetch the index files
@@ -524,11 +533,14 @@ backup_db_file(DbName) ->
 
 restore_backup_db_file(DbName) ->
     DbDir = config:get("couchdb", "database_dir"),
-    stop(whereis(couch_server_sup)),
+
+    {ok, Db} = couch_db:open_int(DbName, []),
+    ok = couch_db:close(Db),
+    exit(Db#db.main_pid, shutdown),
+
     DbFile = filename:join([DbDir, ?b2l(DbName) ++ ".couch"]),
     ok = file:delete(DbFile),
     ok = file:rename(DbFile ++ ".backup", DbFile),
-    start(),
     ok.
 
 compact_db(DbName) ->
@@ -655,4 +667,24 @@ read_header(File) ->
     couch_file:close(Fd),
     Header.
 
--endif.
+stop_indexer(StopFun, Pid, Line, Reason) ->
+    case test_util:stop_sync(Pid, StopFun) of
+    timeout ->
+        erlang:error(
+            {assertion_failed,
+             [{module, ?MODULE}, {line, Line},
+              {reason, Reason}]});
+    ok ->
+        ok
+    end.
+
+wait_indexer(IndexerPid) ->
+    test_util:wait(fun() ->
+        {ok, Info} = couch_index:get_info(IndexerPid),
+        case couch_util:get_value(compact_running, Info) of
+            true ->
+                wait;
+            false ->
+                ok
+        end
+    end).


[04/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Implement test_util:stop_sync

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

Branch: refs/heads/master
Commit: cacca040a28668e69829c21f3e2279a2f00c1f04
Parents: 4529e12
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 08:32:39 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:36:16 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/cacca040/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index acf8b3d..219cf6b 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -22,6 +22,8 @@
 -export([start_config/1, stop_config/1]).
 -export([start_applications/1]).
 
+-export([stop_sync/1, stop_sync/2, stop_sync/3]).
+
 
 srcdir() ->
     code:priv_dir(couch) ++ "/../../".
@@ -114,3 +116,30 @@ stop_config(Pid) ->
     after Timeout ->
         throw({timeout_error, config_stop})
     end.
+
+stop_sync(Name) ->
+    stop_sync(Name, shutdown).
+stop_sync(Name, Reason) ->
+    stop_sync(Name, Reason, 5000).
+
+stop_sync(Name, Reason, Timeout) when is_atom(Name) ->
+    stop_sync(whereis(Name), Reason, Timeout);
+stop_sync(Pid, Reason, Timeout) when is_atom(Reason) and is_pid(Pid) ->
+    stop_sync(Pid, fun() -> exit(Pid, Reason) end, Timeout);
+stop_sync(Pid, Fun, Timeout) when is_function(Fun) and is_pid(Pid) ->
+    MRef = erlang:monitor(process, Pid),
+    try
+        begin
+            catch unlink(Pid),
+            Res = (catch Fun()),
+            receive
+            {'DOWN', MRef, _, _, _} ->
+                Res
+            after Timeout ->
+                timeout
+            end
+        end
+    after
+        erlang:demonitor(MRef, [flush])
+    end;
+stop_sync(_, _, _) -> error(badarg).


[17/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Use test_util:start in test suite

Use test_util:start in setup fixture of tests.
We also add ioq to list of dependencies for some 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/061c5304
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/061c5304
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/061c5304

Branch: refs/heads/master
Commit: 061c5304f4aac97a56faf89d1dd21d003dea3572
Parents: a78267b
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Feb 2 06:57:44 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:03:19 2015 -0800

----------------------------------------------------------------------
 test/couch_btree_tests.erl  | 94 +++++++++++++++++++++++-----------------
 test/couch_stream_tests.erl | 30 +++++++------
 test/couchdb_cors_tests.erl |  2 +-
 3 files changed, 73 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/061c5304/test/couch_btree_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_btree_tests.erl b/test/couch_btree_tests.erl
index 60469cf..35cf416 100644
--- a/test/couch_btree_tests.erl
+++ b/test/couch_btree_tests.erl
@@ -86,9 +86,13 @@ sorted_kvs_test_() ->
     {
         "BTree with sorted keys",
         {
-            foreachx,
-            fun setup_kvs/1, fun teardown/2,
-            [{Sorted, Fun} || Fun <- Funs]
+            setup,
+            fun() -> test_util:start(?MODULE, [ioq]) end, fun test_util:stop/1,
+            {
+                foreachx,
+                fun setup_kvs/1, fun teardown/2,
+                [{Sorted, Fun} || Fun <- Funs]
+            }
         }
     }.
 
@@ -99,9 +103,13 @@ rsorted_kvs_test_() ->
     {
         "BTree with backward sorted keys",
         {
-            foreachx,
-            fun setup_kvs/1, fun teardown/2,
-            [{Reversed, Fun} || Fun <- Funs]
+            setup,
+            fun() -> test_util:start(?MODULE, [ioq]) end, fun test_util:stop/1,
+            {
+                foreachx,
+                fun setup_kvs/1, fun teardown/2,
+                [{Reversed, Fun} || Fun <- Funs]
+            }
         }
     }.
 
@@ -112,50 +120,58 @@ shuffled_kvs_test_() ->
     {
         "BTree with shuffled keys",
         {
-            foreachx,
-            fun setup_kvs/1, fun teardown/2,
-            [{Shuffled, Fun} || Fun <- Funs]
+            setup,
+            fun() -> test_util:start(?MODULE, [ioq]) end, fun test_util:stop/1,
+            {
+                foreachx,
+                fun setup_kvs/1, fun teardown/2,
+                [{Shuffled, Fun} || Fun <- Funs]
+            }
         }
     }.
 
 reductions_test_() ->
     {
         "BTree reductions",
-        [
-            {
-                "Common tests",
+        {
+            setup,
+            fun() -> test_util:start(?MODULE, [ioq]) end, fun test_util:stop/1,
+            [
                 {
-                    foreach,
-                    fun setup_red/0, fun teardown/1,
-                    [
-                        fun should_reduce_without_specified_direction/1,
-                        fun should_reduce_forward/1,
-                        fun should_reduce_backward/1
-                    ]
-                }
-            },
-            {
-                "Range requests",
-                [
+                    "Common tests",
                     {
-                        "Forward direction",
+                        foreach,
+                        fun setup_red/0, fun teardown/1,
+                        [
+                            fun should_reduce_without_specified_direction/1,
+                            fun should_reduce_forward/1,
+                            fun should_reduce_backward/1
+                        ]
+                    }
+                },
+                {
+                    "Range requests",
+                    [
                         {
-                            foreachx,
-                            fun setup_red/1, fun teardown/2,
-                            [{fwd, F} || F <- red_test_funs()]
-                        }
-                    },
-                    {
-                        "Backward direction",
+                            "Forward direction",
+                            {
+                                foreachx,
+                                fun setup_red/1, fun teardown/2,
+                                [{fwd, F} || F <- red_test_funs()]
+                            }
+                        },
                         {
-                            foreachx,
-                            fun setup_red/1, fun teardown/2,
-                            [{rev, F} || F <- red_test_funs()]
+                            "Backward direction",
+                            {
+                                foreachx,
+                                fun setup_red/1, fun teardown/2,
+                                [{rev, F} || F <- red_test_funs()]
+                            }
                         }
-                    }
-                ]
-            }
-        ]
+                    ]
+                }
+            ]
+        }
     }.
 
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/061c5304/test/couch_stream_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_stream_tests.erl b/test/couch_stream_tests.erl
index e12e714..e842c86 100644
--- a/test/couch_stream_tests.erl
+++ b/test/couch_stream_tests.erl
@@ -28,19 +28,23 @@ stream_test_() ->
     {
         "CouchDB stream tests",
         {
-            foreach,
-            fun setup/0, fun teardown/1,
-            [
-                fun should_write/1,
-                fun should_write_consecutive/1,
-                fun should_write_empty_binary/1,
-                fun should_return_file_pointers_on_close/1,
-                fun should_return_stream_size_on_close/1,
-                fun should_return_valid_pointers/1,
-                fun should_recall_last_pointer_position/1,
-                fun should_stream_more_with_4K_chunk_size/1,
-                fun should_stop_on_normal_exit_of_stream_opener/1
-            ]
+            setup,
+            fun() -> test_util:start(?MODULE, [ioq]) end, fun test_util:stop/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_write/1,
+                    fun should_write_consecutive/1,
+                    fun should_write_empty_binary/1,
+                    fun should_return_file_pointers_on_close/1,
+                    fun should_return_stream_size_on_close/1,
+                    fun should_return_valid_pointers/1,
+                    fun should_recall_last_pointer_position/1,
+                    fun should_stream_more_with_4K_chunk_size/1,
+                    fun should_stop_on_normal_exit_of_stream_opener/1
+                ]
+            }
         }
     }.
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/061c5304/test/couchdb_cors_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_cors_tests.erl b/test/couchdb_cors_tests.erl
index 5d4bc83..4b2e2b5 100644
--- a/test/couchdb_cors_tests.erl
+++ b/test/couchdb_cors_tests.erl
@@ -22,7 +22,7 @@
 
 
 start() ->
-    Ctx = test_util:start_couch(),
+    Ctx = test_util:start_couch([ioq]),
     ok = config:set("httpd", "enable_cors", "true", false),
     ok = config:set("vhosts", "example.com", "/", false),
     Ctx.


[22/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Enable couch_doc_json_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/b59b529e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/b59b529e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/b59b529e

Branch: refs/heads/master
Commit: b59b529e59c072939d2c327f86401ad2d30a5e98
Parents: 5331056
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Mon Feb 2 12:24:59 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:04:24 2015 -0800

----------------------------------------------------------------------
 test/couch_doc_json_tests.erl | 108 ++++++++++++++++---------------------
 1 file changed, 47 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b59b529e/test/couch_doc_json_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_doc_json_tests.erl b/test/couch_doc_json_tests.erl
index 20010ac..56587cd 100644
--- a/test/couch_doc_json_tests.erl
+++ b/test/couch_doc_json_tests.erl
@@ -16,21 +16,10 @@
 -include_lib("couch/include/couch_db.hrl").
 
 
--ifdef(run_broken_tests).
-
-setup() ->
-    {ok, Pid} = test_util:start_config(?CONFIG_CHAIN),
-    config:set("attachments", "compression_level", "0", false),
-    Pid.
-
-teardown(_) ->
-    test_util:stop_config().
-
-
 json_doc_test_() ->
     {
         setup,
-        fun setup/0, fun teardown/1,
+        fun() -> test_util:start(?MODULE) end, fun test_util:stop/1,
         [
             {
                 "Document from JSON",
@@ -93,22 +82,22 @@ from_json_success_cases() ->
                 ]}}
             ]}}]},
             #doc{atts = [
-                #att{
-                    name = <<"my_attachment.fu">>,
-                    data = stub,
-                    type = <<"application/awesome">>,
-                    att_len = 45,
-                    disk_len = 45,
-                    revpos = nil
-                },
-                #att{
-                    name = <<"noahs_private_key.gpg">>,
-                    data = <<"I have a pet fish!">>,
-                    type = <<"application/pgp-signature">>,
-                    att_len = 18,
-                    disk_len = 18,
-                    revpos = 0
-                }
+                couch_att:new([
+                    {name, <<"my_attachment.fu">>},
+                    {data, stub},
+                    {type, <<"application/awesome">>},
+                    {att_len, 45},
+                    {disk_len, 45},
+                    {revpos, undefined}
+                ]),
+                couch_att:new([
+                    {name, <<"noahs_private_key.gpg">>},
+                    {data, <<"I have a pet fish!">>},
+                    {type, <<"application/pgp-signature">>},
+                    {att_len, 18},
+                    {disk_len, 18},
+                    {revpos, 0}
+                ])
             ]},
             "Attachments are parsed correctly."
         },
@@ -312,22 +301,22 @@ to_json_success_cases() ->
         },
         {
             #doc{atts = [
-                #att{
-                    name = <<"big.xml">>,
-                    type = <<"xml/sucks">>,
-                    data = fun() -> ok end,
-                    revpos = 1,
-                    att_len = 400,
-                    disk_len = 400
-                },
-                #att{
-                    name = <<"fast.json">>,
-                    type = <<"json/ftw">>,
-                    data = <<"{\"so\": \"there!\"}">>,
-                    revpos = 1,
-                    att_len = 16,
-                    disk_len = 16
-                }
+                couch_att:new([
+                    {name, <<"big.xml">>},
+                    {type, <<"xml/sucks">>},
+                    {data, fun() -> ok end},
+                    {revpos, 1},
+                    {att_len, 400},
+                    {disk_len, 400}
+                ]),
+                couch_att:new([
+                    {name, <<"fast.json">>},
+                    {type, <<"json/ftw">>},
+                    {data, <<"{\"so\": \"there!\"}">>},
+                    {revpos, 1},
+                    {att_len, 16},
+                    {disk_len, 16}
+                ])
             ]},
             {[
                  {<<"_id">>, <<>>},
@@ -351,20 +340,20 @@ to_json_success_cases() ->
         {
             [attachments],
             #doc{atts = [
-                #att{
-                    name = <<"stuff.txt">>,
-                    type = <<"text/plain">>,
-                    data = fun() -> <<"diet pepsi">> end,
-                    revpos = 1,
-                    att_len = 10,
-                    disk_len = 10
-                },
-                #att{
-                    name = <<"food.now">>,
-                    type = <<"application/food">>,
-                    revpos = 1,
-                    data = <<"sammich">>
-                }
+                couch_att:new([
+                    {name, <<"stuff.txt">>},
+                    {type, <<"text/plain">>},
+                    {data, fun() -> <<"diet pepsi">> end},
+                    {revpos, 1},
+                    {att_len, 10},
+                    {disk_len, 10}
+                ]),
+                couch_att:new([
+                    {name, <<"food.now">>},
+                    {type, <<"application/food">>},
+                    {revpos, 1},
+                    {data, <<"sammich">>}
+                ])
             ]},
             {[
                 {<<"_id">>, <<>>},
@@ -391,6 +380,3 @@ to_json_success_cases() ->
         ({Options, Doc, EJson, Msg}) ->
             {Msg, ?_assertMatch(EJson, couch_doc:to_json_obj(Doc, Options))}
     end, Cases).
-
--endif.
-


[26/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Add test_util:wait function

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

Branch: refs/heads/master
Commit: 0d5acb1354c717a3b1350ca511d03e7817f48586
Parents: 5e95b1a
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 3 12:22:25 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 11:04:52 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/0d5acb13/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index ec2029d..48b57f0 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -28,6 +28,7 @@
 
 -export([with_process_restart/1, with_process_restart/2, with_process_restart/3]).
 -export([wait_process/1, wait_process/2]).
+-export([wait/1, wait/2, wait/3]).
 
 -export([start/1, start/2, start/3, stop/1]).
 
@@ -183,20 +184,38 @@ with_process_restart(Name, Fun, Timeout) ->
         Pid
     end.
 
+
 wait_process(Name) ->
     wait_process(Name, 5000).
 wait_process(Name, Timeout) ->
+    wait(fun() ->
+       case whereis(Name) of
+       undefined ->
+          wait;
+       Pid ->
+          Pid
+       end
+    end, Timeout).
+
+wait(Fun) ->
+    wait(Fun, 5000, 50).
+
+wait(Fun, Timeout) ->
+    wait(Fun, Timeout, 50).
+
+wait(Fun, Timeout, Delay) ->
     Now = now_us(),
-    wait_process(Name, Timeout * 1000, Now, Now).
+    wait(Fun, Timeout * 1000, Delay, Now, Now).
 
-wait_process(_Name, Timeout, Started, Prev) when Prev - Started > Timeout ->
+wait(_Fun, Timeout, _Delay, Started, Prev) when Prev - Started > Timeout ->
     timeout;
-wait_process(Name, Timeout, Started, _Prev) ->
-    case whereis(Name) of
-    undefined ->
-        wait_process(Name, Timeout, Started, now_us());
-    Pid ->
-        Pid
+wait(Fun, Timeout, Delay, Started, _Prev) ->
+    case Fun() of
+    wait ->
+        ok = timer:sleep(Delay),
+        wait(Fun, Timeout, Delay, Started, now_us());
+    Else ->
+        Else
     end.
 
 start(Module) ->


[06/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Implement test_util:stop_sync_throw

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

Branch: refs/heads/master
Commit: fa159b1d484a43044bd3205f419a2f18a13ad875
Parents: f66255f
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 08:47:23 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:39:03 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/fa159b1d/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index 1ac9794..1c3c93f 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -24,6 +24,7 @@
 
 -export([stop_sync/1, stop_sync/2, stop_sync/3]).
 
+-export([stop_sync_throw/2, stop_sync_throw/3, stop_sync_throw/4]).
 
 srcdir() ->
     code:priv_dir(couch) ++ "/../../".
@@ -141,3 +142,16 @@ stop_sync(Pid, Fun, Timeout) when is_function(Fun) and is_pid(Pid) ->
         erlang:demonitor(MRef, [flush])
     end;
 stop_sync(_, _, _) -> error(badarg).
+
+stop_sync_throw(Name, Error) ->
+    stop_sync_throw(Name, shutdown, Error).
+stop_sync_throw(Name, Reason, Error) ->
+    stop_sync_throw(Name, Reason, Error, 5000).
+
+stop_sync_throw(Pid, Fun, Error, Timeout) ->
+    case stop_sync(Pid, Fun, Timeout) of
+        timeout ->
+            throw(Error);
+        Else ->
+            Else
+    end.


[03/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Remove test_util:request

Use test_request:request instead

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

Branch: refs/heads/master
Commit: 4529e1288a9d72637b0bcf19fe84cb39b646d37c
Parents: 9af979f
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Jan 27 08:28:17 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 10 10:33:45 2015 -0800

----------------------------------------------------------------------
 src/test_util.erl | 32 +-------------------------------
 1 file changed, 1 insertion(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/4529e128/src/test_util.erl
----------------------------------------------------------------------
diff --git a/src/test_util.erl b/src/test_util.erl
index 07bbeb0..acf8b3d 100644
--- a/src/test_util.erl
+++ b/src/test_util.erl
@@ -17,7 +17,7 @@
 -export([init_code_path/0]).
 -export([source_file/1, build_file/1]).
 %% -export([run/2]).
--export([request/3, request/4]).
+
 -export([start_couch/0, start_couch/1, start_couch/2, stop_couch/0, stop_couch/1]).
 -export([start_config/1, stop_config/1]).
 -export([start_applications/1]).
@@ -49,36 +49,6 @@ source_file(Name) ->
 build_file(Name) ->
     filename:join([builddir(), Name]).
 
-
-request(Url, Headers, Method) ->
-    request(Url, Headers, Method, []).
-
-request(Url, Headers, Method, Body) ->
-    request(Url, Headers, Method, Body, 3).
-
-request(_Url, _Headers, _Method, _Body, 0) ->
-    {error, request_failed};
-request(Url, Headers, Method, Body, N) ->
-    case code:is_loaded(ibrowse) of
-    false ->
-        {ok, _} = ibrowse:start();
-    _ ->
-        ok
-    end,
-    case ibrowse:send_req(Url, Headers, Method, Body) of
-    {ok, Code0, RespHeaders, RespBody0} ->
-        Code = list_to_integer(Code0),
-        RespBody = iolist_to_binary(RespBody0),
-        {ok, Code, RespHeaders, RespBody};
-    {error, {'EXIT', {normal, _}}} ->
-        % Connection closed right after a successful request that
-        % used the same connection.
-        request(Url, Headers, Method, Body, N - 1);
-    Error ->
-        Error
-    end.
-
-
 start_couch() ->
     start_couch(?CONFIG_CHAIN, []).
 


[45/48] couch commit: updated refs/heads/master to 7776921

Posted by kx...@apache.org.
Improve couch_compaction_daemon test performance

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

Branch: refs/heads/master
Commit: 17937d53e9692c2d999c20a789616b26da0f41ee
Parents: 7d7e039
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Feb 24 12:22:01 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 24 12:22:01 2015 -0800

----------------------------------------------------------------------
 src/couch_compaction_daemon.erl    | 23 +++++++---
 test/couchdb_compaction_daemon.erl | 76 ++++++++++++++++++++++-----------
 2 files changed, 70 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/17937d53/src/couch_compaction_daemon.erl
----------------------------------------------------------------------
diff --git a/src/couch_compaction_daemon.erl b/src/couch_compaction_daemon.erl
index 2294fbc..7888eb4 100644
--- a/src/couch_compaction_daemon.erl
+++ b/src/couch_compaction_daemon.erl
@@ -15,7 +15,7 @@
 -behaviour(config_listener).
 
 % public API
--export([start_link/0]).
+-export([start_link/0, in_progress/0]).
 
 % gen_server callbacks
 -export([init/1, handle_call/3, handle_info/2, handle_cast/2]).
@@ -30,7 +30,8 @@
 -define(CONFIG_ETS, couch_compaction_daemon_config).
 
 -record(state, {
-    loop_pid
+    loop_pid,
+    in_progress = []
 }).
 
 -record(config, {
@@ -50,6 +51,8 @@
 start_link() ->
     gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
 
+in_progress() ->
+    gen_server:call(?MODULE, in_progress).
 
 init(_) ->
     process_flag(trap_exit, true),
@@ -82,6 +85,14 @@ handle_cast({config_update, DbName, Config}, #state{loop_pid = Loop} = State) ->
     {noreply, State}.
 
 
+handle_call({start, DbName}, {Pid, _},
+        #state{loop_pid = Pid, in_progress = InProgress} = State) ->
+    {reply, ok, State#state{in_progress = [DbName|InProgress]}};
+handle_call({stop, DbName}, {Pid, _},
+        #state{loop_pid = Pid, in_progress = InProgress} = State) ->
+    {reply, ok, State#state{in_progress = InProgress -- [DbName]}};
+handle_call(in_progress, _From, #state{in_progress = InProgress} = State) ->
+    {reply, InProgress, State};
 handle_call(Msg, _From, State) ->
     {stop, {unexpected_call, Msg}, State}.
 
@@ -123,7 +134,7 @@ compact_loop(Parent) ->
                 {ok, Config} ->
                     case check_period(Config) of
                     true ->
-                        maybe_compact_db(DbName, Config);
+                        maybe_compact_db(Parent, DbName, Config);
                     false ->
                         ok
                     end
@@ -142,12 +153,13 @@ compact_loop(Parent) ->
     compact_loop(Parent).
 
 
-maybe_compact_db(DbName, Config) ->
+maybe_compact_db(Parent, DbName, Config) ->
     case (catch couch_db:open_int(DbName, [?ADMIN_CTX])) of
     {ok, Db} ->
         DDocNames = db_ddoc_names(Db),
         case can_db_compact(Config, Db) of
         true ->
+            gen_server:call(Parent, {start, DbName}),
             {ok, _} = couch_db:start_compact(Db),
             TimeLeft = compact_time_left(Config),
             case Config#config.parallel_view_compact of
@@ -192,7 +204,8 @@ maybe_compact_db(DbName, Config) ->
                     unlink(ViewsCompactPid),
                     exit(ViewsCompactPid, kill)
                 end
-            end;
+            end,
+            gen_server:call(Parent, {stop, DbName});
         false ->
             couch_db:close(Db),
             maybe_compact_views(DbName, DDocNames, Config)

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/17937d53/test/couchdb_compaction_daemon.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_compaction_daemon.erl b/test/couchdb_compaction_daemon.erl
index 7d771fd..92ed8ac 100644
--- a/test/couchdb_compaction_daemon.erl
+++ b/test/couchdb_compaction_daemon.erl
@@ -15,7 +15,6 @@
 -include_lib("couch/include/couch_eunit.hrl").
 -include_lib("couch/include/couch_db.hrl").
 
--define(DELAY, 100).
 -define(TIMEOUT, 30000).
 -define(TIMEOUT_S, ?TIMEOUT div 1000).
 
@@ -70,15 +69,18 @@ should_compact_by_default_rule(DbName) ->
         {_, DbFileSize} = get_db_frag(DbName),
         {_, ViewFileSize} = get_view_frag(DbName),
 
-        ok = config:set("compactions", "_default",
-            "[{db_fragmentation, \"70%\"}, {view_fragmentation, \"70%\"}]",
-            false),
+        with_config_change(DbName, fun() ->
+            ok = config:set("compactions", "_default",
+                "[{db_fragmentation, \"70%\"}, {view_fragmentation, \"70%\"}]",
+                false)
+        end),
 
-        ok = timer:sleep(5000), % something >= check_interval
+        wait_compaction_started(DbName),
         wait_compaction_finished(DbName),
 
-        ok = config:delete("compactions", "_default", false),
-        ok = timer:sleep(1000), % need to wait so gen_server:cast would complete
+        with_config_change(DbName, fun() ->
+            ok = config:delete("compactions", "_default", false)
+        end),
 
         {DbFrag2, DbFileSize2} = get_db_frag(DbName),
         {ViewFrag2, ViewFileSize2} = get_view_frag(DbName),
@@ -101,14 +103,18 @@ should_compact_by_dbname_rule(DbName) ->
         {_, DbFileSize} = get_db_frag(DbName),
         {_, ViewFileSize} = get_view_frag(DbName),
 
-        ok = config:set("compactions", ?b2l(DbName),
-            "[{db_fragmentation, \"70%\"}, {view_fragmentation, \"70%\"}]",
-            false),
+        with_config_change(DbName, fun() ->
+            ok = config:set("compactions", ?b2l(DbName),
+                "[{db_fragmentation, \"70%\"}, {view_fragmentation, \"70%\"}]",
+                false)
+        end),
 
-        ok = timer:sleep(4000), % something >= check_interval
+        wait_compaction_started(DbName),
         wait_compaction_finished(DbName),
-        ok = config:delete("compactions", ?b2l(DbName), false),
-        ok = timer:sleep(1000), % need to wait so gen_server:cast would complete
+
+        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),
@@ -198,12 +204,29 @@ get_view_frag(DbName) ->
 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
+        case is_compaction_running(DbName) of
+            true -> wait;
+            false -> ok
+        end
     end,
     case test_util:wait(WaitFun, 10000) of
         timeout ->
@@ -215,16 +238,21 @@ wait_compaction_finished(DbName) ->
             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, <<"_design/foo">>),
-    couch_db:close(Db),
-    (couch_util:get_value(compact_running, ViewInfo) =:= true)
-        orelse (couch_util:get_value(compact_running, DbInfo) =:= true).
+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).