Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
briansonnenberg committed Nov 8, 2024
1 parent 8e2d306 commit d236307
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/common/upstream/load_stats_reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class LoadStatsReporter
std::unique_ptr<envoy::service::load_stats::v3::LoadStatsResponse>&& message) override;
void onReceiveTrailingMetadata(Http::ResponseTrailerMapPtr&& metadata) override;
void onRemoteClose(Grpc::Status::GrpcStatus status, const std::string& message) override;
const LoadReporterStats& getStats() { return stats_; };

// TODO(htuch): Make this configurable or some static.
const uint32_t RETRY_DELAY_MS = 5000;
Expand Down
14 changes: 14 additions & 0 deletions test/common/upstream/load_stats_reporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,22 @@ TEST_F(LoadStatsReporterTest, RemoteStreamClose) {
EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_));
expectSendMessage({});
retry_timer_cb_();
EXPECT_EQ(load_stats_reporter_->getStats().errors_.value(), 1);
}

// Validate that errors stat is not incremented for a graceful stream termination.
TEST_F(LoadStatsReporterTest, RemoteStreamGracefulClose) {
EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_));
expectSendMessage({});
createLoadStatsReporter();
EXPECT_CALL(*response_timer_, disableTimer());
EXPECT_CALL(*retry_timer_, enableTimer(_, _));
load_stats_reporter_->onRemoteClose(Grpc::Status::WellKnownGrpcStatus::Ok, "");
EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_));
expectSendMessage({});
retry_timer_cb_();
EXPECT_EQ(load_stats_reporter_->getStats().errors_.value(), 0);
}
} // namespace
} // namespace Upstream
} // namespace Envoy

0 comments on commit d236307

Please sign in to comment.