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: mock cleanup #7922

Merged
merged 2 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions test/common/access_log/access_log_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ TEST_F(AccessLogManagerImplTest, flushToLogFilePeriodically) {
// make sure timer is re-enabled on callback call
log_file->write("test2");
EXPECT_CALL(*timer, enableTimer(timeout_40ms_));
timer->callback_();
timer->invokeCallback();

{
Thread::LockGuard lock(file_->write_mutex_);
Expand Down Expand Up @@ -147,7 +147,7 @@ TEST_F(AccessLogManagerImplTest, flushToLogFileOnDemand) {
// make sure timer is re-enabled on callback call
log_file->write("test2");
EXPECT_CALL(*timer, enableTimer(timeout_40ms_));
timer->callback_();
timer->invokeCallback();
expected_writes++;

{
Expand Down Expand Up @@ -176,7 +176,7 @@ TEST_F(AccessLogManagerImplTest, reopenFile) {
}));

log_file->write("before");
timer->callback_();
timer->invokeCallback();

{
Thread::LockGuard lock(file_->write_mutex_);
Expand Down Expand Up @@ -205,7 +205,7 @@ TEST_F(AccessLogManagerImplTest, reopenFile) {

log_file->reopen();
log_file->write("reopened");
timer->callback_();
timer->invokeCallback();

{
Thread::LockGuard lock(file_->write_mutex_);
Expand Down Expand Up @@ -237,7 +237,7 @@ TEST_F(AccessLogManagerImplTest, reopenThrows) {
.WillOnce(Return(ByMove(Filesystem::resultFailure<bool>(false, 0))));

log_file->write("test write");
timer->callback_();
timer->invokeCallback();
{
Thread::LockGuard lock(file_->write_mutex_);
while (file_->num_writes_ != 1) {
Expand All @@ -247,7 +247,7 @@ TEST_F(AccessLogManagerImplTest, reopenThrows) {
log_file->reopen();

log_file->write("this is to force reopen");
timer->callback_();
timer->invokeCallback();

{
Thread::LockGuard lock(file_->open_mutex_);
Expand All @@ -258,7 +258,7 @@ TEST_F(AccessLogManagerImplTest, reopenThrows) {

// write call should not cause any exceptions
log_file->write("random data");
timer->callback_();
timer->invokeCallback();
}

TEST_F(AccessLogManagerImplTest, bigDataChunkShouldBeFlushedWithoutTimer) {
Expand Down
2 changes: 1 addition & 1 deletion test/common/config/delta_subscription_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class DeltaSubscriptionTestHarness : public SubscriptionTestHarness {
EXPECT_CALL(*init_timeout_timer_, disableTimer());
}

void callInitFetchTimeoutCb() override { init_timeout_timer_->callback_(); }
void callInitFetchTimeoutCb() override { init_timeout_timer_->invokeCallback(); }

const Protobuf::MethodDescriptor* method_descriptor_;
Grpc::MockAsyncClient* async_client_;
Expand Down
2 changes: 1 addition & 1 deletion test/common/config/grpc_subscription_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class GrpcSubscriptionTestHarness : public SubscriptionTestHarness {
EXPECT_CALL(*init_timeout_timer_, disableTimer());
}

void callInitFetchTimeoutCb() override { init_timeout_timer_->callback_(); }
void callInitFetchTimeoutCb() override { init_timeout_timer_->invokeCallback(); }

std::string version_;
const Protobuf::MethodDescriptor* method_descriptor_;
Expand Down
2 changes: 1 addition & 1 deletion test/common/config/http_subscription_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class HttpSubscriptionTestHarness : public SubscriptionTestHarness {
EXPECT_CALL(*init_timeout_timer_, disableTimer());
}

void callInitFetchTimeoutCb() override { init_timeout_timer_->callback_(); }
void callInitFetchTimeoutCb() override { init_timeout_timer_->invokeCallback(); }

void timerTick() {
expectSendMessage(cluster_names_, version_);
Expand Down
10 changes: 5 additions & 5 deletions test/common/http/async_client_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ TEST_F(AsyncClientImplTest, Retry) {

EXPECT_CALL(stream_encoder_, encodeHeaders(HeaderMapEqualRef(&message_copy->headers()), false));
EXPECT_CALL(stream_encoder_, encodeData(BufferEqual(&data), true));
timer_->callback_();
timer_->invokeCallback();

// Normal response.
expectSuccess(200);
Expand Down Expand Up @@ -240,7 +240,7 @@ TEST_F(AsyncClientImplTest, RetryWithStream) {

EXPECT_CALL(stream_encoder_, encodeHeaders(HeaderMapEqualRef(&headers), false));
EXPECT_CALL(stream_encoder_, encodeData(BufferEqual(body.get()), true));
timer_->callback_();
timer_->invokeCallback();

// Normal response.
expectResponseHeaders(stream_callbacks_, 200, true);
Expand Down Expand Up @@ -731,7 +731,7 @@ TEST_F(AsyncClientImplTest, StreamTimeout) {
AsyncClient::Stream* stream = client_.start(
stream_callbacks_, AsyncClient::StreamOptions().setTimeout(std::chrono::milliseconds(40)));
stream->sendHeaders(message_->headers(), true);
timer_->callback_();
timer_->invokeCallback();

EXPECT_EQ(1UL,
cm_.thread_local_cluster_.cluster_.info_->stats_store_.counter("upstream_rq_timeout")
Expand Down Expand Up @@ -765,7 +765,7 @@ TEST_F(AsyncClientImplTest, StreamTimeoutHeadReply) {
AsyncClient::Stream* stream = client_.start(
stream_callbacks_, AsyncClient::StreamOptions().setTimeout(std::chrono::milliseconds(40)));
stream->sendHeaders(message->headers(), true);
timer_->callback_();
timer_->invokeCallback();
}

TEST_F(AsyncClientImplTest, RequestTimeout) {
Expand All @@ -783,7 +783,7 @@ TEST_F(AsyncClientImplTest, RequestTimeout) {
EXPECT_CALL(stream_encoder_.stream_, resetStream(_));
client_.send(std::move(message_), callbacks_,
AsyncClient::RequestOptions().setTimeout(std::chrono::milliseconds(40)));
timer_->callback_();
timer_->invokeCallback();

EXPECT_EQ(1UL,
cm_.thread_local_cluster_.cluster_.info_->stats_store_.counter("upstream_rq_timeout")
Expand Down
24 changes: 12 additions & 12 deletions test/common/http/conn_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,7 @@ TEST_F(HttpConnectionManagerImplTest, PerStreamIdleTimeoutGlobal) {
// encodeHeaders()/encodeData().
EXPECT_CALL(*idle_timer, enableTimer(_)).Times(2);
EXPECT_CALL(*idle_timer, disableTimer());
idle_timer->callback_();
idle_timer->invokeCallback();
}));

// 408 direct response after timeout.
Expand Down Expand Up @@ -1449,7 +1449,7 @@ TEST_F(HttpConnectionManagerImplTest, AccessEncoderRouteBeforeHeadersArriveOnIdl
EXPECT_CALL(*idle_timer, enableTimer(_)).Times(2);
EXPECT_CALL(*idle_timer, disableTimer());
// Simulate and idle timeout so that the filter chain gets created.
idle_timer->callback_();
idle_timer->invokeCallback();
}));

// This should not be called as we don't have request headers.
Expand Down Expand Up @@ -1489,7 +1489,7 @@ TEST_F(HttpConnectionManagerImplTest, TestStreamIdleAccessLog) {
// encodeHeaders()/encodeData().
EXPECT_CALL(*idle_timer, enableTimer(_)).Times(2);
EXPECT_CALL(*idle_timer, disableTimer());
idle_timer->callback_();
idle_timer->invokeCallback();
}));

std::shared_ptr<MockStreamDecoderFilter> filter(new NiceMock<MockStreamDecoderFilter>());
Expand Down Expand Up @@ -1597,7 +1597,7 @@ TEST_F(HttpConnectionManagerImplTest, PerStreamIdleTimeoutAfterDownstreamHeaders
// encodeHeaders()/encodeData().
EXPECT_CALL(*idle_timer, enableTimer(_)).Times(2);
EXPECT_CALL(*idle_timer, disableTimer());
idle_timer->callback_();
idle_timer->invokeCallback();

data.drain(4);
}));
Expand Down Expand Up @@ -1669,7 +1669,7 @@ TEST_F(HttpConnectionManagerImplTest, PerStreamIdleTimeoutAfterDownstreamHeaders
// encodeHeaders()/encodeData().
EXPECT_CALL(*idle_timer, enableTimer(_)).Times(2);
EXPECT_CALL(*idle_timer, disableTimer());
idle_timer->callback_();
idle_timer->invokeCallback();

data.drain(4);
}));
Expand Down Expand Up @@ -1720,7 +1720,7 @@ TEST_F(HttpConnectionManagerImplTest, PerStreamIdleTimeoutAfterUpstreamHeaders)
filter->callbacks_->encodeHeaders(std::move(response_headers), false);

EXPECT_CALL(*idle_timer, disableTimer());
idle_timer->callback_();
idle_timer->invokeCallback();

data.drain(4);
}));
Expand Down Expand Up @@ -1784,7 +1784,7 @@ TEST_F(HttpConnectionManagerImplTest, PerStreamIdleTimeoutAfterBidiData) {
filter->callbacks_->encodeData(fake_response, false);

EXPECT_CALL(*idle_timer, disableTimer());
idle_timer->callback_();
idle_timer->invokeCallback();

data.drain(4);
}));
Expand Down Expand Up @@ -1865,7 +1865,7 @@ TEST_F(HttpConnectionManagerImplTest, RequestTimeoutCallbackDisarmsAndReturns408
EXPECT_CALL(response_encoder_, encodeData(_, true)).WillOnce(AddBufferToString(&response_body));

conn_manager_->newStream(response_encoder_);
request_timer->callback_();
request_timer->invokeCallback();
}));

Buffer::OwnedImpl fake_input("1234");
Expand Down Expand Up @@ -2148,7 +2148,7 @@ TEST_F(HttpConnectionManagerImplTest, DrainClose) {
EXPECT_CALL(filter_callbacks_.connection_,
close(Network::ConnectionCloseType::FlushWriteAndDelay));
EXPECT_CALL(*drain_timer, disableTimer());
drain_timer->callback_();
drain_timer->invokeCallback();

EXPECT_EQ(1U, stats_.named_.downstream_cx_drain_close_.value());
EXPECT_EQ(1U, stats_.named_.downstream_rq_3xx_.value());
Expand Down Expand Up @@ -2381,7 +2381,7 @@ TEST_F(HttpConnectionManagerImplTest, IdleTimeoutNoCodec) {

EXPECT_CALL(filter_callbacks_.connection_, close(Network::ConnectionCloseType::FlushWrite));
EXPECT_CALL(*idle_timer, disableTimer());
idle_timer->callback_();
idle_timer->invokeCallback();

EXPECT_EQ(1U, stats_.named_.downstream_cx_idle_timeout_.value());
}
Expand Down Expand Up @@ -2426,14 +2426,14 @@ TEST_F(HttpConnectionManagerImplTest, IdleTimeout) {

Event::MockTimer* drain_timer = setUpTimer();
EXPECT_CALL(*drain_timer, enableTimer(_));
idle_timer->callback_();
idle_timer->invokeCallback();

EXPECT_CALL(*codec_, goAway());
EXPECT_CALL(filter_callbacks_.connection_,
close(Network::ConnectionCloseType::FlushWriteAndDelay));
EXPECT_CALL(*idle_timer, disableTimer());
EXPECT_CALL(*drain_timer, disableTimer());
drain_timer->callback_();
drain_timer->invokeCallback();

EXPECT_EQ(1U, stats_.named_.downstream_cx_idle_timeout_.value());
}
Expand Down
2 changes: 1 addition & 1 deletion test/common/http/date_provider_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST(DateProviderImplTest, All) {
EXPECT_NE(nullptr, headers.Date());

EXPECT_CALL(*timer, enableTimer(std::chrono::milliseconds(500)));
timer->callback_();
timer->invokeCallback();

headers.removeDate();
provider.setDateHeader(headers);
Expand Down
6 changes: 3 additions & 3 deletions test/common/http/http1/conn_pool_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class ConnPoolImplForTest : public ConnPoolImpl {

void expectAndRunUpstreamReady() {
EXPECT_TRUE(upstream_ready_enabled_);
mock_upstream_ready_timer_->callback_();
mock_upstream_ready_timer_->invokeCallback();
EXPECT_FALSE(upstream_ready_enabled_);
}

Expand Down Expand Up @@ -400,10 +400,10 @@ TEST_F(Http1ConnPoolImplTest, ConnectTimeout) {
EXPECT_NE(nullptr, conn_pool_.newStream(outer_decoder2, callbacks2));
}));

conn_pool_.test_clients_[0].connect_timer_->callback_();
conn_pool_.test_clients_[0].connect_timer_->invokeCallback();

EXPECT_CALL(callbacks2.pool_failure_, ready());
conn_pool_.test_clients_[1].connect_timer_->callback_();
conn_pool_.test_clients_[1].connect_timer_->invokeCallback();

EXPECT_CALL(conn_pool_, onClientDestroy()).Times(2);
dispatcher_.clearDeferredDeleteList();
Expand Down
2 changes: 1 addition & 1 deletion test/common/http/http2/conn_pool_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ TEST_F(Http2ConnPoolImplTest, ConnectTimeout) {
expectClientCreate();
ActiveTestRequest r1(*this, 0, false);
EXPECT_CALL(r1.callbacks_.pool_failure_, ready());
test_clients_[0].connect_timer_->callback_();
test_clients_[0].connect_timer_->invokeCallback();

EXPECT_CALL(*this, onClientDestroy());
dispatcher_.clearDeferredDeleteList();
Expand Down
9 changes: 1 addition & 8 deletions test/common/network/connection_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ TEST_P(ConnectionImplTest, DelayedCloseTimerResetWithPendingWriteBufferFlushes)
(*mocks.file_ready_cb_)(Event::FileReadyType::Write);

// Force the delayed close timeout to trigger so the connection is cleaned up.
mocks.timer_->callback_();
mocks.timer_->invokeCallback();
}

// Test that tearing down the connection will disable the delayed close timer.
Expand Down Expand Up @@ -1321,16 +1321,9 @@ TEST_P(ConnectionImplTest, DelayedCloseTimeoutNullStats) {
EXPECT_CALL(*mocks.timer_, enableTimer(_)).Times(1);
server_connection->close(ConnectionCloseType::FlushWriteAndDelay);
EXPECT_CALL(*mocks.timer_, disableTimer()).Times(1);
// Copy the callback since mocks.timer will be freed when closeSocket() is called.
Event::TimerCb callback = mocks.timer_->callback_;
// The following close() will call closeSocket() and reset internal data structures such as
// stats.
server_connection->close(ConnectionCloseType::NoFlush);
// Verify the onDelayedCloseTimeout() callback is resilient to the post closeSocket(), pre
// destruction state. This should not actually happen due to the timeout disablement in
// closeSocket(), but there is enough complexity in connection handling codepaths that being
// extra defensive is valuable.
callback();
}

class FakeReadFilter : public Network::ReadFilter {
Expand Down
Loading