Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: deflake timer test, not completely #12642

Merged
merged 1 commit into from
Aug 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions test/common/event/dispatcher_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Envoy {
namespace Event {
namespace {

static void onWatcherReady(evwatch*, const evwatch_prepare_cb_info*, void* arg) {
void onWatcherReady(evwatch*, const evwatch_prepare_cb_info*, void* arg) {
// `arg` contains the ReadyWatcher passed in from evwatch_prepare_new.
auto watcher = static_cast<ReadyWatcher*>(arg);
watcher->ready();
Expand Down Expand Up @@ -480,8 +480,7 @@ class TimerImplTest : public testing::TestWithParam<bool> {
{{"envoy.reloadable_features.activate_timers_next_event_loop",
activateTimersNextEventLoop() ? "true" : "false"}});
// Watch for dispatcher prepare events.
evwatch_prepare_new(&static_cast<DispatcherImpl*>(dispatcher_.get())->base(), onWatcherReady,
&prepare_watcher_);
evwatch_prepare_new(&libevent_base_, onWatcherReady, &prepare_watcher_);
}

bool activateTimersNextEventLoop() { return GetParam(); }
Expand Down Expand Up @@ -553,7 +552,7 @@ TEST_P(TimerImplTest, ChangeTimerBackwardsBeforeRun) {
timer1->enableTimer(std::chrono::milliseconds(4));

// Advance time by 5ms so timers above all trigger in the same loop iteration.
advanceLibeventTime(absl::Milliseconds(5));
advanceLibeventTime(absl::Milliseconds(10));

// Expect watcher3 to trigger first because the deadlines for timers 1 and 2 was moved backwards.
InSequence s;
Expand All @@ -576,16 +575,17 @@ TEST_P(TimerImplTest, ChangeTimerForwardsToZeroBeforeRun) {
timer1->enableTimer(std::chrono::milliseconds(0));

// Advance time by 5ms so timers above all trigger in the same loop iteration.
advanceLibeventTime(absl::Milliseconds(5));
advanceLibeventTime(absl::Milliseconds(10));

// Expect watcher1 to trigger first because timer1's deadline was moved forward.
InSequence s;
EXPECT_CALL(prepare_watcher_, ready());
if (activateTimersNextEventLoop()) {
// Expect watcher1 to trigger first because timer1's deadline was moved forward.
InSequence s;
EXPECT_CALL(prepare_watcher_, ready());
EXPECT_CALL(watcher1, ready());
EXPECT_CALL(watcher2, ready());
} else {
// Timers execute in the wrong order.
EXPECT_CALL(prepare_watcher_, ready());
EXPECT_CALL(watcher2, ready());
EXPECT_CALL(watcher1, ready());
}
Expand All @@ -604,7 +604,7 @@ TEST_P(TimerImplTest, ChangeTimerForwardsToNonZeroBeforeRun) {
timer1->enableTimer(std::chrono::milliseconds(1));

// Advance time by 5ms so timers above all trigger in the same loop iteration.
advanceLibeventTime(absl::Milliseconds(5));
advanceLibeventTime(absl::Milliseconds(10));

// Expect watcher1 to trigger first because timer1's deadline was moved forward.
InSequence s;
Expand Down Expand Up @@ -671,7 +671,7 @@ TEST_P(TimerImplTest, TimerOrdering) {
timer3->enableTimer(std::chrono::milliseconds(2));

// Advance time by 5ms so timers above all trigger in the same loop iteration.
advanceLibeventTime(absl::Milliseconds(5));
advanceLibeventTime(absl::Milliseconds(10));

EXPECT_TRUE(timer1->enabled());
EXPECT_TRUE(timer2->enabled());
Expand Down Expand Up @@ -705,7 +705,7 @@ TEST_P(TimerImplTest, TimerOrderAndDisableAlarm) {
timer3->enableTimer(std::chrono::milliseconds(2));

// Advance time by 5ms so timers above all trigger in the same loop iteration.
advanceLibeventTime(absl::Milliseconds(5));
advanceLibeventTime(absl::Milliseconds(10));

EXPECT_TRUE(timer1->enabled());
EXPECT_TRUE(timer2->enabled());
Expand Down Expand Up @@ -746,7 +746,7 @@ TEST_P(TimerImplTest, TimerOrderDisableAndReschedule) {
timer4->enableTimer(std::chrono::milliseconds(3));

// Advance time by 5ms so timers above all trigger in the same loop iteration.
advanceLibeventTime(absl::Milliseconds(5));
advanceLibeventTime(absl::Milliseconds(10));

EXPECT_TRUE(timer1->enabled());
EXPECT_TRUE(timer2->enabled());
Expand All @@ -764,7 +764,7 @@ TEST_P(TimerImplTest, TimerOrderDisableAndReschedule) {
// that timers 2 and 3 are picked up by the same loop iteration. Without the sleep the two
// timers could execute in different loop iterations.
EXPECT_CALL(prepare_watcher_, ready()).WillOnce(testing::InvokeWithoutArgs([&]() {
advanceLibeventTime(absl::Milliseconds(5));
advanceLibeventTime(absl::Milliseconds(10));
}));
EXPECT_CALL(watcher2, ready());
EXPECT_CALL(watcher3, ready());
Expand All @@ -773,7 +773,7 @@ TEST_P(TimerImplTest, TimerOrderDisableAndReschedule) {
EXPECT_CALL(watcher2, ready());
// Sleep in prepare cb to avoid flakiness if epoll_wait returns before the timer timeout.
EXPECT_CALL(prepare_watcher_, ready()).WillOnce(testing::InvokeWithoutArgs([&]() {
advanceLibeventTime(absl::Milliseconds(5));
advanceLibeventTime(absl::Milliseconds(10));
}));
EXPECT_CALL(watcher3, ready());
}
Expand Down Expand Up @@ -805,7 +805,7 @@ TEST_P(TimerImplTest, TimerOrderAndReschedule) {
timer4->enableTimer(std::chrono::milliseconds(3));

// Advance time by 5ms so timers above all trigger in the same loop iteration.
advanceLibeventTime(absl::Milliseconds(5));
advanceLibeventTime(absl::Milliseconds(10));

EXPECT_TRUE(timer1->enabled());
EXPECT_TRUE(timer2->enabled());
Expand All @@ -824,7 +824,7 @@ TEST_P(TimerImplTest, TimerOrderAndReschedule) {
// that timers 2 and 3 are picked up by the same loop iteration. Without the sleep the two
// timers could execute in different loop iterations.
EXPECT_CALL(prepare_watcher_, ready()).WillOnce(testing::InvokeWithoutArgs([&]() {
advanceLibeventTime(absl::Milliseconds(5));
advanceLibeventTime(absl::Milliseconds(10));
}));
EXPECT_CALL(watcher2, ready());
EXPECT_CALL(watcher3, ready());
Expand All @@ -833,7 +833,7 @@ TEST_P(TimerImplTest, TimerOrderAndReschedule) {
EXPECT_CALL(watcher4, ready());
// Sleep in prepare cb to avoid flakiness if epoll_wait returns before the timer timeout.
EXPECT_CALL(prepare_watcher_, ready()).WillOnce(testing::InvokeWithoutArgs([&]() {
advanceLibeventTime(absl::Milliseconds(5));
advanceLibeventTime(absl::Milliseconds(10));
}));
EXPECT_CALL(watcher3, ready());
}
Expand Down