Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Fix itf fake peers on demand ordering test #2067

Conversation

MBoldyrev
Copy link
Contributor

Description of the Change

Rewrote the test...

Benefits

...to fix an unidentified bug and to improve the test logic.

@MBoldyrev MBoldyrev added needs-review pr awaits review from maintainers bug bug/defect that was reproduced by maintainers tests pr aimed at the code coverage increase or test refactorings labels Jan 31, 2019
@MBoldyrev MBoldyrev self-assigned this Jan 31, 2019
[&proposal](iroha::expected::Value<std::unique_ptr<
shared_model::interface::Proposal>> &v) {
auto p1 =
std::static_pointer_cast<shared_model::proto::Proposal>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D: may you a bit elaborate what is happening here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a debugging code I forgot to remove, sorry.

@MBoldyrev MBoldyrev requested review from muratovv and removed request for Akvinikym February 4, 2019 07:10
const auto valid_hash =
valid_block_storage->getBlockByHeight(committed_block->height())
->hash()
.hex();
const auto commited_hash = committed_block->hash().hex();
if (commited_hash != valid_hash) {
if (commited_hash == valid_hash) {
ASSERT_EQ(commited_hash, valid_hash) << "Wrong block got committed!";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like conditional in previous line should be removed, otherwise ASSERT_EQ will always pass.

shared_model::interface::Proposal>> &v) {
// casting std::shared_ptr<shared_model::interface::Proposal>
// to std::shared_ptr<const shared_model::proto::Proposal>
proposal = std::const_pointer_cast<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
proposal = std::const_pointer_cast<
proposal = std::static_pointer_cast<

Because static cast allows to add const.

@MBoldyrev MBoldyrev force-pushed the fix/itf-fake-peer-on-demand-ordering branch from b459159 to 7417957 Compare March 18, 2019 09:43
@MBoldyrev MBoldyrev changed the base branch from trunk/itf-fake-peer to feature/itf-fake-peer-merge-develop-2019-03-18 March 18, 2019 09:43
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
@MBoldyrev MBoldyrev force-pushed the fix/itf-fake-peer-on-demand-ordering branch from 7417957 to 56283d5 Compare March 18, 2019 09:48
@MBoldyrev MBoldyrev requested a review from lebdron March 27, 2019 12:43
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
@MBoldyrev MBoldyrev force-pushed the fix/itf-fake-peer-on-demand-ordering branch from 6ce87e3 to 7ba327c Compare March 27, 2019 14:07
Copy link
Contributor

@lebdron lebdron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code in fake_peer::Behaviour looks fragile with this calls captured in observable callback. Maybe we should consider looking at class diagram in order to simplify FakePeer and shared_ptr - weak_ptr relations in the future.

@@ -25,25 +25,37 @@ namespace integration_framework {
subscriptions_.emplace_back(
getFakePeer().getMstStatesObservable().subscribe(
[this](const auto &message) {
this->processMstMessage(message);
if (auto alive = fake_peer_wptr_.lock()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this object outlive the observable? If there are no such guarantees, probably fake_peer_wptr_ has to be captured by value.
Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great catch, thanks!

@lebdron lebdron requested a review from luckychess April 2, 2019 10:44
Copy link
Contributor

@luckychess luckychess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI tells that fake_peer_example_test still fails. Looks suspicious.

@@ -124,6 +124,12 @@ namespace integration_framework {
yac_transport_->subscribe(yac_network_notifier_);
}

FakePeer::~FakePeer() {
if (behaviour_) {
behaviour_->absolve();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I can see Behaviour class calls absolve by itself in its destructor. Could you explain why we should do it manually here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do it to ensure it will stop its operation on this peer. The destructor may not be called if the behaviour is managed by a shared pointer stored elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it will be called later anyway, what's the problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do not call absolve() here, a behaviour (if it overlives the peer) will try to lock its weak pointer and will not succeed. This line absolves its duties on fake peer exit.

std::atomic_store_explicit(
&default_provider_,
std::make_shared<DefaultProvider>(std::move(provider)),
std::memory_order_release);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to add some comments about why memory order here and below is important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a general case of release-acquire model with nothing specific.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, what will happen if I omit memory_order arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right that this optimization is excessive in tests. I believe no noticeable overhead will be added if the default memory order is restored.

static constexpr std::chrono::seconds kMstStateWaitingTime(10);
static constexpr std::chrono::seconds kSynchronizerWaitingTime(10);
static constexpr std::chrono::seconds kProposalWaitingTime(1);
static constexpr std::chrono::seconds kMstStateWaitingTime(20);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty suspicious change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since rxcpp timeout works well now, we can loosen the time limits, that were previously lowered to reduce the test execution time.

this->processMstMessage(message);
[weak_this,
weak_fake_peer = fake_peer_wptr_](const auto &message) {
auto me_alive = weak_this.lock();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code of locking and checking is duplicated 5 times. I think better to refactor it.

@@ -16,6 +16,8 @@

using namespace std::chrono_literals;

static constexpr std::chrono::milliseconds kMstEmissionPeriod = 100ms;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess better to move default constants from itf to a separate header.

Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
@MBoldyrev MBoldyrev merged commit ada2f31 into feature/itf-fake-peer-merge-develop-2019-03-18 Apr 4, 2019
@MBoldyrev MBoldyrev deleted the fix/itf-fake-peer-on-demand-ordering branch April 4, 2019 16:14
MBoldyrev added a commit that referenced this pull request Apr 4, 2019
* new logger integration to itf fake peers
* updating batches propagation without round
* Fix itf fake peers on demand ordering test (#2067)
* fix the fake peer ordering test
* reworked ordering test without sync
* reworked synchronization test without sync
* reworked mst test without sync
* absolve behaviour on FakePeer destruction
* fixed fake peer lifetime in behaviour subscriptions
* use the new ProposalStorage iface to add tx
* reduce timeouts
* reduce MST delay
* state alive check in behaviour subscriptions
* removed explicit memory order
* Locker class in Behaviour
* fixated proposal storage in fake peer
* synchronized subjects on_next()

Signed-off-by: Mikhail Boldyrev <[email protected]>
MBoldyrev added a commit that referenced this pull request Apr 4, 2019
* fix the fake peer ordering test
* reworked ordering test without sync
* reworked synchronization test without sync
* reworked mst test without sync
* absolve behaviour on FakePeer destruction
* fixed fake peer lifetime in behaviour subscriptions
* use the new ProposalStorage iface to add tx
* reduce timeouts
* reduce MST delay
* state alive check in behaviour subscriptions
* removed explicit memory order
* Locker class in Behaviour
* fixated proposal storage in fake peer
* synchronized subjects on_next()

Signed-off-by: Mikhail Boldyrev <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug bug/defect that was reproduced by maintainers needs-review pr awaits review from maintainers tests pr aimed at the code coverage increase or test refactorings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants