Skip to content
This repository
Browse code

Clean up bitcask_eqc.erl

* Allow any test process to call incr_clock()
* Clean up unused var warnings
* Add explicit support to run on local or slave node, default = local
* Comment out the useful but now (I hope) unnecessary scribbling of
  the test inputs to a /tmp scratch file before executing.
* prop_pulse_test_() runs for 60 seconds
* Fix fork_results() `after` timeout to avoid false positives when
  the test case is really huge.
  • Loading branch information...
commit b350fb5907a390231f0cf849736eecf1e44aa43f 1 parent 20dfed4
Scott Lystig Fritchie slfritchie authored

Showing 1 changed file with 26 additions and 14 deletions. Show diff stats Hide diff stats

  1. +26 14 test/pulse/bitcask_eqc.erl
40 test/pulse/bitcask_eqc.erl
@@ -70,7 +70,8 @@ command(S) ->
70 70 [ {2, {call, ?MODULE, fork, [not_commands(?MODULE, #state{ is_writer = false })]}}
71 71 || S#state.is_writer ] ++
72 72 [ {30, {call, ?MODULE, incr_clock, []}}
73   - || true ] ++
  73 + %% Any proc can call incr_clock
  74 + ] ++
74 75 [ {10, {call, ?MODULE, get, [S#state.handle, key()]}}
75 76 || S#state.handle /= undefined ] ++
76 77 [ {20, {call, ?MODULE, put, [S#state.handle, key(), value()]}}
@@ -104,7 +105,7 @@ command(S) ->
104 105 %% Precondition, checked before a command is added to the command sequence.
105 106 precondition(S, {call, _, fork, _}) ->
106 107 S#state.is_writer;
107   -precondition(S, {call, _, incr_clock, _}) ->
  108 +precondition(_S, {call, _, incr_clock, _}) ->
108 109 true;
109 110 precondition(S, {call, _, get, [H, _]}) ->
110 111 S#state.handle == H;
@@ -255,7 +256,9 @@ start_node(Verbose) ->
255 256 stop_node() ->
256 257 slave:stop(node_name()).
257 258
258   -run_on_node(Verbose, M, F, A) ->
  259 +run_on_node(local, _Verbose, M, F, A) ->
  260 + rpc:call(node(), M, F, A);
  261 +run_on_node(slave, Verbose, M, F, A) ->
259 262 start_node(Verbose),
260 263 rpc:call(node_name(), M, F, A).
261 264
@@ -266,8 +269,11 @@ mute(false, Fun) -> mute:run(Fun).
266 269 %%
267 270 %% The actual code of the property, run on remote node via rpc:call above
268 271 %%
269   -run_commands_on_node(Cmds, Seed, Verbose) ->
  272 +run_commands_on_node(LocalOrSlave, Cmds, Seed, Verbose) ->
270 273 mute(Verbose, fun() ->
  274 + AfterTime = if LocalOrSlave == local -> 50000;
  275 + LocalOrSlave == remote -> 1000000
  276 + end,
271 277 event_logger:start_link(),
272 278 pulse:start(),
273 279 bitcask_nifs:set_pulse_pid(utils:whereis(pulse)),
@@ -275,21 +281,21 @@ run_commands_on_node(Cmds, Seed, Verbose) ->
275 281 error_logger:add_report_handler(handle_errors),
276 282 token:next_name(),
277 283 event_logger:start_logging(),
278   - bitcask_time:test__set_fudge(0),
  284 + bitcask_time:test__set_fudge(10),
279 285 X =
280 286 try
281 287 {H, S, Res, PidRs, Trace} = pulse:run(fun() ->
282 288 %% pulse_application_controller:start({application, kernel, []}),
283 289 application:start(bitcask),
284   - receive after 1000000 -> ok end,
  290 + receive after AfterTime -> ok end,
285 291 OldVerbose = pulse:verbose([ all || Verbose ]),
286 292 {H, S, R} = run_commands(?MODULE, Cmds),
287 293 Pids = lists:usort(S#state.readers),
288 294 PidRs = fork_results(Pids),
289   - receive after 1000000 -> ok end,
  295 + receive after AfterTime -> ok end,
290 296 pulse:verbose(OldVerbose),
291 297 Trace = event_logger:get_events(),
292   - receive after 1000000 -> ok end,
  298 + receive after AfterTime -> ok end,
293 299 exit(pulse_application_controller, shutdown),
294 300 {H, S, R, PidRs, Trace}
295 301 end, [{seed, Seed},
@@ -305,13 +311,19 @@ run_commands_on_node(Cmds, Seed, Verbose) ->
305 311 X end).
306 312
307 313 prop_pulse() ->
308   - prop_pulse(false).
  314 + prop_pulse(local, false).
309 315
310   -prop_pulse(Verbose) ->
311   - ?FORALL(Cmds, ?LET(Cmds, more_commands(2, commands(?MODULE)), shrink_commands(Cmds)),
  316 +prop_pulse(Boolean) ->
  317 + prop_pulse(local, Boolean).
  318 +
  319 +prop_pulse(LocalOrSlave, Verbose) ->
  320 + More = 2,
  321 + if More < 2 -> [erlang:display({"NOTE: we are using a perhaps small More value?", More}) || _ <- lists:seq(1,10)]; true -> ok end,
  322 + ?FORALL(Cmds, ?LET(Cmds, more_commands(More, commands(?MODULE)), shrink_commands(Cmds)),
312 323 ?FORALL(Seed, pulse:seed(),
313 324 begin
314   - case run_on_node(Verbose, ?MODULE, run_commands_on_node, [Cmds, Seed, Verbose]) of
  325 + %% ok = file:write_file("/tmp/slf-stuff-just-in-case", term_to_binary({Cmds,Seed})),
  326 + case run_on_node(LocalOrSlave, Verbose, ?MODULE, run_commands_on_node, [LocalOrSlave, Cmds, Seed, Verbose]) of
315 327 {'EXIT', Err} ->
316 328 equals({'EXIT', Err}, ok);
317 329 {H, S, Res, PidRs, Trace, Schedule, Errors} ->
@@ -337,7 +349,7 @@ prop_pulse_test_() ->
337 349 {timeout, 1000000,
338 350 fun() ->
339 351 copy_bitcask_app(),
340   - ?assert(eqc:quickcheck(eqc:testing_time(10,?QC_OUT(prop_pulse()))))
  352 + ?assert(eqc:quickcheck(eqc:testing_time(60,?QC_OUT(prop_pulse()))))
341 353 end}.
342 354
343 355 %% Needed since rebar fails miserably in setting up the .eunit test directory
@@ -537,7 +549,7 @@ command_data({set, _, {call, _, Fun, _}}, {_S, _V}) ->
537 549 fork_results(Pids) ->
538 550 [ receive
539 551 {Pid, done, R} -> {I, R}
540   - after 10*1000 -> {I, timeout}
  552 + after 99*1000 -> {I, timeout_fork_results}
541 553 end || {I, Pid} <- lists:zip(lists:seq(1, length(Pids)), Pids) ].
542 554
543 555 %% Implementation of a the commands

0 comments on commit b350fb5

Please sign in to comment.
Something went wrong with that request. Please try again.