You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by gi...@git.apache.org on 2017/04/27 20:48:21 UTC

[GitHub] mayya-sharipova commented on a change in pull request #497: notify couch_index_processes on all shards when ddoc updated

mayya-sharipova commented on a change in pull request #497: notify couch_index_processes on all shards when ddoc updated
URL: https://github.com/apache/couchdb/pull/497#discussion_r113798448
 
 

 ##########
 File path: src/couch_index/test/couch_index_ddoc_updated_tests.erl
 ##########
 @@ -0,0 +1,134 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_ddoc_updated_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
+setup() ->
+    DbName = ?tempdb(),
+    fake_mem3(DbName),
+    fake_index(),
+
+    DbNames = [mem3:name(Sh) || Sh <- mem3:local_shards(mem3:dbname(DbName))],
+    [Db1| RestDbs] = lists:map(fun(DBName) ->
+        {ok, DB} = couch_db:create(DBName, [?ADMIN_CTX]),
+        DB
+    end, DbNames),
+
+    % create a DDoc on the 1st Db
+    DDocID = <<"idx_name">>,
+    DDocJson = couch_doc:from_json_obj({[
+        {<<"_id">>, DDocID},
+        {<<"value">>, 1}
+    ]}),
+    {ok, _Rev} = couch_db:update_doc(Db1, DDocJson, []),
+    {ok, Db} = couch_db:reopen(Db1),
+    {ok, DDoc} = couch_db:open_doc(Db, DDocID, [ejson_body, ?ADMIN_CTX]),
+    Dbs = [Db | RestDbs],
+    {Dbs, DDoc}.
+
+
+teardown({Dbs, _DDoc}) ->
+    lists:foreach(fun(Db) ->
+        couch_db:close(Db),
+        couch_server:delete(Db#db.name, [?ADMIN_CTX])
+    end, Dbs),
+    (catch meck:unload(mem3)),
+    (catch meck:unload(test_index)),
+    ok.
+
+
+ddoc_update_test_() ->
+    {
+        "Check ddoc update actions",
+        {
+            setup,
+            fun() -> test_util:start_couch([]) end, fun test_util:stop_couch/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun ddoc_update/1
+                ]
+            }
+        }
+    }.
+
+
+ddoc_update({[Db | _] = Dbs, DDoc}) ->
+    ?_test(begin
+        N = length(Dbs),
+        DDocID = DDoc#doc.id,
+
+        % run couch_index process for each Db
+        lists:foreach(fun(DB) ->
+            couch_index_server:get_index(test_index, DB, DDoc)
+        end, Dbs),
+        IndexesBefore = ets:match_object(
+            couchdb_indexes_by_db, {'$1', {DDocID, '$2'}}),
+        ?assertEqual(N, length(IndexesBefore)),
+
+        % update ddoc
+        DDocJson2 = couch_doc:from_json_obj({[
+            {<<"_id">>, DDocID},
+            {<<"value">>, 2},
+            {<<"_rev">>, couch_doc:rev_to_str(DDoc#doc.revs)}
+        ]}),
+        {ok, _} = couch_db:update_doc(Db, DDocJson2, []),
+
+        % assert that all index processes exited after ddoc updated
+        couch_index_server:handle_db_event(
+            Db#db.name, {ddoc_updated, DDocID}, {st, ""}),
+        timer:sleep(1000),
 
 Review comment:
   @iilyak thanks for your comments. I will address them all in the next commit. The only thing I am not sure is how to avoid timer:sleep? If I check `couchdb_indexes_by_db` ETS immediately  after `ddoc_updated` notification, the ETS will still contain indexes. We need to allow some time pass for `couch_index` process to exit,  and `couch_index_server` process to clean its ETS tables. 
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services