summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2020-01-21 10:20:08 -0500
committerNick Vatamaniuc <nickva@users.noreply.github.com>2020-01-21 10:51:19 -0500
commit3e0dd6b6edb077de570b05e2acec0a857563be53 (patch)
tree6830a46fa770cca15090c1263d735e828afe7ea8
parent2ac0673824dff1606e04741d83cd14964fb60481 (diff)
downloadcouchdb-3e0dd6b6edb077de570b05e2acec0a857563be53.tar.gz
Replace Triq with PropEr
It was already used in the IOQ2 work so all the plumbing to pull it in during dev testing was there and it seems awkward to have two different property testing framework for just a few tests. It is still an optional component and is not included in the release.
-rw-r--r--mix.exs1
-rw-r--r--rebar.config.script2
-rw-r--r--src/couch/include/couch_eunit_proper.hrl29
-rw-r--r--src/couch/rebar.config.script7
-rw-r--r--src/couch/test/eunit/couch_key_tree_prop_tests.erl40
-rw-r--r--src/mem3/rebar.config.script22
-rw-r--r--src/mem3/test/eunit/mem3_ring_prop_tests.erl17
7 files changed, 90 insertions, 28 deletions
diff --git a/mix.exs b/mix.exs
index 4432b1c83..d717e4b4a 100644
--- a/mix.exs
+++ b/mix.exs
@@ -109,7 +109,6 @@ defmodule CouchDBTest.Mixfile do
"bear",
"mochiweb",
"snappy",
- "triq",
"rebar",
"proper",
"mochiweb",
diff --git a/rebar.config.script b/rebar.config.script
index e39a08228..a2e19229e 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -155,7 +155,7 @@ DepDescs = [
{tag, "v1.2.2"}, [raw]},
%% Third party deps
{folsom, "folsom", {tag, "CouchDB-0.8.3"}},
-{hyper, "hyper", {tag, "CouchDB-2.2.0-4"}},
+{hyper, "hyper", {tag, "CouchDB-2.2.0-6"}},
{ibrowse, "ibrowse", {tag, "CouchDB-4.0.1-1"}},
{jiffy, "jiffy", {tag, "CouchDB-0.14.11-2"}},
{mochiweb, "mochiweb", {tag, "v2.20.0"}},
diff --git a/src/couch/include/couch_eunit_proper.hrl b/src/couch/include/couch_eunit_proper.hrl
new file mode 100644
index 000000000..31ae40e9d
--- /dev/null
+++ b/src/couch/include/couch_eunit_proper.hrl
@@ -0,0 +1,29 @@
+% 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.
+
+-include_lib("proper/include/proper.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+
+-define(EUNIT_QUICKCHECK(QuickcheckTimeout),
+ [
+ {
+ atom_to_list(F),
+ {timeout, QuickcheckTimeout,
+ ?_assert(proper:quickcheck(?MODULE:F(), [
+ {to_file, user},
+ {start_size, 2},
+ long_result
+ ]))}
+ }
+ || {F, 0} <- ?MODULE:module_info(exports), F > 'prop_', F < 'prop`'
+ ]).
diff --git a/src/couch/rebar.config.script b/src/couch/rebar.config.script
index a6468612c..c0889ce75 100644
--- a/src/couch/rebar.config.script
+++ b/src/couch/rebar.config.script
@@ -92,6 +92,11 @@ MD5Config = case lists:keyfind(erlang_md5, 1, CouchConfig) of
[]
end,
+ProperConfig = case code:lib_dir(proper) of
+ {error, bad_name} -> [];
+ _ -> [{d, 'WITH_PROPER'}]
+end,
+
{JS_CFLAGS, JS_LDFLAGS} = case os:type() of
{win32, _} when SMVsn == "1.8.5" ->
{
@@ -212,7 +217,7 @@ AddConfig = [
{d, 'COUCHDB_VERSION', Version},
{d, 'COUCHDB_GIT_SHA', GitSha},
{i, "../"}
- ] ++ MD5Config},
+ ] ++ MD5Config ++ ProperConfig},
{eunit_compile_opts, PlatformDefines}
].
diff --git a/src/couch/test/eunit/couch_key_tree_prop_tests.erl b/src/couch/test/eunit/couch_key_tree_prop_tests.erl
index f8146926a..9c09aace5 100644
--- a/src/couch/test/eunit/couch_key_tree_prop_tests.erl
+++ b/src/couch/test/eunit/couch_key_tree_prop_tests.erl
@@ -12,14 +12,21 @@
-module(couch_key_tree_prop_tests).
--include_lib("triq/include/triq.hrl").
--triq(eunit).
+
+-ifdef(WITH_PROPER).
+
+-include_lib("couch/include/couch_eunit_proper.hrl").
+
-define(SIZE_REDUCTION, 3). % How much to reduce size with tree depth.
-define(MAX_BRANCHES, 4). % Maximum number of branches.
-define(RAND_SIZE, 1 bsl 64).
+property_test_() ->
+ ?EUNIT_QUICKCHECK(60).
+
+
%
% Properties
%
@@ -116,10 +123,10 @@ prop_stemming_results_in_same_or_less_total_revs() ->
prop_stem_path_expect_size_to_get_smaller() ->
?FORALL({RevTree, StemDepth},
{
- ?SIZED(Size, resize(Size * 10, g_revtree([], 1))),
- choose(1,5)
+ ?SIZED(Size, g_revtree(Size * 10, [], 1)),
+ choose(1,3)
},
- ?IMPLIES(real_depth(RevTree) > 5,
+ ?IMPLIES(real_depth(RevTree) > 3,
begin
Stemmed = couch_key_tree:stem(RevTree, StemDepth),
StemmedKeys = lists:usort(keylist(Stemmed)),
@@ -224,7 +231,7 @@ g_revtree(Size, ERevs, MaxBranches) ->
g_treenode(0, Revs, _) ->
{elements(Revs), x, []};
g_treenode(Size, Revs, MaxBranches) ->
- ?DELAY(?LET(N, int(0, MaxBranches),
+ ?LAZY(?LET(N, choose(0, MaxBranches),
begin
[Rev | ChildRevs] = Revs,
{Rev, x, g_nodes(Size div ?SIZE_REDUCTION, N, ChildRevs, MaxBranches)}
@@ -261,17 +268,15 @@ g_stem_depth(Size) ->
% Uses the shuffle/1 function to shuffle the input list. Unshuffled list is
% used as the shrink value.
%
+g_shuffle([]) -> [];
g_shuffle(L) when is_list(L) ->
- triq_dom:domain(g_shuffle,
- fun(Self, _Size) -> {Self, shuffle(L)} end,
- fun(Self, _Val) -> {Self, L} end
- ).
+ ?LET(X, elements(L), [X | g_shuffle(lists:delete(X,L))]).
% Wrapper to make a list shuffling generator that doesn't shrink
%
g_shuffle_noshrink(L) when is_list(L) ->
- triq_dom:noshrink(g_shuffle(L)).
+ proper_types:noshrink(g_shuffle(L)).
% Generate shuffled sublists up to N items long from a list.
@@ -297,7 +302,7 @@ g_revs(Size, Existing) when is_integer(Size), is_list(Existing) ->
true -> % have extra, try various sublists
g_shuffled_sublists(Revs, Expected);
false ->
- triq_dom:return(Revs)
+ proper_types:return(Revs)
end.
@@ -319,19 +324,12 @@ same_keys(RevTree1, RevTree2) ->
all(L) ->
lists:all(fun(E) -> E end, L).
-% Shufle a list of items. Tag each item with a random number then sort
-% the list and remove the tags.
-%
-shuffle(L) ->
- Tagged = [{triq_rnd:uniform(), X} || X <- L],
- [X || {_, X} <- lists:sort(Tagged)].
-
% Generate list of relateively unique large random numbers
rand_list(N) when N =< 0 ->
[];
rand_list(N) ->
- [triq_rnd:uniform(?RAND_SIZE) || _ <- lists:seq(1, N)].
+ [rand:uniform(?RAND_SIZE) || _ <- lists:seq(1, N)].
% Generate a list of revisions to be used as key in revision trees. Expected
@@ -528,3 +526,5 @@ child_revs(ChildCount, Revs, Size, MaxBranches) ->
false ->
throw({not_enough_revisions, length(Revs), NeedKeys})
end.
+
+-endif.
diff --git a/src/mem3/rebar.config.script b/src/mem3/rebar.config.script
new file mode 100644
index 000000000..8f2deb4ae
--- /dev/null
+++ b/src/mem3/rebar.config.script
@@ -0,0 +1,22 @@
+%% 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.
+
+WithProper = code:lib_dir(proper) /= {error, bad_name}.
+
+if not WithProper -> CONFIG; true ->
+ CurrOpts = case lists:keyfind(erl_opts, 1, CONFIG) of
+ {erl_opts, Opts} -> Opts;
+ false -> []
+ end,
+ NewOpts = [{d, 'WITH_PROPER'} | CurrOpts],
+ lists:keystore(erl_opts, 1, CONFIG, {erl_opts, NewOpts})
+end.
diff --git a/src/mem3/test/eunit/mem3_ring_prop_tests.erl b/src/mem3/test/eunit/mem3_ring_prop_tests.erl
index 9f4f86f5f..51d8f10bf 100644
--- a/src/mem3/test/eunit/mem3_ring_prop_tests.erl
+++ b/src/mem3/test/eunit/mem3_ring_prop_tests.erl
@@ -13,8 +13,13 @@
-module(mem3_ring_prop_tests).
--include_lib("triq/include/triq.hrl").
--triq(eunit).
+-ifdef(WITH_PROPER).
+
+-include_lib("couch/include/couch_eunit_proper.hrl").
+
+
+property_test_() ->
+ ?EUNIT_QUICKCHECK(60).
% Properties
@@ -97,7 +102,7 @@ g_disconnected_intervals(Begin, End) ->
g_disconnected_intervals(Begin, End, Split) when Begin =< End ->
?LET(Connected, g_non_trivial_connected_intervals(Begin, End, Split),
begin
- I = triq_rnd:uniform(length(Connected)) - 1,
+ I = rand:uniform(length(Connected)) - 1,
{Before, [_ | After]} = lists:split(I, Connected),
Before ++ After
end).
@@ -131,14 +136,16 @@ rand_range(B, B) ->
B;
rand_range(B, E) ->
- B + triq_rnd:uniform(E - B).
+ B + rand:uniform(E - B).
shuffle(L) ->
- Tagged = [{triq_rnd:uniform(), X} || X <- L],
+ Tagged = [{rand:uniform(), X} || X <- L],
[X || {_, X} <- lists:sort(Tagged)].
endpoints(Ranges) ->
{Begins, Ends} = lists:unzip(Ranges),
sets:from_list(Begins ++ Ends).
+
+-endif.