summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul J. Davis <paul.joseph.davis@gmail.com>2020-09-04 09:29:21 -0500
committerPaul J. Davis <paul.joseph.davis@gmail.com>2020-09-15 11:07:26 -0500
commit77f9c8babb1a21e969ca1e3778f0551a4d2b4534 (patch)
tree78da2b9dcd74c067cd324b96c846b06d8d97bbda
parent055079fac7b444078142b90c6a6b5ee6b250af37 (diff)
downloadcouchdb-prototype/fdb-layer-replace-couch-rate.tar.gz
Move error reporting test to EUnitprototype/fdb-layer-replace-couch-rate
This test doesn't fail correctly any longer. Rather than attempting to create a new pathological view case I've just moved it to eunit where we can use meck to throw errors directly.
-rw-r--r--src/couch_views/test/couch_views_error_test.erl102
-rw-r--r--test/elixir/test/map_test.exs32
2 files changed, 102 insertions, 32 deletions
diff --git a/src/couch_views/test/couch_views_error_test.erl b/src/couch_views/test/couch_views_error_test.erl
new file mode 100644
index 000000000..8b6399e0e
--- /dev/null
+++ b/src/couch_views/test/couch_views_error_test.erl
@@ -0,0 +1,102 @@
+% 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_views_error_test).
+
+-include_lib("eunit/include/eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("fabric/test/fabric2_test.hrl").
+
+-define(USER, "chttpd_db_test_admin").
+-define(PASS, "pass").
+-define(AUTH, {basic_auth, {?USER, ?PASS}}).
+-define(CONTENT_JSON, {"Content-Type", "application/json"}).
+
+
+error_test_() ->
+ {
+ "Test views report errors",
+ {
+ setup,
+ fun setup/0,
+ fun teardown/1,
+ {
+ foreach,
+ fun foreach_setup/0,
+ fun foreach_teardown/1,
+ [
+ ?TDEF_FE(view_reports_error)
+ ]
+ }
+ }
+ }.
+
+
+setup() ->
+ Ctx = test_util:start_couch([
+ fabric,
+ chttpd,
+ couch_jobs,
+ couch_js,
+ couch_views
+ ]),
+ Hashed = couch_passwords:hash_admin_password(?PASS),
+ ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
+ Ctx.
+
+
+teardown(Ctx) ->
+ test_util:stop_couch(Ctx).
+
+
+foreach_setup() ->
+ Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
+ Port = mochiweb_socket_server:get(chttpd, port),
+ {ok, Db} = fabric2_db:create(?tempdb(), [{user_ctx, ?ADMIN_USER}]),
+ DbName = fabric2_db:name(Db),
+ Url = lists:concat(["http://", Addr, ":", Port, "/", ?b2l(DbName)]),
+ {Db, Url}.
+
+
+foreach_teardown({Db, _}) ->
+ meck:unload(),
+ ok = fabric2_db:delete(fabric2_db:name(Db), []).
+
+
+view_reports_error({Db, Url}) ->
+ meck:new(couch_views_batch, [passthrough]),
+ meck:expect(couch_views_batch, start, fun(_) ->
+ erlang:error({erlfdb_error, 2101})
+ end),
+
+ {ok, _} = fabric2_db:update_doc(Db, ddoc(), []),
+
+ ViewUrl = lists:concat([Url, "/_design/foo/_view/bar"]),
+ {ok, Status, _Headers, Body} = test_request:get(ViewUrl, [?AUTH]),
+
+ ?assertEqual(500, Status),
+ {Props} = couch_util:json_decode(Body),
+ {<<"error">>, Error} = lists:keyfind(<<"error">>, 1, Props),
+ ?assertEqual(<<"foundationdb_error">>, Error).
+
+
+ddoc() ->
+ couch_doc:from_json_obj({[
+ {<<"_id">>, <<"_design/foo">>},
+ {<<"language">>, <<"javascript">>},
+ {<<"views">>, {[
+ {<<"bar">>, {[
+ {<<"map">>, <<"function(doc) {emit(doc.value, doc.value);}">>}
+ ]}}
+ ]}}
+ ]}).
diff --git a/test/elixir/test/map_test.exs b/test/elixir/test/map_test.exs
index 9254cc4c3..3e2765fbd 100644
--- a/test/elixir/test/map_test.exs
+++ b/test/elixir/test/map_test.exs
@@ -503,38 +503,6 @@ defmodule ViewMapTest do
assert keys == ["bar"]
end
- test "send error for failed indexing", context do
- db_name = context[:db_name]
-
- docs = [
- %{_id: "doc1", foo: "foo", bar: "bar"},
- %{
- _id: "_design/view1",
- views: %{
- view: %{
- map: """
- function (doc) {
- for (var i=0; i<10000; i++) {
- emit({doc: doc._id + 1}, doc._id);
- }
- }
- """
- }
- }
- }
- ]
-
- resp = Couch.post("/#{db_name}/_bulk_docs", body: %{:docs => docs})
- assert resp.status_code == 201
-
- url = "/#{db_name}/_design/view1/_view/view"
-
- resp = Couch.get(url, timeout: 500_000)
- assert resp.status_code == 500
- %{:body => %{"error" => error}} = resp
- assert error == "foundationdb_error"
- end
-
test "descending=true query with startkey_docid", context do
db_name = context[:db_name]