Skip to content

Commit

Permalink
Fix hashtree:sha_test_ from timing out
Browse files Browse the repository at this point in the history
EQC takes a long time, and uses gigabytes of memory to generate 1MB
random binaries, as evidenced by:

    eqc_gen:sample(eqc_gen:binary(1024 * 1024)).

We're still able to write a solid test, by ensuring that we always chunk
the binary into between 1 and 16 chunks. So instead of generating the
chunk size, we now generate the number of chunks, and derive chunk size
from that. This change allowed us to remove one level of ?FORALL
nesting, as well.
  • Loading branch information
reiddraper committed May 22, 2014
1 parent ba2a678 commit 602e3ab
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/hashtree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1129,10 +1129,18 @@ sha_test_() ->
}.

prop_sha() ->
?FORALL(Size, choose(256, 1024*1024),
?FORALL(Chunk, choose(1, Size),
%% NOTE: Generating 1MB (1024 * 1024) size binaries is incredibly slow
%% with EQC and was using over 2GB of memory
?FORALL({Size, NumChunks}, {choose(1, 1024), choose(1, 16)},
?FORALL(Bin, binary(Size),
sha(Chunk, Bin) =:= esha(Bin)))).
begin
%% we need at least one chunk,
%% and then we divide the binary size
%% into the number of chunks (as a natural
%% number)
ChunkSize = max(1, (Size div NumChunks)),
sha(ChunkSize, Bin) =:= esha(Bin)
end)).

eqc_test_() ->
{timeout, 5,
Expand Down

3 comments on commit 602e3ab

@borshop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from kellymclaughlin
at 602e3ab

@borshop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging basho/riak_core/bugfix/hashtree-prop_sha-timeout = 602e3ab into borshop-integration-587-bugfix/hashtree-prop_sha-timeout

@borshop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basho/riak_core/bugfix/hashtree-prop_sha-timeout = 602e3ab merged ok, testing candidate = 1d196e9

Please sign in to comment.