summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shorin <kxepal@apache.org>2014-06-12 02:44:30 +0400
committerAlexander Shorin <kxepal@apache.org>2015-12-03 00:52:10 +0300
commit1649e68f8fbc4c74bcda608bf5e3f0fa7a620ec2 (patch)
tree6965b38eeed39b14d3c2e92e8da201070cec61cd
parentd85394fd6dcecdb392754425ddcf1224e6723b6c (diff)
downloadcouchdb-1649e68f8fbc4c74bcda608bf5e3f0fa7a620ec2.tar.gz
Port couch_mrview/07-compact-swap.t etap test suite to eunit
-rw-r--r--src/couch_mrview/Makefile.am4
-rw-r--r--src/couch_mrview/test/07-compact-swap.t57
-rw-r--r--src/couch_mrview/test/couch_mrview_compact_tests.erl101
3 files changed, 103 insertions, 59 deletions
diff --git a/src/couch_mrview/Makefile.am b/src/couch_mrview/Makefile.am
index 45d099af7..0f140aa78 100644
--- a/src/couch_mrview/Makefile.am
+++ b/src/couch_mrview/Makefile.am
@@ -35,11 +35,11 @@ source_files = \
test_files = \
test/couch_mrview_all_docs_tests.erl \
test/couch_mrview_collation_tests.erl \
+ test/couch_mrview_compact_tests.erl \
test/couch_mrview_index_info_tests.erl \
test/couch_mrview_map_views_tests.erl \
test/couch_mrview_modules_load_tests.erl \
- test/couch_mrview_red_views_tests.erl \
- test/07-compact-swap.t
+ test/couch_mrview_red_views_tests.erl
compiled_files = \
ebin/couch_mrview.app \
diff --git a/src/couch_mrview/test/07-compact-swap.t b/src/couch_mrview/test/07-compact-swap.t
deleted file mode 100644
index 4bfe12406..000000000
--- a/src/couch_mrview/test/07-compact-swap.t
+++ /dev/null
@@ -1,57 +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.
-
-main(_) ->
- test_util:run(1, fun() -> test() end).
-
-
-test() ->
- couch_server_sup:start_link(test_util:config_files()),
- {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map, 1000),
- couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
- test_swap(Db),
- ok.
-
-
-test_swap(Db) ->
- {ok, QPid} = start_query(Db),
- {ok, MonRef} = couch_mrview:compact(Db, <<"_design/bar">>, [monitor]),
- receive
- {'DOWN', MonRef, process, _, _} -> ok
- after 1000 ->
- throw(compaction_failed)
- end,
- QPid ! {self(), continue},
- receive
- {QPid, Count} ->
- etap:is(Count, 1000, "View finished successfully.")
- after 1000 ->
- throw("query failed")
- end.
-
-
-start_query(Db) ->
- Self = self(),
- Pid = spawn(fun() ->
- CB = fun
- (_, wait) -> receive {Self, continue} -> {ok, 0} end;
- ({row, _}, Count) -> {ok, Count+1};
- (_, Count) -> {ok, Count}
- end,
- {ok, Result} =
- couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, [], CB, wait),
- Self ! {self(), Result}
- end),
- {ok, Pid}.
diff --git a/src/couch_mrview/test/couch_mrview_compact_tests.erl b/src/couch_mrview/test/couch_mrview_compact_tests.erl
new file mode 100644
index 000000000..4cb7dafd0
--- /dev/null
+++ b/src/couch_mrview/test/couch_mrview_compact_tests.erl
@@ -0,0 +1,101 @@
+% 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_mrview_compact_tests).
+
+-include("couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+-define(TIMEOUT, 1000).
+
+
+start() ->
+ {ok, Pid} = couch_server_sup:start_link(?CONFIG_CHAIN),
+ Pid.
+
+stop(Pid) ->
+ erlang:monitor(process, Pid),
+ couch_server_sup:stop(),
+ receive
+ {'DOWN', _, _, Pid, _} ->
+ ok
+ after ?TIMEOUT ->
+ throw({timeout, server_stop})
+ end.
+
+setup() ->
+ {ok, Db} = couch_mrview_test_util:init_db(?tempdb(), map, 1000),
+ Db.
+
+teardown(Db) ->
+ couch_db:close(Db),
+ couch_server:delete(Db#db.name, [?ADMIN_USER]),
+ ok.
+
+
+compaction_test_() ->
+ {
+ "Compaction tests",
+ {
+ setup,
+ fun start/0, fun stop/1,
+ {
+ foreach,
+ fun setup/0, fun teardown/1,
+ [
+ fun should_swap/1
+ ]
+ }
+ }
+ }.
+
+
+should_swap(Db) ->
+ ?_test(begin
+ couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
+ {ok, QPid} = start_query(Db),
+ {ok, MonRef} = couch_mrview:compact(Db, <<"_design/bar">>, [monitor]),
+ receive
+ {'DOWN', MonRef, process, _, _} -> ok
+ after ?TIMEOUT ->
+ erlang:error(
+ {assertion_failed,
+ [{module, ?MODULE}, {line, ?LINE},
+ {reason, "compaction failed"}]})
+ end,
+ QPid ! {self(), continue},
+ receive
+ {QPid, Count} ->
+ ?assertEqual(1000, Count)
+ after ?TIMEOUT ->
+ erlang:error(
+ {assertion_failed,
+ [{module, ?MODULE}, {line, ?LINE},
+ {reason, "query failed"}]})
+ end
+ end).
+
+
+start_query(Db) ->
+ Self = self(),
+ Pid = spawn(fun() ->
+ CB = fun
+ (_, wait) -> receive {Self, continue} -> {ok, 0} end;
+ ({row, _}, Count) -> {ok, Count+1};
+ (_, Count) -> {ok, Count}
+ end,
+ {ok, Result} =
+ couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, [], CB, wait),
+ Self ! {self(), Result}
+ end),
+ {ok, Pid}.