Skip to content

Commit

Permalink
Add tests for storing budget records in ES
Browse files Browse the repository at this point in the history
  • Loading branch information
abitmore committed Jan 3, 2022
1 parent 827340a commit 446fb3c
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/elasticsearch/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) {
es.elasticsearch_url = GRAPHENE_TESTING_ES_URL;
es.index_prefix = es_obj_index_prefix;

idump( (db.head_block_num()) );

// delete all first
auto delete_objects = graphene::utilities::deleteAll(es);
BOOST_REQUIRE(delete_objects); // require successful deletion
Expand Down Expand Up @@ -259,11 +261,31 @@ BOOST_AUTO_TEST_CASE(elasticsearch_objects) {

auto bitasset_data_id = j["hits"]["hits"][size_t(0)]["_source"]["bitasset_data_id"].as_string();
es.endpoint = es.index_prefix + "bitasset/_doc/_search";
es.query = "{ \"query\" : { \"bool\": { \"must\" : [{ \"term\": { \"object_id\": \""+bitasset_data_id+"\"}}] } } }";
es.query = "{ \"query\" : { \"bool\": { \"must\" : [{ \"term\": { \"object_id\": \""
+ bitasset_data_id + "\"}}] } } }";
res = graphene::utilities::simpleQuery(es);
j = fc::json::from_string(res);
auto bitasset_object_id = j["hits"]["hits"][size_t(0)]["_source"]["object_id"].as_string();
BOOST_CHECK_EQUAL(bitasset_object_id, bitasset_data_id);

// maintenance, for budget records
generate_blocks( db.get_dynamic_global_properties().next_maintenance_time );
generate_block();

es.endpoint = es.index_prefix + "budget/_doc/_count";
es.query = "";
fc::wait_for( ES_WAIT_TIME, [&]() {
res = graphene::utilities::getEndPoint(es);
j = fc::json::from_string(res);
if( !j.is_object() )
return false;
const auto& obj = j.get_object();
if( obj.find("count") == obj.end() )
return false;
total = obj["count"].as_string();
return (total == "2"); // the first from block one, the second from the first maintenance block
});

}
}
catch (fc::exception &e) {
Expand Down

0 comments on commit 446fb3c

Please sign in to comment.