SON193-SON200- SON Heartbeats and maintenance tests

This commit is contained in:
satyakoneru 2019-12-10 18:22:25 +00:00
parent 20e598276d
commit ac46c2343a
3 changed files with 86 additions and 1 deletions

View file

@ -247,6 +247,7 @@ void database::initialize_evaluators()
register_evaluator<create_son_evaluator>();
register_evaluator<update_son_evaluator>();
register_evaluator<delete_son_evaluator>();
register_evaluator<son_heartbeat_evaluator>();
}
void database::initialize_indexes()

View file

@ -92,7 +92,7 @@ namespace graphene { namespace chain {
using son_stats_index = generic_index<son_statistics_object, son_stats_multi_index_type>;
} } // graphene::chain
FC_REFLECT_ENUM(graphene::chain::son_status, (inactive)(active)(in_maintenance) )
FC_REFLECT_ENUM(graphene::chain::son_status, (inactive)(active)(in_maintenance)(deregistered) )
FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object),
(son_account)(vote_id)(total_votes)(url)(deposit)(signing_key)(pay_vb) )

View file

@ -652,4 +652,88 @@ BOOST_AUTO_TEST_CASE( son_witness_proposal_test )
generate_block();
} FC_LOG_AND_RETHROW()
}
BOOST_AUTO_TEST_CASE( son_heartbeat_test ) {
try
{
INVOKE(create_son_test);
GET_ACTOR(alice);
{
// Send Heartbeat for an inactive SON
son_heartbeat_operation op;
op.owner_account = alice_id;
op.son_id = son_id_type(0);
op.ts = fc::time_point::now();
trx.operations.push_back(op);
sign(trx, alice_private_key);
// Expect an exception
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0), fc::exception);
trx.clear();
}
generate_block();
const auto& idx = db.get_index_type<son_index>().indices().get<by_account>();
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find( alice_id );
BOOST_REQUIRE( obj != idx.end() );
const auto& sidx = db.get_index_type<son_stats_index>().indices().get<by_id>();
BOOST_REQUIRE( sidx.size() == 1 );
auto son_stats_obj = sidx.find( obj->statistics );
BOOST_REQUIRE( son_stats_obj != sidx.end() );
// Modify SON's status to in_maintenance
db.modify( *obj, [&]( son_object& _s)
{
_s.status = son_status::in_maintenance;
});
db.modify( *son_stats_obj, [&]( son_statistics_object& _s)
{
_s.last_down_timestamp = fc::time_point_sec(db.head_block_time() - fc::hours(1));
});
uint64_t downtime = 0;
{
generate_block();
// Send Heartbeat for an in_maintenance SON
son_heartbeat_operation op;
op.owner_account = alice_id;
op.son_id = son_id_type(0);
op.ts = (db.head_block_time()+fc::seconds(2*db.block_interval()));
trx.operations.push_back(op);
sign(trx, alice_private_key);
PUSH_TX( db, trx, ~0);
generate_block();
trx.clear();
BOOST_REQUIRE_EQUAL(son_stats_obj->current_interval_downtime, op.ts.sec_since_epoch() - son_stats_obj->last_down_timestamp.sec_since_epoch());
downtime = op.ts.sec_since_epoch() - son_stats_obj->last_down_timestamp.sec_since_epoch();
BOOST_CHECK( obj->status == son_status::active);
BOOST_CHECK( son_stats_obj->last_active_timestamp == op.ts);
}
{
generate_block();
// Send Heartbeat for an active SON
son_heartbeat_operation op;
op.owner_account = alice_id;
op.son_id = son_id_type(0);
op.ts = (db.head_block_time()+fc::seconds(2*db.block_interval()));
trx.operations.push_back(op);
sign(trx, alice_private_key);
PUSH_TX( db, trx, ~0);
generate_block();
trx.clear();
BOOST_REQUIRE_EQUAL(son_stats_obj->current_interval_downtime, downtime);
BOOST_CHECK( obj->status == son_status::active);
BOOST_CHECK( son_stats_obj->last_active_timestamp == op.ts);
}
} FC_LOG_AND_RETHROW()
} BOOST_AUTO_TEST_SUITE_END()