Skip to content

Commit 658fbc3

Browse files
oschaafhtuch
authored andcommitted
Sequencer: don't assert when starting late. (#76)
Noticed this when generating a test coverage report on a machine with many cores. Apparently that ran into some more extreme drifts in expected timings, which triggered an assert. Looking into this, we can and should just handle this case. (Note: not visible in this PR, but the code will log an error as well when this happens). Signed-off-by: Otto van der Schaaf <oschaaf@we-amp.com>
1 parent fbb61b5 commit 658fbc3

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

source/common/sequencer_impl.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,10 @@ void SequencerImpl::run(bool from_periodic_timer) {
150150
}
151151

152152
void SequencerImpl::waitForCompletion() {
153-
ASSERT(running_);
154-
dispatcher_.run(Envoy::Event::Dispatcher::RunType::Block);
153+
// It's possible that we have already finished when we get here.
154+
if (running_) {
155+
dispatcher_.run(Envoy::Event::Dispatcher::RunType::Block);
156+
}
155157
// We should guarantee the flow terminates, so:
156158
ASSERT(!running_);
157159
}

test/sequencer_test.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class SequencerTestWithTimerEmulation : public SequencerTest {
9393
timer2_set_ = true;
9494
}));
9595
EXPECT_CALL(*dispatcher_, exit()).WillOnce(Invoke([&]() { stopped_ = true; }));
96+
}
97+
98+
void expectDispatcherRun() {
9699
EXPECT_CALL(*dispatcher_, run(_))
97100
.WillOnce(Invoke([&](Envoy::Event::DispatcherImpl::RunType type) {
98101
ASSERT_EQ(Envoy::Event::DispatcherImpl::RunType::Block, type);
@@ -150,7 +153,21 @@ TEST_F(SequencerTestWithTimerEmulation, RateLimiterInteraction) {
150153
.WillRepeatedly(Return(false));
151154

152155
EXPECT_CALL(*target(), callback(_)).Times(2).WillOnce(Return(true)).WillOnce(Return(true));
156+
expectDispatcherRun();
157+
sequencer.start();
158+
sequencer.waitForCompletion();
159+
}
160+
161+
TEST_F(SequencerTestWithTimerEmulation, StartingLate) {
162+
SequencerTarget callback =
163+
std::bind(&MockSequencerTarget::callback, target(), std::placeholders::_1);
164+
SequencerImpl sequencer(
165+
platform_util_, *dispatcher_, time_system_, time_system_.monotonicTime(),
166+
std::move(rate_limiter_), callback, std::make_unique<StreamingStatistic>(),
167+
std::make_unique<StreamingStatistic>(),
168+
test_number_of_intervals_ * interval_ /* Sequencer run time.*/, 1ms /* Sequencer timeout. */);
153169

170+
time_system_.setMonotonicTime(time_system_.monotonicTime() + 100s);
154171
sequencer.start();
155172
sequencer.waitForCompletion();
156173
}
@@ -175,6 +192,7 @@ TEST_F(SequencerTestWithTimerEmulation, RateLimiterSaturatedTargetInteraction) {
175192

176193
// The sequencer should call RateLimiter::releaseOne() when the target returns false.
177194
EXPECT_CALL(rate_limiter_unsafe_ref_, releaseOne()).Times(1);
195+
expectDispatcherRun();
178196

179197
sequencer.start();
180198
sequencer.waitForCompletion();
@@ -186,6 +204,7 @@ class SequencerIntegrationTest : public SequencerTestWithTimerEmulation {
186204
SequencerIntegrationTest() {
187205
Envoy::Event::SimulatedTimeSystem time_system;
188206
rate_limiter_ = std::make_unique<LinearRateLimiter>(time_system_, frequency_);
207+
expectDispatcherRun();
189208
}
190209

191210
bool timeout_test(const std::function<void()>& /* f */) {

0 commit comments

Comments
 (0)