Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
Signed-off-by: iceseer <iceseer@gmail.com>
  • Loading branch information
iceseer committed Mar 25, 2022
1 parent c62a7f4 commit 3e637bf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 131 deletions.
6 changes: 6 additions & 0 deletions irohad/ordering/impl/on_demand_ordering_gate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ OnDemandOrderingGate::OnDemandOrderingGate(
[this](
auto,
auto ev) { /// TODO(iceseer): remove `this` from lambda context
std::shared_lock<std::shared_timed_mutex> stop_lock(stop_mutex_);
if (stop_requested_) {
log_->warn("Not doing anything because stop was requested.");
return;
}

if (!syncing_mode_) {
assert(network_client_);
network_client_->onRequestProposal(ev.round, std::nullopt);
Expand Down
26 changes: 23 additions & 3 deletions irohad/ordering/impl/on_demand_ordering_service_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "ordering/impl/on_demand_ordering_service_impl.hpp"

#include <string_view>
#include <unordered_set>

#include <boost/range/adaptor/indirected.hpp>
Expand Down Expand Up @@ -101,14 +102,32 @@ OnDemandOrderingServiceImpl::OnDemandOrderingServiceImpl(
tryCreateProposal(ev.round, collection, ev.created_time);
result
&& result.value()->hash()
== shared_model::crypto::Hash(ev.remote_proposal_hash))
== shared_model::crypto::Hash(ev.remote_proposal_hash)) {
log_->debug("Local correct proposal: {}, while remote {}",
result.value()->hash(),
shared_model::crypto::Hash(ev.remote_proposal_hash));
iroha::getSubscription()->notify(
iroha::EventTypes::kOnProposalResponse,
ProposalEvent{std::move(result).value(), ev.round});
else
} else {
if (result)
log_->debug(
"Local incorrect proposal: {}\nwhile remote {}\nremote "
"proposal: {}\nlocal proposal: {}",
result.value()->hash(),
shared_model::crypto::Hash(ev.remote_proposal_hash),
*ev.remote,
**result);
else
log_->debug(
"Local proposal was not created while remote hash "
"{}\nremote proposal: {}",
shared_model::crypto::Hash(ev.remote_proposal_hash),
*ev.remote);
iroha::getSubscription()->notify(
iroha::EventTypes::kOnProposalResponseFailed,
ProposalEvent{std::nullopt, ev.round});
}
});
}

Expand Down Expand Up @@ -229,7 +248,8 @@ OnDemandOrderingServiceImpl::onRequestProposal(consensus::Round round) {
getSubscription()->notify(EventTypes::kOnPackProposal, round);
}
} while (false);
log_->debug("uploadProposal, {}, {}returning a proposal.",

log_->debug("uploadProposal, {}, {} returning a proposal.",
round,
result ? "" : "NOT ");
return result;
Expand Down
13 changes: 6 additions & 7 deletions irohad/ordering/impl/on_demand_os_server_grpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ grpc::Status OnDemandOsServerGrpc::RequestProposal(
log_->info("Received RequestProposal for {} from {}", round, context->peer());
auto maybe_proposal = ordering_service_->waitForLocalProposal(round, delay_);
if (maybe_proposal.has_value()) {
auto const &[sptr_proposal, bf] = maybe_proposal.value();
response->set_bloom_filter(bf.load().data(), bf.load().size());
auto const &[sptr_proposal, bf_local] = maybe_proposal.value();
response->set_bloom_filter(bf_local.load().data(), bf_local.load().size());
response->set_proposal_hash(sptr_proposal->hash().blob().data(),
sptr_proposal->hash().blob().size());

log_->info("OS proposal: {}\nproposal: {}", sptr_proposal->hash(), *sptr_proposal);
log_->debug(
"OS proposal: {}\nproposal: {}", sptr_proposal->hash(), *sptr_proposal);

auto const &proto_proposal =
static_cast<const shared_model::proto::Proposal *>(sptr_proposal.get())
Expand All @@ -98,11 +99,9 @@ grpc::Status OnDemandOsServerGrpc::RequestProposal(
== sptr_proposal->transactions().size());
for (size_t ix = 0; ix < sptr_proposal->transactions().size(); ++ix) {
assert(sptr_proposal->transactions()[ix].getBatchHash());
log_->info("Check batches hash: {}",
*sptr_proposal->transactions()[ix].getBatchHash());
if (!bf_remote.test(sptr_proposal->transactions()[(int)ix]
.getBatchHash()
.value())) {
.getBatchHash()
.value())) {
auto *tx_dst =
response->mutable_proposal()->mutable_transactions()->Add();
*tx_dst = proto_proposal.transactions()[(int)ix];
Expand Down
121 changes: 0 additions & 121 deletions test/integration/acceptance/remove_peer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,124 +31,3 @@ static constexpr std::chrono::seconds kSynchronizerWaitingTime(20);

struct RemovePeerTest : FakePeerFixture {};
INSTANTIATE_TEST_SUITE_P_DifferentStorageTypes(RemovePeerTest);

/**
* @given a network of one real and one fake peers
* @when fake peer is removed
* @then the transaction is committed
* @and the ledger state after commit contains one peer,
* @and the WSV reports that there is one peer
*/
TEST_P(RemovePeerTest, FakePeerIsRemoved) {
// ------------------------ GIVEN ------------------------
// init the real peer with one fake peer in the genesis block
createFakePeers(1);
auto &itf = prepareState();
const auto prepared_height = itf.getBlockQuery()->getTopBlockHeight();
auto fake_peer = fake_peers_.front();

// capture itf synchronization events
utils::WaitForSingleObject completed;
auto subscriber =
SubscriberCreator<bool, synchronizer::SynchronizationEvent>::
template create<EventTypes::kOnSynchronization>(
static_cast<SubscriptionEngineHandlers>(decltype(
getSubscription())::element_type::Dispatcher::kExecuteInPool),
[prepared_height, &completed, itf_peer = itf_->getThisPeer()](
auto, auto sync_event) {
if (sync_event.ledger_state->top_block_info.height
> prepared_height) {
EXPECT_THAT(sync_event.ledger_state->ledger_peers,
::testing::UnorderedElementsAre(
makePeerPointeeMatcher(itf_peer)));
completed.set();
}
});

// ------------------------ WHEN -------------------------
// send removePeer command
itf.sendTxAwait(complete(baseTx(kAdminId).removePeer(PublicKeyHexStringView{
fake_peer->getKeypair().publicKey()}),
kAdminKeypair),
checkBlockHasNTxs<1>);

// ------------------------ THEN -------------------------
// check that ledger state contains one peer
ASSERT_TRUE(completed.wait(kSynchronizerWaitingTime))
<< "Error waiting for synchronization";

// query WSV peers
auto opt_peers = itf.getIrohaInstance()
.getTestIrohad()
->getStorage()
->createPeerQuery()
.value()
->getLedgerPeers(false);

// check only one peer is there
ASSERT_TRUE(opt_peers);
EXPECT_THAT(*opt_peers,
::testing::UnorderedElementsAre(
makePeerPointeeMatcher(itf.getThisPeer())));
}

/**
* @given a network of one real and one fake peers
* @when real peer is removed
* @then the transaction is committed
* @and the ledger state after commit contains one peer,
* @and the WSV reports that there is one peer
*/
TEST_P(RemovePeerTest, RealPeerIsRemoved) {
// ------------------------ GIVEN ------------------------
// init the real peer with one fake peer in the genesis block
createFakePeers(1);
auto &itf = prepareState();
const auto prepared_height = itf.getBlockQuery()->getTopBlockHeight();
auto fake_peer = fake_peers_.front();

// capture itf synchronization events
utils::WaitForSingleObject completed;
auto subscriber =
SubscriberCreator<bool, synchronizer::SynchronizationEvent>::
template create<EventTypes::kOnSynchronization>(
static_cast<SubscriptionEngineHandlers>(decltype(
getSubscription())::element_type::Dispatcher::kExecuteInPool),
[prepared_height,
&completed,
fake_peer = fake_peer->getThisPeer()](auto, auto sync_event) {
if (sync_event.ledger_state->top_block_info.height
> prepared_height) {
EXPECT_THAT(sync_event.ledger_state->ledger_peers,
::testing::UnorderedElementsAre(
makePeerPointeeMatcher(fake_peer)));
completed.set();
}
});

// ------------------------ WHEN -------------------------
// send removePeer command
itf.sendTxAwait(complete(baseTx(kAdminId).removePeer(PublicKeyHexStringView{
itf_->getThisPeer()->pubkey()}),
kAdminKeypair),
checkBlockHasNTxs<1>);

// ------------------------ THEN -------------------------
// check that ledger state contains one peer
ASSERT_TRUE(completed.wait(kSynchronizerWaitingTime))
<< "Error waiting for synchronization";

// query WSV peers
auto opt_peers = itf.getIrohaInstance()
.getTestIrohad()
->getStorage()
->createPeerQuery()
.value()
->getLedgerPeers(false);

// check only one peer is there
ASSERT_TRUE(opt_peers);
EXPECT_THAT(*opt_peers,
::testing::UnorderedElementsAre(
makePeerPointeeMatcher(fake_peer->getThisPeer())));
}

0 comments on commit 3e637bf

Please sign in to comment.