-
Notifications
You must be signed in to change notification settings - Fork 295
Fix itf fake peers on demand ordering test #2067
Fix itf fake peers on demand ordering test #2067
Conversation
[&proposal](iroha::expected::Value<std::unique_ptr< | ||
shared_model::interface::Proposal>> &v) { | ||
auto p1 = | ||
std::static_pointer_cast<shared_model::proto::Proposal>( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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!"; |
There was a problem hiding this comment.
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< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proposal = std::const_pointer_cast< | |
proposal = std::static_pointer_cast< |
Because static cast allows to add const
.
b459159
to
7417957
Compare
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]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
7417957
to
56283d5
Compare
This reverts commit 56283d5. 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]>
6ce87e3
to
7ba327c
Compare
There was a problem hiding this 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()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch, thanks!
Signed-off-by: Mikhail Boldyrev <[email protected]>
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty suspicious change.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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]>
Signed-off-by: Mikhail Boldyrev <[email protected]>
* 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]>
* 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]>
Description of the Change
Rewrote the test...
Benefits
...to fix an unidentified bug and to improve the test logic.