diff --git a/.github/workflows/build-and-test.ubuntu-debug.yml b/.github/workflows/build-and-test.ubuntu-debug.yml index 92eca92eb7..3ca8a0d347 100644 --- a/.github/workflows/build-and-test.ubuntu-debug.yml +++ b/.github/workflows/build-and-test.ubuntu-debug.yml @@ -94,6 +94,9 @@ jobs: run: | _build/tests/app_test -l test_suite df -h + curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ + -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' + echo _build/tests/es_test -l test_suite df -h libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite diff --git a/.github/workflows/build-and-test.ubuntu-release.yml b/.github/workflows/build-and-test.ubuntu-release.yml index 9f30bf55ba..5f5be7fd12 100644 --- a/.github/workflows/build-and-test.ubuntu-release.yml +++ b/.github/workflows/build-and-test.ubuntu-release.yml @@ -73,6 +73,9 @@ jobs: - name: Unit-Tests run: | _build/tests/app_test -l test_suite + curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ + -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' + echo _build/tests/es_test -l test_suite libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite _build/tests/cli_test -l test_suite diff --git a/.github/workflows/sonar-scan.yml b/.github/workflows/sonar-scan.yml index f1afc20f3c..f9e07e8c0c 100644 --- a/.github/workflows/sonar-scan.yml +++ b/.github/workflows/sonar-scan.yml @@ -118,6 +118,9 @@ jobs: run: | _build/tests/app_test -l test_suite df -h + curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \ + -d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }' + echo _build/tests/es_test -l test_suite df -h libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite diff --git a/tests/app/main.cpp b/tests/app/main.cpp index a0d1b9b168..ba4b944819 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -42,10 +42,9 @@ #include "../../libraries/app/application_impl.hxx" -#define BOOST_TEST_MODULE Test Application -#include - +#include "../common/init_unit_test_suite.hpp" #include "../common/genesis_file_util.hpp" +#include "../common/utils.hpp" using namespace graphene; namespace bpo = boost::program_options; @@ -53,17 +52,6 @@ namespace bpo = boost::program_options; namespace fc { extern std::unordered_map &get_logger_map(); extern std::unordered_map &get_appender_map(); - - /** Waits for F() to return true before max_duration has passed. - */ - template - static void wait_for( const fc::microseconds max_duration, const Functor&& f ) - { - const auto start = fc::time_point::now(); - while( !f() && fc::time_point::now() < start + max_duration ) - fc::usleep(fc::milliseconds(100)); - BOOST_REQUIRE( f() ); - } } BOOST_AUTO_TEST_CASE(load_configuration_options_test_config_logging_files_created) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index cdaa707e3b..91c0af7cc6 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -60,8 +60,7 @@ #include -#define BOOST_TEST_MODULE Test Application -#include +#include "../common/init_unit_test_suite.hpp" /***** * Global Initialization for Windows diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index c70ed4cca1..a5f3e7b40d 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -54,7 +54,8 @@ using namespace graphene::chain::test; -uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; +extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; +extern std::string GRAPHENE_TESTING_ES_URL; namespace graphene { namespace chain { @@ -292,14 +293,22 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) current_test_name == "elasticsearch_history_api") { auto esplugin = app.register_plugin(true); - options.insert(std::make_pair("elasticsearch-node-url", boost::program_options::variable_value(string("http://localhost:9200/"), false))); - options.insert(std::make_pair("elasticsearch-bulk-replay", boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("elasticsearch-bulk-sync", boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("elasticsearch-start-es-after-block", boost::program_options::variable_value(uint32_t(0), false))); - options.insert(std::make_pair("elasticsearch-visitor", boost::program_options::variable_value(false, false))); - options.insert(std::make_pair("elasticsearch-operation-object", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("elasticsearch-operation-string", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("elasticsearch-mode", boost::program_options::variable_value(uint16_t(2), false))); + options.insert(std::make_pair("elasticsearch-node-url", + boost::program_options::variable_value(GRAPHENE_TESTING_ES_URL, false))); + options.insert(std::make_pair("elasticsearch-bulk-replay", + boost::program_options::variable_value(uint32_t(2), false))); + options.insert(std::make_pair("elasticsearch-bulk-sync", + boost::program_options::variable_value(uint32_t(2), false))); + options.insert(std::make_pair("elasticsearch-start-es-after-block", + boost::program_options::variable_value(uint32_t(0), false))); + options.insert(std::make_pair("elasticsearch-visitor", + boost::program_options::variable_value(false, false))); + options.insert(std::make_pair("elasticsearch-operation-object", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("elasticsearch-operation-string", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("elasticsearch-mode", + boost::program_options::variable_value(uint16_t(2), false))); es_index_prefix = string("bitshares-") + fc::to_string(uint64_t(rand())) + "-"; BOOST_TEST_MESSAGE( string("ES index prefix is ") + es_index_prefix ); @@ -319,15 +328,24 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) if(current_test_name == "elasticsearch_objects" || current_test_name == "elasticsearch_suite") { auto esobjects_plugin = app.register_plugin(true); - options.insert(std::make_pair("es-objects-elasticsearch-url", boost::program_options::variable_value(string("http://localhost:9200/"), false))); - options.insert(std::make_pair("es-objects-bulk-replay", boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("es-objects-bulk-sync", boost::program_options::variable_value(uint32_t(2), false))); - options.insert(std::make_pair("es-objects-proposals", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-accounts", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-assets", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-balances", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-limit-orders", boost::program_options::variable_value(true, false))); - options.insert(std::make_pair("es-objects-asset-bitasset", boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-elasticsearch-url", + boost::program_options::variable_value(GRAPHENE_TESTING_ES_URL, false))); + options.insert(std::make_pair("es-objects-bulk-replay", + boost::program_options::variable_value(uint32_t(2), false))); + options.insert(std::make_pair("es-objects-bulk-sync", + boost::program_options::variable_value(uint32_t(2), false))); + options.insert(std::make_pair("es-objects-proposals", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-accounts", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-assets", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-balances", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-limit-orders", + boost::program_options::variable_value(true, false))); + options.insert(std::make_pair("es-objects-asset-bitasset", + boost::program_options::variable_value(true, false))); es_obj_index_prefix = string("objects-") + fc::to_string(uint64_t(rand())) + "-"; BOOST_TEST_MESSAGE( string("ES_OBJ index prefix is ") + es_obj_index_prefix ); @@ -401,6 +419,41 @@ database_fixture::~database_fixture() } catch (...) { BOOST_FAIL( "Uncaught exception in ~database_fixture" ); } + + // cleanup data in ES + if( !es_index_prefix.empty() || !es_obj_index_prefix.empty() ) + { + CURL *curl; // curl handler + curl = curl_easy_init(); + curl_easy_setopt(curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); + + graphene::utilities::ES es; + es.curl = curl; + es.elasticsearch_url = GRAPHENE_TESTING_ES_URL; + + if( !es_index_prefix.empty() ) + { + es.index_prefix = es_index_prefix; + // delete all + try { + graphene::utilities::deleteAll(es); + } catch (...) { + // nothing to do + } + } + + if( !es_obj_index_prefix.empty() ) + { + es.index_prefix = es_obj_index_prefix; + // delete all + try { + graphene::utilities::deleteAll(es); + } catch (...) { + // nothing to do + } + } + } + } void database_fixture::vote_for_committee_and_witnesses(uint16_t num_committee, uint16_t num_witness) diff --git a/tests/common/init_unit_test_suite.hpp b/tests/common/init_unit_test_suite.hpp new file mode 100644 index 0000000000..472d1e7f14 --- /dev/null +++ b/tests/common/init_unit_test_suite.hpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include +#include +#include +#include +#include + +uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP = 1431700000; +std::string GRAPHENE_TESTING_ES_URL = "http://127.0.0.1:9200/"; + +boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { + const auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); + std::srand( seed ); + std::cout << "Random number generator seeded to " << seed << std::endl; + const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); + if( genesis_timestamp_str != nullptr ) + { + GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); + } + std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; + const char* env_es_url = getenv("GRAPHENE_TESTING_ES_URL"); + if( env_es_url != nullptr ) + { + std::string tmp_es_url( env_es_url ); + if( tmp_es_url.substr(0, 7) == "http://" || tmp_es_url.substr(0, 8) == "https://" ) + GRAPHENE_TESTING_ES_URL = tmp_es_url; + } + std::cout << "GRAPHENE_TESTING_ES_URL is " << GRAPHENE_TESTING_ES_URL << std::endl; + return nullptr; +} diff --git a/tests/common/utils.hpp b/tests/common/utils.hpp new file mode 100644 index 0000000000..b590331f64 --- /dev/null +++ b/tests/common/utils.hpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include + +namespace fc { + + /** Waits for F() to return true before max_duration has passed. + */ + template + static void wait_for( const fc::microseconds max_duration, const Functor&& f ) + { + const auto start = fc::time_point::now(); + while( !f() && fc::time_point::now() < start + max_duration ) + fc::usleep(fc::milliseconds(100)); + BOOST_REQUIRE( f() ); + } +} diff --git a/tests/elasticsearch/main.cpp b/tests/elasticsearch/main.cpp index 2935a047d8..eb254c559c 100644 --- a/tests/elasticsearch/main.cpp +++ b/tests/elasticsearch/main.cpp @@ -31,19 +31,17 @@ #include "../common/database_fixture.hpp" -#define BOOST_TEST_MODULE Elastic Search Database Tests -#include +#include "../common/init_unit_test_suite.hpp" +#include "../common/utils.hpp" -#ifdef NDEBUG - #define ES_WAIT_TIME (fc::milliseconds(1000)) -#else - #define ES_WAIT_TIME (fc::milliseconds(3000)) -#endif +#define ES_WAIT_TIME (fc::milliseconds(10000)) using namespace graphene::chain; using namespace graphene::chain::test; using namespace graphene::app; +extern std::string GRAPHENE_TESTING_ES_URL; + BOOST_FIXTURE_TEST_SUITE( elasticsearch_tests, database_fixture ) BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { @@ -54,14 +52,13 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { graphene::utilities::ES es; es.curl = curl; - es.elasticsearch_url = "http://localhost:9200/"; + es.elasticsearch_url = GRAPHENE_TESTING_ES_URL; es.index_prefix = es_index_prefix; - //es.auth = "elastic:changeme"; // delete all first auto delete_account_history = graphene::utilities::deleteAll(es); - fc::usleep(ES_WAIT_TIME); // this is because index.refresh_interval, nothing to worry + BOOST_REQUIRE(delete_account_history); // require successful deletion if(delete_account_history) { // all records deleted //account_id_type() do 3 ops @@ -70,20 +67,21 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { auto bob = create_account("bob"); generate_block(); - fc::usleep(ES_WAIT_TIME); - - // for later use - //int asset_create_op_id = operation::tag::value; - //int account_create_op_id = operation::tag::value; string query = "{ \"query\" : { \"bool\" : { \"must\" : [{\"match_all\": {}}] } } }"; es.endpoint = es.index_prefix + "*/data/_count"; es.query = query; - auto res = graphene::utilities::simpleQuery(es); - variant j = fc::json::from_string(res); - auto total = j["count"].as_string(); - BOOST_CHECK_EQUAL(total, "5"); + string res; + variant j; + string total; + + fc::wait_for( ES_WAIT_TIME, [&]() { + res = graphene::utilities::simpleQuery(es); + j = fc::json::from_string(res); + total = j["count"].as_string(); + return (total == "5"); + }); es.endpoint = es.index_prefix + "*/data/_search"; res = graphene::utilities::simpleQuery(es); @@ -95,14 +93,14 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { auto willie = create_account("willie"); generate_block(); - fc::usleep(ES_WAIT_TIME); // index.refresh_interval - es.endpoint = es.index_prefix + "*/data/_count"; - res = graphene::utilities::simpleQuery(es); - j = fc::json::from_string(res); - total = j["count"].as_string(); - BOOST_CHECK_EQUAL(total, "7"); + fc::wait_for( ES_WAIT_TIME, [&]() { + res = graphene::utilities::simpleQuery(es); + j = fc::json::from_string(res); + total = j["count"].as_string(); + return (total == "7"); + }); // do some transfers in 1 block transfer(account_id_type()(db), bob, asset(100)); @@ -110,13 +108,13 @@ BOOST_AUTO_TEST_CASE(elasticsearch_account_history) { transfer(account_id_type()(db), bob, asset(300)); generate_block(); - fc::usleep(ES_WAIT_TIME); // index.refresh_interval - - res = graphene::utilities::simpleQuery(es); - j = fc::json::from_string(res); - total = j["count"].as_string(); - BOOST_CHECK_EQUAL(total, "13"); + fc::wait_for( ES_WAIT_TIME, [&]() { + res = graphene::utilities::simpleQuery(es); + j = fc::json::from_string(res); + total = j["count"].as_string(); + return (total == "13"); + }); // check the visitor data auto block_date = db.head_block_time(); @@ -143,31 +141,35 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) { graphene::utilities::ES es; es.curl = curl; - es.elasticsearch_url = "http://localhost:9200/"; + es.elasticsearch_url = GRAPHENE_TESTING_ES_URL; es.index_prefix = es_obj_index_prefix; - //es.auth = "elastic:changeme"; // delete all first auto delete_objects = graphene::utilities::deleteAll(es); + BOOST_REQUIRE(delete_objects); // require successful deletion generate_block(); - fc::usleep(ES_WAIT_TIME); if(delete_objects) { // all records deleted // asset and bitasset create_bitasset("USD", account_id_type()); generate_block(); - fc::usleep(ES_WAIT_TIME); string query = "{ \"query\" : { \"bool\" : { \"must\" : [{\"match_all\": {}}] } } }"; es.endpoint = es.index_prefix + "*/data/_count"; es.query = query; - auto res = graphene::utilities::simpleQuery(es); - variant j = fc::json::from_string(res); - auto total = j["count"].as_string(); - BOOST_CHECK_EQUAL(total, "2"); + string res; + variant j; + string total; + + fc::wait_for( ES_WAIT_TIME, [&]() { + res = graphene::utilities::simpleQuery(es); + j = fc::json::from_string(res); + total = j["count"].as_string(); + return (total == "2"); + }); es.endpoint = es.index_prefix + "asset/data/_search"; res = graphene::utilities::simpleQuery(es); @@ -198,13 +200,17 @@ BOOST_AUTO_TEST_CASE(elasticsearch_suite) { graphene::utilities::ES es; es.curl = curl; - es.elasticsearch_url = "http://localhost:9200/"; + es.elasticsearch_url = GRAPHENE_TESTING_ES_URL; es.index_prefix = es_index_prefix; auto delete_account_history = graphene::utilities::deleteAll(es); - fc::usleep(ES_WAIT_TIME); - es.index_prefix = es_obj_index_prefix; - auto delete_objects = graphene::utilities::deleteAll(es); - fc::usleep(ES_WAIT_TIME); + BOOST_REQUIRE(delete_account_history); // require successful deletion + + graphene::utilities::ES es_obj; + es_obj.curl = curl; + es_obj.elasticsearch_url = GRAPHENE_TESTING_ES_URL; + es_obj.index_prefix = es_obj_index_prefix; + auto delete_objects = graphene::utilities::deleteAll(es_obj); + BOOST_REQUIRE(delete_objects); // require successful deletion if(delete_account_history && delete_objects) { // all records deleted @@ -224,13 +230,13 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { graphene::utilities::ES es; es.curl = curl; - es.elasticsearch_url = "http://localhost:9200/"; + es.elasticsearch_url = GRAPHENE_TESTING_ES_URL; es.index_prefix = es_index_prefix; auto delete_account_history = graphene::utilities::deleteAll(es); + BOOST_REQUIRE(delete_account_history); // require successful deletion generate_block(); - fc::usleep(ES_WAIT_TIME); if(delete_account_history) { @@ -243,15 +249,20 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { create_bitasset("OIL", dan.id); // create op 6 generate_block(); - fc::usleep(ES_WAIT_TIME); graphene::app::history_api hist_api(app); app.enable_plugin("elasticsearch"); // f(A, 0, 4, 9) = { 5, 3, 1, 0 } - auto histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(9)); - - BOOST_CHECK_EQUAL(histories.size(), 4u); + auto histories = hist_api.get_account_history( + "1.2.0", operation_history_id_type(), 4, operation_history_id_type(9)); + + fc::wait_for( ES_WAIT_TIME, [&]() { + histories = hist_api.get_account_history( + "1.2.0", operation_history_id_type(), 4, operation_history_id_type(9)); + return (histories.size() == 4u); + }); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); @@ -259,7 +270,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 0, 4, 6) = { 5, 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(6)); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); @@ -267,7 +278,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 0, 4, 5) = { 5, 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(5)); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); @@ -275,33 +286,33 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 0, 4, 4) = { 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(4)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 4, 3) = { 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(3)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 4, 2) = { 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(2)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 4, 1) = { 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type(1)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 4, 0) = { 5, 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type()); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); @@ -309,30 +320,30 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 1, 5, 9) = { 5, 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(9)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 1, 5, 6) = { 5, 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(6)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 1, 5, 5) = { 5, 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(5)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 1, 5, 4) = { 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(4)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); // f(A, 1, 5, 3) = { 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(3)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); // f(A, 1, 5, 2) = { } @@ -345,67 +356,67 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 1, 5, 0) = { 5, 3 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 5, operation_history_id_type(0)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); // f(A, 0, 3, 9) = { 5, 3, 1 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(9)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(A, 0, 3, 6) = { 5, 3, 1 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(6)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(A, 0, 3, 5) = { 5, 3, 1 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(5)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(A, 0, 3, 4) = { 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(4)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 3, 3) = { 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(3)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); // f(A, 0, 3, 2) = { 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(2)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 3, 1) = { 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type(1)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); // f(A, 0, 3, 0) = { 5, 3, 1 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 3, operation_history_id_type()); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(B, 0, 4, 9) = { 6, 4, 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(9)); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 2u); @@ -413,7 +424,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(B, 0, 4, 6) = { 6, 4, 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(6)); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 2u); @@ -421,38 +432,38 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(B, 0, 4, 5) = { 4, 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(5)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(B, 0, 4, 4) = { 4, 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(4)); - BOOST_CHECK_EQUAL(histories.size(), 3u); + BOOST_REQUIRE_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); // f(B, 0, 4, 3) = { 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(3)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); // f(B, 0, 4, 2) = { 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(2)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 2u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); // f(B, 0, 4, 1) = { 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type(1)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); // f(B, 0, 4, 0) = { 6, 4, 2, 1 } histories = hist_api.get_account_history("dan", operation_history_id_type(), 4, operation_history_id_type()); - BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_REQUIRE_EQUAL(histories.size(), 4u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 2u); @@ -460,24 +471,24 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(B, 2, 4, 9) = { 6, 4 } histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(9)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); // f(B, 2, 4, 6) = { 6, 4 } histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(6)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); // f(B, 2, 4, 5) = { 4 } histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(5)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); // f(B, 2, 4, 4) = { 4 } histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(4)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 4u); // f(B, 2, 4, 3) = { } @@ -494,7 +505,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(B, 2, 4, 0) = { 6, 4 } histories = hist_api.get_account_history("dan", operation_history_id_type(2), 4, operation_history_id_type(0)); - BOOST_CHECK_EQUAL(histories.size(), 2u); + BOOST_REQUIRE_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 6u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 4u); @@ -512,11 +523,14 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { create_account("alice"); generate_block(); - fc::usleep(ES_WAIT_TIME); // f(C, 0, 4, 10) = { 7 } - histories = hist_api.get_account_history("alice", operation_history_id_type(0), 4, operation_history_id_type(10)); - BOOST_CHECK_EQUAL(histories.size(), 1u); + fc::wait_for( ES_WAIT_TIME, [&]() { + histories = hist_api.get_account_history( + "alice", operation_history_id_type(0), 4, operation_history_id_type(10)); + return (histories.size() == 1u); + }); + BOOST_REQUIRE_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 7u); // f(C, 8, 4, 10) = { } @@ -525,7 +539,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) { // f(A, 0, 10, 0) = { 7, 5, 3, 1, 0 } histories = hist_api.get_account_history("1.2.0", operation_history_id_type(0), 10, operation_history_id_type(0)); - BOOST_CHECK_EQUAL(histories.size(), 5u); + BOOST_REQUIRE_EQUAL(histories.size(), 5u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 7u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 5u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 3u); diff --git a/tests/performance/performance_tests.cpp b/tests/performance/performance_tests.cpp index 152f672189..35d0a1b7cc 100644 --- a/tests/performance/performance_tests.cpp +++ b/tests/performance/performance_tests.cpp @@ -22,13 +22,7 @@ * THE SOFTWARE. */ -#include - -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; - return nullptr; -} +#include "../common/init_unit_test_suite.hpp" #include diff --git a/tests/tests/main.cpp b/tests/tests/main.cpp index 0c3e9f7644..48ba3b7e4b 100644 --- a/tests/tests/main.cpp +++ b/tests/tests/main.cpp @@ -21,22 +21,4 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include -#include -#include -#include - -extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; - -boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - const auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); - std::srand( seed ); - std::cout << "Random number generator seeded to " << seed << std::endl; - const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); - if( genesis_timestamp_str != nullptr ) - { - GRAPHENE_TESTING_GENESIS_TIMESTAMP = std::stoul( genesis_timestamp_str ); - } - std::cout << "GRAPHENE_TESTING_GENESIS_TIMESTAMP is " << GRAPHENE_TESTING_GENESIS_TIMESTAMP << std::endl; - return nullptr; -} +#include "../common/init_unit_test_suite.hpp"