mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Make unit tests repeatable
This commit is contained in:
@@ -58,9 +58,13 @@ public:
|
|||||||
// When booted, we just get a null json response
|
// When booted, we just get a null json response
|
||||||
if(jv.isNull())
|
if(jv.isNull())
|
||||||
booted = true;
|
booted = true;
|
||||||
else
|
else if (!(jv.isMember(jss::status) &&
|
||||||
BEAST_EXPECT(jv.isMember(jss::status)
|
(jv[jss::status] == "success")))
|
||||||
&& (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))
|
if(jv.isMember(jss::warning))
|
||||||
warned = jv[jss::warning] == jss::load;
|
warned = jv[jss::warning] == jss::load;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include <ripple/basics/random.h>
|
#include <ripple/basics/random.h>
|
||||||
#include <ripple/basics/StringUtilities.h>
|
#include <ripple/basics/StringUtilities.h>
|
||||||
#include <ripple/beast/unit_test.h>
|
#include <ripple/beast/unit_test.h>
|
||||||
|
#include <ripple/beast/xor_shift_engine.h>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
namespace tests {
|
namespace tests {
|
||||||
@@ -31,12 +32,14 @@ namespace tests {
|
|||||||
class sync_test : public beast::unit_test::suite
|
class sync_test : public beast::unit_test::suite
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static std::shared_ptr<SHAMapItem> makeRandomAS ()
|
beast::xor_shift_engine eng_;
|
||||||
|
|
||||||
|
std::shared_ptr<SHAMapItem> makeRandomAS ()
|
||||||
{
|
{
|
||||||
Serializer s;
|
Serializer s;
|
||||||
|
|
||||||
for (int d = 0; d < 3; ++d)
|
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>(
|
return std::make_shared<SHAMapItem>(
|
||||||
s.getSHA512Half(), s.peekData ());
|
s.getSHA512Half(), s.peekData ());
|
||||||
@@ -140,8 +143,8 @@ public:
|
|||||||
SHAMapNodeID (),
|
SHAMapNodeID (),
|
||||||
gotNodeIDs_a,
|
gotNodeIDs_a,
|
||||||
gotNodes_a,
|
gotNodes_a,
|
||||||
rand_bool(),
|
rand_bool(eng_),
|
||||||
rand_int(2)));
|
rand_int(eng_, 2)));
|
||||||
|
|
||||||
unexpected (gotNodes_a.size () < 1, "NodeSize");
|
unexpected (gotNodes_a.size () < 1, "NodeSize");
|
||||||
|
|
||||||
@@ -168,24 +171,32 @@ public:
|
|||||||
|
|
||||||
for (auto& it : nodesMissing)
|
for (auto& it : nodesMissing)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(source.getNodeFat (
|
// Don't use BEAST_EXPECT here b/c it will be called a non-deterministic number of times
|
||||||
it.first,
|
// and the number of tests run should be deterministic
|
||||||
gotNodeIDs_b,
|
if (!source.getNodeFat(
|
||||||
gotNodes_b,
|
it.first,
|
||||||
rand_bool(),
|
gotNodeIDs_b,
|
||||||
rand_int(2)));
|
gotNodes_b,
|
||||||
|
rand_bool(eng_),
|
||||||
|
rand_int(eng_, 2)))
|
||||||
|
fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
BEAST_EXPECT(gotNodeIDs_b.size () == gotNodes_b.size ());
|
// Don't use BEAST_EXPECT here b/c it will be called a non-deterministic number of times
|
||||||
BEAST_EXPECT(!gotNodeIDs_b.empty ());
|
// 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)
|
for (std::size_t i = 0; i < gotNodeIDs_b.size(); ++i)
|
||||||
{
|
{
|
||||||
BEAST_EXPECT(
|
// Don't use BEAST_EXPECT here b/c it will be called a non-deterministic number of times
|
||||||
destination.addKnownNode (
|
// and the number of tests run should be deterministic
|
||||||
gotNodeIDs_b[i],
|
if (!destination
|
||||||
makeSlice(gotNodes_b[i]),
|
.addKnownNode(
|
||||||
nullptr).isUseful ());
|
gotNodeIDs_b[i], makeSlice(gotNodes_b[i]), nullptr)
|
||||||
|
.isUseful())
|
||||||
|
fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (true);
|
while (true);
|
||||||
|
|||||||
Reference in New Issue
Block a user