Make unit tests repeatable

This commit is contained in:
seelabs
2017-08-24 14:38:50 -04:00
parent 5fe65c5906
commit 6ff5d3734f
2 changed files with 35 additions and 20 deletions

View File

@@ -58,9 +58,13 @@ public:
// When booted, we just get a null json response
if(jv.isNull())
booted = true;
else
BEAST_EXPECT(jv.isMember(jss::status)
&& (jv[jss::status] == "success"));
else if (!(jv.isMember(jss::status) &&
(jv[jss::status] == "success")))
{
// Don't use BEAST_EXPECT above b/c it will be called a non-deterministic number of times
// and the number of tests run should be deterministic
fail();
}
if(jv.isMember(jss::warning))
warned = jv[jss::warning] == jss::load;

View File

@@ -24,6 +24,7 @@
#include <ripple/basics/random.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/beast/unit_test.h>
#include <ripple/beast/xor_shift_engine.h>
namespace ripple {
namespace tests {
@@ -31,12 +32,14 @@ namespace tests {
class sync_test : public beast::unit_test::suite
{
public:
static std::shared_ptr<SHAMapItem> makeRandomAS ()
beast::xor_shift_engine eng_;
std::shared_ptr<SHAMapItem> makeRandomAS ()
{
Serializer s;
for (int d = 0; d < 3; ++d)
s.add32 (rand_int<std::uint32_t>());
s.add32 (rand_int<std::uint32_t>(eng_));
return std::make_shared<SHAMapItem>(
s.getSHA512Half(), s.peekData ());
@@ -140,8 +143,8 @@ public:
SHAMapNodeID (),
gotNodeIDs_a,
gotNodes_a,
rand_bool(),
rand_int(2)));
rand_bool(eng_),
rand_int(eng_, 2)));
unexpected (gotNodes_a.size () < 1, "NodeSize");
@@ -168,24 +171,32 @@ public:
for (auto& it : nodesMissing)
{
BEAST_EXPECT(source.getNodeFat (
it.first,
gotNodeIDs_b,
gotNodes_b,
rand_bool(),
rand_int(2)));
// Don't use BEAST_EXPECT here b/c it will be called a non-deterministic number of times
// and the number of tests run should be deterministic
if (!source.getNodeFat(
it.first,
gotNodeIDs_b,
gotNodes_b,
rand_bool(eng_),
rand_int(eng_, 2)))
fail();
}
BEAST_EXPECT(gotNodeIDs_b.size () == gotNodes_b.size ());
BEAST_EXPECT(!gotNodeIDs_b.empty ());
// Don't use BEAST_EXPECT here b/c it will be called a non-deterministic number of times
// and the number of tests run should be deterministic
if (gotNodeIDs_b.size() != gotNodes_b.size() ||
gotNodeIDs_b.empty())
fail();
for (std::size_t i = 0; i < gotNodeIDs_b.size(); ++i)
{
BEAST_EXPECT(
destination.addKnownNode (
gotNodeIDs_b[i],
makeSlice(gotNodes_b[i]),
nullptr).isUseful ());
// Don't use BEAST_EXPECT here b/c it will be called a non-deterministic number of times
// and the number of tests run should be deterministic
if (!destination
.addKnownNode(
gotNodeIDs_b[i], makeSlice(gotNodes_b[i]), nullptr)
.isUseful())
fail();
}
}
while (true);