couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [31/36] couchdb commit: updated refs/heads/1963-eunit to 85f2750
Date Tue, 03 Jun 2014 15:55:09 GMT
Port 150-invalid-view-seq.t etap test suite to eunit

Merged into couchdb_views_tests suite.


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

Branch: refs/heads/1963-eunit
Commit: 79c69a9ca1a309728b5551392f198b4b2aba424d
Parents: a36d630
Author: Alexander Shorin <kxepal@apache.org>
Authored: Tue Jun 3 08:49:32 2014 +0400
Committer: Alexander Shorin <kxepal@apache.org>
Committed: Tue Jun 3 19:52:53 2014 +0400

----------------------------------------------------------------------
 test/couchdb/couchdb_views_tests.erl | 142 +++++++++++++++++++++--
 test/etap/150-invalid-view-seq.t     | 183 ------------------------------
 test/etap/Makefile.am                |   1 -
 3 files changed, 131 insertions(+), 195 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/79c69a9c/test/couchdb/couchdb_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb/couchdb_views_tests.erl b/test/couchdb/couchdb_views_tests.erl
index be361c5..ec4d000 100644
--- a/test/couchdb/couchdb_views_tests.erl
+++ b/test/couchdb/couchdb_views_tests.erl
@@ -15,30 +15,50 @@
 -include_lib("../../src/couchdb/couch_db.hrl").
 -include_lib("couchdb_tests.hrl").
 
--define(ADMIN_USER, #user_ctx{roles=[<<"_admin">>]}).
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
 
 
 start() ->
-    couch_server_sup:start_link(?CONFIG_CHAIN),
+    {ok, Pid} = couch_server_sup:start_link(?CONFIG_CHAIN),
     % disable logging to reduce noise in stdout
     couch_config:set("log", "level", "none", false),
-    ok.
+    % disable sasl to not throw large stack trace into stderr for
+    % should_not_remember_docs_in_index_after_backup_restore_test
+    couch_config:set("log", "include_sasl", "false", false),
+    Pid.
 
-stop(_) ->
+stop(Pid) ->
+    erlang:monitor(process, Pid),
     couch_server_sup:stop(),
-    ok.
+    receive
+        {'DOWN', _, _, Pid, _} ->
+            ok
+    after 1000 ->
+        throw({timeout, server_stop})
+    end.
 
 setup() ->
     DbName = ?tempdb(),
-    {ok, _} = couch_db:create(DbName, [{user_ctx, ?ADMIN_USER}]),
+    {ok, _} = couch_db:create(DbName, [?ADMIN_USER]),
     FooRev = create_design_doc(DbName, <<"_design/foo">>, <<"bar">>),
     ok = query_view(DbName, "foo", "bar"),
     BooRev = create_design_doc(DbName, <<"_design/boo">>, <<"baz">>),
     ok = query_view(DbName, "boo", "baz"),
     {DbName, {FooRev, BooRev}}.
 
+setup_with_docs() ->
+    DbName = ?tempdb(),
+    {ok, _} = couch_db:create(DbName, [?ADMIN_USER]),
+    create_docs(DbName),
+    create_design_doc(DbName),
+    backup_db_file(DbName),
+    create_new_doc(DbName),
+    DbName.
+
 teardown({DbName, _}) ->
-    ok = couch_server:delete(DbName, []),
+    teardown(DbName);
+teardown(DbName) when is_binary(DbName) ->
+    ok = couch_server:delete(DbName, [?ADMIN_USER]),
     ok.
 
 
@@ -60,6 +80,40 @@ view_indexes_cleanup_test_() ->
         }
     }.
 
+
+should_not_remember_docs_in_index_after_backup_restore_test() ->
+    %% COUCHDB-640
+    start(),
+    DbName = setup_with_docs(),
+
+    {ok, Code0, _, Body0} = test_request:get(
+        db_url(DbName) ++ "/_design/foo/_view/bar"),
+    ?assertEqual(200, Code0),
+
+    ViewJson0 = ejson:decode(Body0),
+    Rows0 = couch_util:get_nested_json_value(ViewJson0, [<<"rows">>]),
+    ?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),
+
+    {ok, Code1, _, Body1} = test_request:get(
+        db_url(DbName) ++ "/_design/foo/_view/bar"),
+    ?assertEqual(200, Code1),
+
+    ViewJson1 = ejson:decode(Body1),
+    Rows1 = couch_util:get_nested_json_value(ViewJson1, [<<"rows">>]),
+    ?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_have_two_indexes_alive_before_deletion({DbName, _}) ->
     view_cleanup(DbName),
     ?_assertEqual(2, count_index_files(DbName)).
@@ -77,7 +131,7 @@ should_cleanup_all_index_files({DbName, {FooRev, BooRev}})->
 
 
 create_design_doc(DbName, DDName, ViewName) ->
-    {ok, Db} = couch_db:open(DbName, [{user_ctx, ?ADMIN_USER}]),
+    {ok, Db} = couch_db:open(DbName, [?ADMIN_USER]),
     DDoc = couch_doc:from_json_obj({[
         {<<"_id">>, DDName},
         {<<"language">>, <<"javascript">>},
@@ -93,7 +147,7 @@ create_design_doc(DbName, DDName, ViewName) ->
     Rev.
 
 delete_design_doc(DbName, DDName, Rev) ->
-    {ok, Db} = couch_db:open(DbName, [{user_ctx, ?ADMIN_USER}]),
+    {ok, Db} = couch_db:open(DbName, [?ADMIN_USER]),
     DDoc = couch_doc:from_json_obj({[
         {<<"_id">>, DDName},
         {<<"_rev">>, couch_doc:rev_to_str(Rev)},
@@ -105,7 +159,7 @@ delete_design_doc(DbName, DDName, Rev) ->
 db_url(DbName) ->
     Addr = couch_config:get("httpd", "bind_address", "127.0.0.1"),
     Port = integer_to_list(mochiweb_socket_server:get(couch_httpd, port)),
-    "http://" ++ Addr ++ ":" ++ Port ++ "/" ++ binary_to_list(DbName).
+    "http://" ++ Addr ++ ":" ++ Port ++ "/" ++ ?b2l(DbName).
 
 query_view(DbName, DDoc, View) ->
     {ok, Code, _Headers, _Body} = test_request:get(
@@ -114,7 +168,7 @@ query_view(DbName, DDoc, View) ->
     ok.
 
 view_cleanup(DbName) ->
-    {ok, Db} = couch_db:open(DbName, [{user_ctx, ?ADMIN_USER}]),
+    {ok, Db} = couch_db:open(DbName, [?ADMIN_USER]),
     couch_mrview:cleanup(Db),
     couch_db:close(Db).
 
@@ -123,3 +177,69 @@ count_index_files(DbName) ->
     RootDir = couch_config:get("couchdb", "view_index_dir"),
     length(filelib:wildcard(RootDir ++ "/." ++
         binary_to_list(DbName) ++ "_design"++"/mrview/*")).
+
+create_docs(DbName) ->
+    {ok, Db} = couch_db:open(DbName, [?ADMIN_USER]),
+    Doc1 = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"doc1">>},
+        {<<"value">>, 1}
+
+    ]}),
+    Doc2 = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"doc2">>},
+        {<<"value">>, 2}
+
+    ]}),
+    Doc3 = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"doc3">>},
+        {<<"value">>, 3}
+
+    ]}),
+    {ok, _} = couch_db:update_docs(Db, [Doc1, Doc2, Doc3]),
+    couch_db:ensure_full_commit(Db),
+    couch_db:close(Db).
+
+create_new_doc(DbName) ->
+    {ok, Db} = couch_db:open(DbName, [?ADMIN_USER]),
+    Doc666 = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"doc666">>},
+        {<<"value">>, 999}
+
+    ]}),
+    {ok, _} = couch_db:update_docs(Db, [Doc666]),
+    couch_db:ensure_full_commit(Db),
+    couch_db:close(Db).
+
+create_design_doc(DbName) ->
+    {ok, Db} = couch_db:open(DbName, [?ADMIN_USER]),
+    DDoc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/foo">>},
+        {<<"language">>, <<"javascript">>},
+        {<<"views">>, {[
+            {<<"bar">>, {[
+                {<<"map">>, <<"function(doc) { emit(doc.value, 1); }">>}
+            ]}}
+        ]}}
+    ]}),
+    {ok, _} = couch_db:update_docs(Db, [DDoc]),
+    couch_db:ensure_full_commit(Db),
+    couch_db:close(Db).
+
+has_doc(DocId1, Rows) ->
+    DocId = iolist_to_binary(DocId1),
+    lists:any(fun({R}) -> lists:member({<<"id">>, DocId}, R) end, Rows).
+
+backup_db_file(DbName) ->
+    DbDir = couch_config:get("couchdb", "database_dir"),
+    DbFile = filename:join([DbDir, ?b2l(DbName) ++ ".couch"]),
+    {ok, _} = file:copy(DbFile, DbFile ++ ".backup"),
+    ok.
+
+restore_backup_db_file(DbName) ->
+    DbDir = couch_config:get("couchdb", "database_dir"),
+    stop(whereis(couch_server_sup)),
+    DbFile = filename:join([DbDir, ?b2l(DbName) ++ ".couch"]),
+    ok = file:delete(DbFile),
+    ok = file:rename(DbFile ++ ".backup", DbFile),
+    start(),
+    ok.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/79c69a9c/test/etap/150-invalid-view-seq.t
----------------------------------------------------------------------
diff --git a/test/etap/150-invalid-view-seq.t b/test/etap/150-invalid-view-seq.t
deleted file mode 100755
index 681875a..0000000
--- a/test/etap/150-invalid-view-seq.t
+++ /dev/null
@@ -1,183 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-% 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.
-
--record(user_ctx, {
-    name = null,
-    roles = [],
-    handler
-}).
-
-test_db_name() ->
-    <<"couch_test_invalid_view_seq">>.
-
-main(_) ->
-    test_util:init_code_path(),
-
-    etap:plan(10),
-    case (catch test()) of
-        ok ->
-            etap:end_tests();
-        Other ->
-            etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
-            etap:bail(Other)
-    end,
-    ok.
-
-%% NOTE: since during the test we stop the server,
-%%       a huge and ugly but harmless stack trace is sent to stderr
-%%
-test() ->
-    couch_server_sup:start_link(test_util:config_files()),
-    timer:sleep(1000),
-    delete_db(),
-    create_db(),
-
-    create_docs(),
-    create_design_doc(),
-
-    % make DB file backup
-    backup_db_file(),
-
-    put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")),
-    put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))),
-
-    create_new_doc(),
-    query_view_before_restore_backup(),
-
-    % restore DB file backup after querying view
-    restore_backup_db_file(),
-
-    query_view_after_restore_backup(),
-
-    delete_db(),
-    couch_server_sup:stop(),
-    ok.
-
-admin_user_ctx() ->
-    {user_ctx, #user_ctx{roles=[<<"_admin">>]}}.
-
-create_db() ->
-    {ok, _} = couch_db:create(test_db_name(), [admin_user_ctx()]).
-
-delete_db() ->
-    couch_server:delete(test_db_name(), [admin_user_ctx()]).
-
-create_docs() ->
-    {ok, Db} = couch_db:open(test_db_name(), [admin_user_ctx()]),
-    Doc1 = couch_doc:from_json_obj({[
-        {<<"_id">>, <<"doc1">>},
-        {<<"value">>, 1}
-
-    ]}),
-    Doc2 = couch_doc:from_json_obj({[
-        {<<"_id">>, <<"doc2">>},
-        {<<"value">>, 2}
-
-    ]}),
-    Doc3 = couch_doc:from_json_obj({[
-        {<<"_id">>, <<"doc3">>},
-        {<<"value">>, 3}
-
-    ]}),
-    {ok, _} = couch_db:update_docs(Db, [Doc1, Doc2, Doc3]),
-    couch_db:ensure_full_commit(Db),
-    couch_db:close(Db).
-
-create_design_doc() ->
-    {ok, Db} = couch_db:open(test_db_name(), [admin_user_ctx()]),
-    DDoc = couch_doc:from_json_obj({[
-        {<<"_id">>, <<"_design/foo">>},
-        {<<"language">>, <<"javascript">>},
-        {<<"views">>, {[
-            {<<"bar">>, {[
-                {<<"map">>, <<"function(doc) { emit(doc.value, 1); }">>}
-            ]}}
-        ]}}
-    ]}),
-    {ok, _} = couch_db:update_docs(Db, [DDoc]),
-    couch_db:ensure_full_commit(Db),
-    couch_db:close(Db).
-
-backup_db_file() ->
-    DbFile = test_util:build_file("tmp/lib/" ++
-        binary_to_list(test_db_name()) ++ ".couch"),
-    {ok, _} = file:copy(DbFile, DbFile ++ ".backup"),
-    ok.
-
-create_new_doc() ->
-    {ok, Db} = couch_db:open(test_db_name(), [admin_user_ctx()]),
-    Doc666 = couch_doc:from_json_obj({[
-        {<<"_id">>, <<"doc666">>},
-        {<<"value">>, 999}
-
-    ]}),
-    {ok, _} = couch_db:update_docs(Db, [Doc666]),
-    couch_db:ensure_full_commit(Db),
-    couch_db:close(Db).
-
-db_url() ->
-    "http://" ++ get(addr) ++ ":" ++ get(port) ++ "/" ++
-    binary_to_list(test_db_name()).
-
-query_view_before_restore_backup() ->
-    {ok, Code, _Headers, Body} = test_util:request(
-        db_url() ++ "/_design/foo/_view/bar", [], get),
-    etap:is(Code, 200, "Got view response before restoring backup."),
-    ViewJson = ejson:decode(Body),
-    Rows = couch_util:get_nested_json_value(ViewJson, [<<"rows">>]),
-    HasDoc1 = has_doc("doc1", Rows),
-    HasDoc2 = has_doc("doc2", Rows),
-    HasDoc3 = has_doc("doc3", Rows),
-    HasDoc666 = has_doc("doc666", Rows),
-    etap:is(HasDoc1, true, "Before backup restore, view has doc1"),
-    etap:is(HasDoc2, true, "Before backup restore, view has doc2"),
-    etap:is(HasDoc3, true, "Before backup restore, view has doc3"),
-    etap:is(HasDoc666, true, "Before backup restore, view has doc666"),
-    ok.
-
-has_doc(DocId1, Rows) ->
-    DocId = iolist_to_binary(DocId1),
-    lists:any(
-        fun({R}) -> lists:member({<<"id">>, DocId}, R) end,
-        Rows
-    ).
-
-restore_backup_db_file() ->
-    couch_server_sup:stop(),
-    timer:sleep(3000),
-    DbFile = test_util:build_file("tmp/lib/" ++
-        binary_to_list(test_db_name()) ++ ".couch"),
-    ok = file:delete(DbFile),
-    ok = file:rename(DbFile ++ ".backup", DbFile),
-    couch_server_sup:start_link(test_util:config_files()),
-    timer:sleep(1000),
-    put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))),
-    ok.
-
-query_view_after_restore_backup() ->
-    {ok, Code, _Headers, Body} = test_util:request(
-        db_url() ++ "/_design/foo/_view/bar", [], get),
-    etap:is(Code, 200, "Got view response after restoring backup."),
-    ViewJson = ejson:decode(Body),
-    Rows = couch_util:get_nested_json_value(ViewJson, [<<"rows">>]),
-    HasDoc1 = has_doc("doc1", Rows),
-    HasDoc2 = has_doc("doc2", Rows),
-    HasDoc3 = has_doc("doc3", Rows),
-    HasDoc666 = has_doc("doc666", Rows),
-    etap:is(HasDoc1, true, "After backup restore, view has doc1"),
-    etap:is(HasDoc2, true, "After backup restore, view has doc2"),
-    etap:is(HasDoc3, true, "After backup restore, view has doc3"),
-    etap:is(HasDoc666, false, "After backup restore, view does not have doc666"),
-    ok.

http://git-wip-us.apache.org/repos/asf/couchdb/blob/79c69a9c/test/etap/Makefile.am
----------------------------------------------------------------------
diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am
index 94ff6f2..bf9b3f2 100644
--- a/test/etap/Makefile.am
+++ b/test/etap/Makefile.am
@@ -36,7 +36,6 @@ fixture_files = \
     fixtures/test.couch
 
 tap_files = \
-    150-invalid-view-seq.t \
     160-vhosts.t \
     170-os-daemons.es \
     170-os-daemons.t \


Mime
View raw message