@@ -41,15 +41,23 @@ class ChannelUsage : public std::enable_shared_from_this<ChannelUsage<T>> {
4141 std::make_shared<Clock>())
4242 : stub_(std::move(stub)), clock_(std::move(clock)) {}
4343
44+ // This constructor is only used in testing.
45+ ChannelUsage (std::shared_ptr<T> stub, std::shared_ptr<Clock> clock,
46+ int initial_outstanding_rpcs)
47+ : stub_(std::move(stub)),
48+ clock_ (std::move(clock)),
49+ outstanding_rpcs_(initial_outstanding_rpcs) {}
50+
4451 // Computes the weighted average of outstanding RPCs on the channel over the
4552 // past 60 seconds.
4653 StatusOr<int > average_outstanding_rpcs () {
4754 auto constexpr kWindowSeconds = 60 ;
4855 auto constexpr kWindowDuration = std::chrono::seconds (kWindowSeconds );
4956 std::scoped_lock lk (mu_);
5057 if (!last_refresh_status_.ok ()) return last_refresh_status_;
51- // If there are no measurements then the stub has never been used.
52- if (measurements_.empty ()) return 0 ;
58+ // If there are no measurements then the stub has never been used. In real
59+ // use this will be 0. In testing we sometimes set an initial value.
60+ if (measurements_.empty ()) return outstanding_rpcs_;
5361 auto now = clock_->Now ();
5462 auto last_time = now;
5563 auto window_start = now - kWindowDuration ;
0 commit comments