Fix confirmation_height.election_winner_details_clearing (#3741)

There is a race condition between a block getting confirmed and setting
of statistics counters. In this case, the counter is incremented in an
observer callback that is executed after the block is confirmed.

One could say that the problem is that the stat counters should updated
before the block is confirmed but I think that is unrealistic to achieve
and possibly not even the right approach.

Converting the check to an ASSERT_TIMELY fixes the problem.
It seems likely that other test cases will have this problem too.
This commit is contained in:
Dimitrios Siganos 2022-02-15 15:56:51 +00:00 committed by GitHub
commit e51b3d6704
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1312,7 +1312,7 @@ TEST (confirmation_height, election_winner_details_clearing)
node->process_confirmed (nano::election_status{ send2 });
ASSERT_TIMELY (5s, node->block_confirmed (send2->hash ()));
ASSERT_EQ (1, node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out));
ASSERT_TIMELY (5s, 1 == node->stats.count (nano::stat::type::confirmation_observer, nano::stat::detail::inactive_conf_height, nano::stat::dir::out));
node->process_confirmed (nano::election_status{ send3 });
ASSERT_TIMELY (5s, node->block_confirmed (send3->hash ()));