You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2016/02/25 21:03:09 UTC

[07/12] couch commit: updated refs/heads/2938-fix-5986-filtered-changes to 9171d5a

Propagate db delete event to changes callback

Not propagating the `delete` event to the changes callback causes
db to stay open when it is deleted in the presence of `continuous`
requests to _changes feed. This in its turn causes couch_file to stay
open until the connection is closed by the client.


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

Branch: refs/heads/2938-fix-5986-filtered-changes
Commit: a51304e9e238af45d9eda2987bc53e953782aaf5
Parents: d08ce07
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed Feb 10 16:26:22 2016 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Feb 16 18:05:51 2016 -0800

----------------------------------------------------------------------
 src/couch_changes.erl        |  4 +++-
 test/couch_changes_tests.erl | 28 ++++++++++++++++++++++------
 2 files changed, 25 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/a51304e9/src/couch_changes.erl
----------------------------------------------------------------------
diff --git a/src/couch_changes.erl b/src/couch_changes.erl
index 0d418e8..73a3cce 100644
--- a/src/couch_changes.erl
+++ b/src/couch_changes.erl
@@ -170,7 +170,9 @@ handle_changes(Args1, Req, Db0, Type) ->
 handle_db_event(_DbName, updated, Parent) ->
     Parent ! updated,
     {ok, Parent};
-
+handle_db_event(_DbName, deleted, Parent) ->
+    Parent ! deleted,
+    {ok, Parent};
 handle_db_event(_DbName, _Event, Parent) ->
     {ok, Parent}.
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/a51304e9/test/couch_changes_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_changes_tests.erl b/test/couch_changes_tests.erl
index c28394b..63062dd 100644
--- a/test/couch_changes_tests.erl
+++ b/test/couch_changes_tests.erl
@@ -18,8 +18,6 @@
 -define(TIMEOUT, 3000).
 -define(TEST_TIMEOUT, 10000).
 
--ifdef(run_broken_tests).
-
 -record(row, {
     id,
     seq,
@@ -117,7 +115,8 @@ continuous_feed() ->
             foreach,
             fun setup/0, fun teardown/1,
             [
-                fun should_filter_continuous_feed_by_specific_doc_ids/1
+                fun should_filter_continuous_feed_by_specific_doc_ids/1,
+                fun should_end_changes_when_db_deleted/1
             ]
         }
     }.
@@ -315,6 +314,25 @@ should_filter_continuous_feed_by_specific_doc_ids({DbName, Revs}) ->
             ?assertMatch([#row{seq = 18, id = <<"doc3">>}], FinalRows)
         end).
 
+
+should_end_changes_when_db_deleted({DbName, _Revs}) ->
+    ?_test(begin
+        {ok, Db} = couch_db:open_int(DbName, []),
+        ChangesArgs = #changes_args{
+            filter = "_doc_ids",
+            feed = "continuous"
+        },
+        DocIds = [<<"doc3">>, <<"doc4">>, <<"doc9999">>],
+        Req = {json_req, {[{<<"doc_ids">>, DocIds}]}},
+        Consumer = spawn_consumer(DbName, ChangesArgs, Req),
+        ok = pause(Consumer),
+        ok = couch_server:delete(DbName, [?ADMIN_CTX]),
+        ok = unpause(Consumer),
+        {_Rows, _LastSeq} = wait_finished(Consumer),
+        stop_consumer(Consumer),
+        ok
+    end).
+
 should_emit_only_design_documents({DbName, Revs}) ->
     ?_test(
         begin
@@ -601,6 +619,4 @@ create_db(DbName) ->
     couch_db:create(DbName, [?ADMIN_CTX, overwrite]).
 
 delete_db(DbName) ->
-    ok = couch_server:delete(DbName, [?ADMIN_CTX]).
-
--endif.
+    couch_server:delete(DbName, [?ADMIN_CTX]).