Skip to content

Commit

Permalink
[FOLD] fix travis errors
Browse files Browse the repository at this point in the history
  • Loading branch information
undertome committed Jul 11, 2021
1 parent 3a95c3f commit 3280111
Showing 1 changed file with 62 additions and 14 deletions.
76 changes: 62 additions & 14 deletions src/test/rpc/NodeToShardRPC_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ class NodeToShardRPC_test : public beast::unit_test::suite
env.close();
}

auto shardStore = env.app().getShardStore();
BEAST_EXPECT(shardStore);

auto importCompleted = [shardStore, this](auto const& result) {
auto const info = shardStore->getShardInfo();

// Assume completed if the import isn't running
auto const completed =
result[jss::error_message] == "Database import not running";

if (completed)
{
BEAST_EXPECT(
info->incomplete().size() + info->finalized().size() ==
numberOfShards);
}

return completed;
};

{
// Initiate a shard store import via the RPC
// interface.
Expand All @@ -75,6 +95,12 @@ class NodeToShardRPC_test : public beast::unit_test::suite
result[jss::message] == "Database import initiated...");
}

while (!shardStore->getDatabaseImportSequence())
{
// Wait until the import starts
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}

{
// Verify that the import is in progress with
// the node_to_shard status RPC command
Expand All @@ -85,10 +111,8 @@ class NodeToShardRPC_test : public beast::unit_test::suite
auto const result = env.rpc(
"json", "node_to_shard", to_string(jvParams))[jss::result];

BEAST_EXPECT(result[jss::status] == "success");

auto shardStore = env.app().getShardStore();
BEAST_EXPECT(shardStore);
BEAST_EXPECT(
result[jss::status] == "success" || importCompleted(result));

std::chrono::seconds const maxWait{30};
auto const start = std::chrono::system_clock::now();
Expand All @@ -108,8 +132,11 @@ class NodeToShardRPC_test : public beast::unit_test::suite
"node_to_shard",
to_string(jvParams))[jss::result];

BEAST_EXPECT(result[jss::firstShardIndex] == 1);
BEAST_EXPECT(result[jss::lastShardIndex] == 10);
if (!importCompleted(result))
{
BEAST_EXPECT(result[jss::firstShardIndex] == 1);
BEAST_EXPECT(result[jss::lastShardIndex] == 10);
}
}

if (boost::icl::contains(completeShards, 1))
Expand All @@ -119,7 +146,10 @@ class NodeToShardRPC_test : public beast::unit_test::suite
"node_to_shard",
to_string(jvParams))[jss::result];

BEAST_EXPECT(result[jss::currentShardIndex] >= 1);
BEAST_EXPECT(
result[jss::currentShardIndex] >= 1 ||
importCompleted(result));

break;
}

Expand All @@ -139,8 +169,7 @@ class NodeToShardRPC_test : public beast::unit_test::suite
if (std::this_thread::sleep_for(std::chrono::milliseconds{100});
std::chrono::system_clock::now() - start > maxWait)
{
BEAST_EXPECTS(
false, "Import timeout: could just be a slow machine.");
BEAST_EXPECT(importCompleted(result));
break;
}
}
Expand Down Expand Up @@ -178,6 +207,26 @@ class NodeToShardRPC_test : public beast::unit_test::suite
env.close();
}

auto shardStore = env.app().getShardStore();
BEAST_EXPECT(shardStore);

auto importCompleted = [shardStore, this](auto const& result) {
auto const info = shardStore->getShardInfo();

// Assume completed if the import isn't running
auto const completed =
result[jss::error_message] == "Database import not running";

if (completed)
{
BEAST_EXPECT(
info->incomplete().size() + info->finalized().size() ==
numberOfShards);
}

return completed;
};

{
// Initiate a shard store import via the RPC
// interface.
Expand All @@ -202,10 +251,8 @@ class NodeToShardRPC_test : public beast::unit_test::suite
auto const result = env.rpc(
"json", "node_to_shard", to_string(jvParams))[jss::result];

BEAST_EXPECT(result[jss::status] == "success");

auto shardStore = env.app().getShardStore();
BEAST_EXPECT(shardStore);
BEAST_EXPECT(
result[jss::status] == "success" || importCompleted(result));

std::chrono::seconds const maxWait{10};
auto const start = std::chrono::system_clock::now();
Expand All @@ -232,7 +279,8 @@ class NodeToShardRPC_test : public beast::unit_test::suite
"json", "node_to_shard", to_string(jvParams))[jss::result];

BEAST_EXPECT(
result[jss::message] == "Database import halt initiated...");
result[jss::message] == "Database import halt initiated..." ||
importCompleted(result));
}

std::chrono::seconds const maxWait{10};
Expand Down

0 comments on commit 3280111

Please sign in to comment.