blob: b6b7bad123d51bbfc8bd450fa131091661efd681 [file] [log] [blame]
% 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
% 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.
all_test_() ->
{setup, fun setup/0, fun cleanup/1, fun instantiate/1}.
setup() ->
Apps = test_util:start_applications([
config, folsom, couch_log, couch_stats, ioq
FakeServer = fun(F) ->
receive {'$gen_call', {Pid, Ref}, Call} ->
Pid ! {Ref, {reply, Call}}
{Apps, spawn(fun() -> FakeServer(FakeServer) end)}.
cleanup({Apps, Server}) ->
exit(Server, kill).
instantiate({_, S}) ->
[{inparallel, lists:map(fun(IOClass) ->
lists:map(fun(Shard) ->
check_call(S, make_ref(), priority(IOClass, Shard))
end, shards())
end, io_classes())},
?_assertEqual(20, ioq:set_disk_concurrency(10)),
?_assertError(badarg, ioq:set_disk_concurrency(0)),
?_assertError(badarg, ioq:set_disk_concurrency(-1)),
?_assertError(badarg, ioq:set_disk_concurrency(foo))].
check_call(Server, Call, Priority) ->
?_assertEqual({reply, Call}, ioq:call(Server, Call, Priority)).
io_classes() -> [interactive, view_update, db_compact, view_compact,
internal_repl, other].
shards() ->
priority(view_update, Shard) ->
{view_update, Shard, <<"_design/foo">>};
priority(Any, Shard) ->
{Any, Shard}.