Skip to content

Commit 1695ca4

Browse files
committed
Merge branch 'eqc-1' into 'master'
Further quickcheck tests Closes #8 and #9 See merge request barrel-db/barrel!4
2 parents b471038 + 810d3d5 commit 1695ca4

6 files changed

+52
-34
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ clean:
2424
@$(REBAR) clean
2525

2626
distclean: clean ## Clean all build and releases artifacts
27-
rm -rf _build
27+
@rm -rf _build
28+
@rm -rf data
2829

2930
cleantest:
3031
@rm -rf _build/test

eqc/barrel_rpc_events_eqc.erl

+16-16
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ get_command(_S = #state{keys = Dict , replicate= R, db= DBS =[D|_]}) ->
6767
false -> D
6868
end,
6969
oneof([
70-
{call, ?MODULE, get,
71-
[DB,
72-
oneof(dict:fetch_keys(Dict)),
70+
{call, ?MODULE, get,
71+
[DB,
72+
oneof(dict:fetch_keys(Dict)),
7373
Dict, oneof(['history', 'nothing'])]},
74-
{call, ?MODULE, get,
74+
{call, ?MODULE, get,
7575
[DB, id(), Dict, 'nothing']}
7676
]).
7777

@@ -92,7 +92,7 @@ get(DB, Id , _Dict, 'history') ->
9292
end;
9393

9494
get(DB, Id, _Dict, _) ->
95-
case barrel:get(DB, Id, #{}) of
95+
case barrel:get(DB, Id, #{}) of
9696
{ok, Doc, Meta} ->
9797
{Doc, Meta};
9898
{error, not_found} ->
@@ -120,7 +120,7 @@ get_next(S= #state{cmds = C},_,_) ->
120120

121121

122122
get_post(#state{keys= Dict}, [_DB, Id,_, _], {error, not_found}) ->
123-
123+
124124
not(dict:is_key(Id, Dict));
125125

126126

@@ -147,7 +147,7 @@ get_post(#state{keys= Dict}, [_DB, Id|_ ],
147147

148148
{ok, #doc{id = Id,
149149
value = V}} = dict:find(Id, Dict),
150-
150+
151151
lists:keymember(Rev,1,V).
152152

153153

@@ -236,7 +236,7 @@ post_command(S = #state{keys = _Dict}) ->
236236
post_pre(#state{replicate = false}, [<<"test02">>, _Doc, _Meta])->
237237
false;
238238
post_pre(#state{keys=Dict},[_, Id|_]) ->
239-
not(dict:is_key(Id, Dict)).
239+
not(dict:is_key(Id, Dict)).
240240

241241

242242
post (DB, Doc = #{<<"id">> := Id}, Opts) ->
@@ -271,11 +271,11 @@ post_next(State = #state{keys = Dict,
271271
put_pre(#state{keys = Dict}) ->
272272
not(dict:is_empty(Dict)) .
273273

274-
274+
275275
put_pre(#state{replicate={var,_}}, [<<"test02">>|_]) ->
276276
false;
277277
put_pre(#state{keys=Dict},[_, Id|_]) ->
278-
dict:is_key(Id, Dict).
278+
dict:is_key(Id, Dict).
279279

280280

281281

@@ -331,7 +331,7 @@ put_rev_pre(#state{keys = Dict}) ->
331331
put_rev_pre(#state{replicate={var,_}}, [<<"test02">>|_]) ->
332332
false;
333333
put_rev_pre(#state{keys=Dict},[_, Id|_]) ->
334-
dict:is_key(Id, Dict).
334+
dict:is_key(Id, Dict).
335335

336336

337337
put_rev_post(#state{keys = Dict} , [_DB, #{<<"id">> := Id}, #{},_], {error, {conflict, doc_exists}}) ->
@@ -354,10 +354,10 @@ put_rev_command(S = #state{keys = Dict}) ->
354354

355355
swap(DBS, Cmds) ->
356356
[swapDB(DBS, Cmd) || Cmd <- Cmds].
357-
357+
358358
swapDB([DB1,DB2], Cmd = [_|Rest]) ->
359359
[DB2|Rest].
360-
360+
361361

362362
getByPos(Pos, L= [A|_]) ->
363363
Arr = array:from_list(L, A),
@@ -472,13 +472,12 @@ command_precondition_common(_S, _Cmd) ->
472472
when S :: eqc_statem:dynamic_state(),
473473
Call :: eqc_statem:call(),
474474
Res :: term().
475-
postcondition_common(_S= #state{keys = Dict, db = [DB|_]}, _Call, _Res) ->
475+
postcondition_common(_S= #state{keys = _Dict, db = [DB|_]}, _Call, _Res) ->
476476

477477
case barrel:database_infos(DB) of
478478
{error,not_found} ->
479479
false;
480480
{ok, _A = #{docs_count := DocCount}} ->
481-
482481
case DocCount < 0
483482
of
484483
true ->
@@ -509,10 +508,11 @@ create_database(DB) ->
509508
{ok, _} -> barrel:delete_database(DB),
510509
timer:sleep(250),
511510
ok ;
512-
{error, not_found} -> ok
511+
{error, db_not_found} -> ok
513512
end,
514513
barrel:create_database(#{<<"database_id">> => DB}).
515514

515+
516516
cleanup() ->
517517
common_eqc:cleanup().
518518

eqc/common_eqc.erl

+7-5
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ delete_db() ->
3434

3535

3636
ascii_string() ->
37-
?LET(S,
38-
non_empty(list(oneof([choose($0,$9),
39-
choose($A,$Z),
40-
choose($a,$z)]))),
41-
list_to_binary(S)
37+
?LET({S,Ss},
38+
{choose($a,$z),
39+
non_empty(list(oneof([choose($a,$z),
40+
choose($0,$9)
41+
]
42+
)))},
43+
list_to_binary([S|Ss] )
4244
).

eqc/create_delete_database_eqc.erl

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ prop_create_delete_database() ->
2020
begin
2121
L = length( barrel:database_names()),
2222
[begin
23-
Id = I,
24-
{ok, #{<<"database_id">> := Id}} =
23+
{ok, #{<<"database_id">> := Id}} =
2524
barrel:create_database(#{<<"database_id">> => Id}),
2625
barrel:post(Id, #{<<"id">> => <<"1234">>,<<"content">> => <<"A">>}, #{}),
27-
ok = barrel:delete_database(Id)
28-
end|| I <- DBS],
26+
ok = barrel:delete_database(Id),
27+
{error, db_not_found} = barrel:post(Id, #{<<"id">> => <<"1234">>,<<"content">> => <<"A">>}, #{})
28+
29+
end|| Id <- DBS],
2930
L1 = length( barrel:database_names()),
3031
L == L1
3132
end)).
32-
33-

eqc/run_tests.erl

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ run_quickcheck_test_() ->
1616
barrel_change_since_eqc,
1717
barrel_rpc_events_eqc,
1818
create_delete_database_eqc,
19-
barrel_rpc_eqc],
20-
19+
barrel_rpc_eqc
20+
],
21+
2122
{timeout, 36000,
22-
[?_assertEqual([], eqc:module({numtests,30} , M)) || M <-Mods
23+
[?_assertEqual([], eqc:module({numtests,100} , M)) || M <-Mods
2324
]}.

rebar.config

+18-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
{erl_opts, [
77
warn_unused_vars,
8-
warnings_as_errors,
9-
warn_export_all,
8+
% warnings_as_errors,
9+
% warn_export_all,
1010
warn_shadow_vars,
1111
warn_unused_import,
1212
warn_unused_function,
@@ -40,6 +40,7 @@
4040
]}.
4141

4242

43+
4344
{eunit_opts, [{dir, "src"}]}.
4445

4546

@@ -67,7 +68,21 @@
6768
{include_src, false},
6869
{extended_start_script, true}
6970
]}
70-
]}
71+
]},
72+
{eqc,
73+
[{src_dirs, ["src","eqc"]},
74+
{deps, [
75+
{uuid, {git, "git://github.com/okeuday/uuid.git", {tag, "v1.5.2-rc1"}}},
76+
{sync, {git, "git://github.com/rustyio/sync.git", {branch, "master"}}}
77+
78+
]},
79+
{erl_opts,[ {parse_transform, eqc_cover},
80+
{parse_transform, lager_transform}
81+
]},
82+
{sasl, [
83+
{sasl_error_logger, false}
84+
]}]}
85+
7186
]}.
7287

7388

0 commit comments

Comments
 (0)