diff --git a/src/test/rpc/NodeToShardRPC_test.cpp b/src/test/rpc/NodeToShardRPC_test.cpp index 58595ecad93..eb1d9471930 100644 --- a/src/test/rpc/NodeToShardRPC_test.cpp +++ b/src/test/rpc/NodeToShardRPC_test.cpp @@ -61,6 +61,28 @@ 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) + { + // If assumption is correct, these should be + // true + BEAST_EXPECT( + info->incomplete().size() == 0 && + info->finalized().size() == numberOfShards); + } + + return completed; + }; + { // Initiate a shard store import via the RPC // interface. @@ -75,6 +97,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 @@ -85,10 +113,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(); @@ -108,8 +134,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)) @@ -119,7 +148,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; } @@ -178,6 +210,28 @@ 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) + { + // If assumption is correct, these should be + // true + BEAST_EXPECT( + info->incomplete().size() == 0 && + info->finalized().size() == numberOfShards); + } + + return completed; + }; + { // Initiate a shard store import via the RPC // interface. @@ -202,10 +256,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(); @@ -232,7 +284,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};