|
|
@ -48,11 +48,11 @@ namespace testing { |
|
|
|
class CallCountingHelperPeer { |
|
|
|
class CallCountingHelperPeer { |
|
|
|
public: |
|
|
|
public: |
|
|
|
explicit CallCountingHelperPeer(CallCountingHelper* node) : node_(node) {} |
|
|
|
explicit CallCountingHelperPeer(CallCountingHelper* node) : node_(node) {} |
|
|
|
grpc_millis last_call_started_millis() const { |
|
|
|
|
|
|
|
|
|
|
|
gpr_timespec last_call_started_time() const { |
|
|
|
CallCountingHelper::CounterData data; |
|
|
|
CallCountingHelper::CounterData data; |
|
|
|
node_->CollectData(&data); |
|
|
|
node_->CollectData(&data); |
|
|
|
gpr_timespec ts = gpr_cycle_counter_to_time(data.last_call_started_cycle); |
|
|
|
return gpr_cycle_counter_to_time(data.last_call_started_cycle); |
|
|
|
return grpc_timespec_to_millis_round_up(ts); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
@ -243,9 +243,9 @@ void ValidateServer(ServerNode* server, const ValidateChannelDataArgs& args) { |
|
|
|
gpr_free(core_api_json_str); |
|
|
|
gpr_free(core_api_json_str); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
grpc_millis GetLastCallStartedMillis(CallCountingHelper* channel) { |
|
|
|
gpr_timespec GetLastCallStartedTime(CallCountingHelper* channel) { |
|
|
|
CallCountingHelperPeer peer(channel); |
|
|
|
CallCountingHelperPeer peer(channel); |
|
|
|
return peer.last_call_started_millis(); |
|
|
|
return peer.last_call_started_time(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ChannelzSleep(int64_t sleep_us) { |
|
|
|
void ChannelzSleep(int64_t sleep_us) { |
|
|
@ -301,28 +301,28 @@ TEST_P(ChannelzChannelTest, BasicChannelAPIFunctionality) { |
|
|
|
ValidateChannel(channelz_channel, {3, 3, 3}); |
|
|
|
ValidateChannel(channelz_channel, {3, 3, 3}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TEST_P(ChannelzChannelTest, LastCallStartedMillis) { |
|
|
|
TEST_P(ChannelzChannelTest, LastCallStartedTime) { |
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
grpc_core::ExecCtx exec_ctx; |
|
|
|
CallCountingHelper counter; |
|
|
|
CallCountingHelper counter; |
|
|
|
// start a call to set the last call started timestamp
|
|
|
|
// start a call to set the last call started timestamp
|
|
|
|
counter.RecordCallStarted(); |
|
|
|
counter.RecordCallStarted(); |
|
|
|
grpc_millis millis1 = GetLastCallStartedMillis(&counter); |
|
|
|
gpr_timespec time1 = GetLastCallStartedTime(&counter); |
|
|
|
// time gone by should not affect the timestamp
|
|
|
|
// time gone by should not affect the timestamp
|
|
|
|
ChannelzSleep(100); |
|
|
|
ChannelzSleep(100); |
|
|
|
grpc_millis millis2 = GetLastCallStartedMillis(&counter); |
|
|
|
gpr_timespec time2 = GetLastCallStartedTime(&counter); |
|
|
|
EXPECT_EQ(millis1, millis2); |
|
|
|
EXPECT_EQ(gpr_time_cmp(time1, time2), 0); |
|
|
|
// calls succeeded or failed should not affect the timestamp
|
|
|
|
// calls succeeded or failed should not affect the timestamp
|
|
|
|
ChannelzSleep(100); |
|
|
|
ChannelzSleep(100); |
|
|
|
counter.RecordCallFailed(); |
|
|
|
counter.RecordCallFailed(); |
|
|
|
counter.RecordCallSucceeded(); |
|
|
|
counter.RecordCallSucceeded(); |
|
|
|
grpc_millis millis3 = GetLastCallStartedMillis(&counter); |
|
|
|
gpr_timespec time3 = GetLastCallStartedTime(&counter); |
|
|
|
EXPECT_EQ(millis1, millis3); |
|
|
|
EXPECT_EQ(gpr_time_cmp(time1, time3), 0); |
|
|
|
// another call started should affect the timestamp
|
|
|
|
// another call started should affect the timestamp
|
|
|
|
// sleep for extra long to avoid flakes (since we cache Now())
|
|
|
|
// sleep for extra long to avoid flakes (since we cache Now())
|
|
|
|
ChannelzSleep(5000); |
|
|
|
ChannelzSleep(5000); |
|
|
|
counter.RecordCallStarted(); |
|
|
|
counter.RecordCallStarted(); |
|
|
|
grpc_millis millis4 = GetLastCallStartedMillis(&counter); |
|
|
|
gpr_timespec time4 = GetLastCallStartedTime(&counter); |
|
|
|
EXPECT_NE(millis1, millis4); |
|
|
|
EXPECT_NE(gpr_time_cmp(time1, time4), 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class ChannelzRegistryBasedTest : public ::testing::TestWithParam<size_t> { |
|
|
|
class ChannelzRegistryBasedTest : public ::testing::TestWithParam<size_t> { |
|
|
|