diff --git a/connections/implementation/analytics/BUILD b/connections/implementation/analytics/BUILD index 8e781b96..903272ff 100644 --- a/connections/implementation/analytics/BUILD +++ b/connections/implementation/analytics/BUILD @@ -68,9 +68,11 @@ cc_test( "//internal/platform:base", "//internal/platform:error_code_recorder", "//internal/platform:logging", + "//internal/platform:test_util", "//internal/platform:types", "//internal/platform/implementation/g3", # build_cleaner: keep "//internal/proto/analytics:connections_log_cc_proto", + "//internal/test", "//net/proto2/contrib/parse_proto:parse_text_proto", "//proto:connections_enums_cc_proto", "@com_github_protobuf_matchers//protobuf-matchers", diff --git a/connections/implementation/analytics/analytics_recorder.cc b/connections/implementation/analytics/analytics_recorder.cc index 2f352045..422b8ae5 100644 --- a/connections/implementation/analytics/analytics_recorder.cc +++ b/connections/implementation/analytics/analytics_recorder.cc @@ -162,20 +162,12 @@ OperationResultCategory ConvertToOperationResultCategory( } } // namespace -AnalyticsRecorder::AnalyticsRecorder(EventLogger *event_logger) +AnalyticsRecorder::AnalyticsRecorder(EventLogger* event_logger) : event_logger_(event_logger) { VLOG(1) << "Start AnalyticsRecorder ctor event_logger_=" << event_logger_; LogStartSession(); } -AnalyticsRecorder::AnalyticsRecorder(EventLogger *event_logger, - bool no_record_time_millis) - : event_logger_(event_logger), - no_record_time_millis_(no_record_time_millis) { - LOG(INFO) << "Start AnalyticsRecorder ctor event_logger_=" << event_logger_; - LogStartSession(); -} - AnalyticsRecorder::~AnalyticsRecorder() = default; bool AnalyticsRecorder::IsSessionLogged() { @@ -184,9 +176,9 @@ bool AnalyticsRecorder::IsSessionLogged() { } int AnalyticsRecorder::GetLatestUpdateIndexLocked( - const std::vector &list) { + const std::vector& list) { int latest_update_index = 0; - for (const auto &operation_result_with_medium : list) { + for (const auto& operation_result_with_medium : list) { if (operation_result_with_medium.update_index() > latest_update_index) { latest_update_index = operation_result_with_medium.update_index(); } @@ -195,8 +187,8 @@ int AnalyticsRecorder::GetLatestUpdateIndexLocked( } void AnalyticsRecorder::OnStartAdvertising( - connections::Strategy strategy, const std::vector &mediums, - AdvertisingMetadataParams *advertising_metadata_params) { + connections::Strategy strategy, const std::vector& mediums, + AdvertisingMetadataParams* advertising_metadata_params) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnStartAdvertising")) { return; @@ -225,7 +217,7 @@ void AnalyticsRecorder::OnStartAdvertising( RepeatedFieldBackInserter( current_advertising_phase_->mutable_adv_dis_result())); } - auto *advertising_metadata = + auto* advertising_metadata = current_advertising_phase_->mutable_advertising_metadata(); advertising_metadata->set_supports_extended_ble_advertisements( advertising_metadata_params->is_extended_advertisement_supported); @@ -257,8 +249,8 @@ int AnalyticsRecorder::GetNextAdvertisingUpdateIndex() { } void AnalyticsRecorder::OnStartDiscovery( - connections::Strategy strategy, const std::vector &mediums, - DiscoveryMetadataParams *discovery_metadata_params) { + connections::Strategy strategy, const std::vector& mediums, + DiscoveryMetadataParams* discovery_metadata_params) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnStartDiscovery")) { return; @@ -287,7 +279,7 @@ void AnalyticsRecorder::OnStartDiscovery( RepeatedFieldBackInserter( current_discovery_phase_->mutable_adv_dis_result())); } - auto *discovery_metadata = + auto* discovery_metadata = current_discovery_phase_->mutable_discovery_metadata(); discovery_metadata->set_supports_extended_ble_advertisements( discovery_metadata_params->is_extended_advertisement_supported); @@ -347,17 +339,15 @@ void AnalyticsRecorder::OnEndpointFound(Medium medium) { "current_discovery_phase_"; return; } - ConnectionsLog::DiscoveredEndpoint *discovered_endpoint = + ConnectionsLog::DiscoveredEndpoint* discovered_endpoint = current_discovery_phase_->add_discovered_endpoint(); discovered_endpoint->set_medium(medium); - if (!no_record_time_millis_) { - discovered_endpoint->set_latency_millis(absl::ToInt64Milliseconds( - SystemClock::ElapsedRealtime() - started_discovery_phase_time_)); - } + discovered_endpoint->set_latency_millis(absl::ToInt64Milliseconds( + SystemClock::ElapsedRealtime() - started_discovery_phase_time_)); } void AnalyticsRecorder::OnRequestConnection( - const connections::Strategy &strategy, const std::string &endpoint_id) { + const connections::Strategy& strategy, const std::string& endpoint_id) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("onRequestConnection")) { return; @@ -370,7 +360,7 @@ void AnalyticsRecorder::OnRequestConnection( } void AnalyticsRecorder::OnConnectionRequestReceived( - const std::string &remote_endpoint_id) { + const std::string& remote_endpoint_id) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnConnectionRequestReceived")) { return; @@ -378,17 +368,15 @@ void AnalyticsRecorder::OnConnectionRequestReceived( absl::Time current_time = SystemClock::ElapsedRealtime(); auto connection_request = std::make_unique(); - if (!no_record_time_millis_) { - connection_request->set_duration_millis(absl::ToUnixMillis(current_time)); - connection_request->set_request_delay_millis(absl::ToInt64Milliseconds( - current_time - started_advertising_phase_time_)); - } + connection_request->set_duration_millis(absl::ToUnixMillis(current_time)); + connection_request->set_request_delay_millis(absl::ToInt64Milliseconds( + current_time - started_advertising_phase_time_)); incoming_connection_requests_.insert( {remote_endpoint_id, std::move(connection_request)}); } void AnalyticsRecorder::OnConnectionRequestSent( - const std::string &remote_endpoint_id) { + const std::string& remote_endpoint_id) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnConnectionRequestSent")) { return; @@ -396,17 +384,15 @@ void AnalyticsRecorder::OnConnectionRequestSent( absl::Time current_time = SystemClock::ElapsedRealtime(); auto connection_request = std::make_unique(); - if (!no_record_time_millis_) { - connection_request->set_duration_millis(absl::ToUnixMillis(current_time)); - connection_request->set_request_delay_millis(absl::ToInt64Milliseconds( - current_time - started_discovery_phase_time_)); - } + connection_request->set_duration_millis(absl::ToUnixMillis(current_time)); + connection_request->set_request_delay_millis( + absl::ToInt64Milliseconds(current_time - started_discovery_phase_time_)); outgoing_connection_requests_.insert( {remote_endpoint_id, std::move(connection_request)}); } void AnalyticsRecorder::OnRemoteEndpointAccepted( - const std::string &remote_endpoint_id) { + const std::string& remote_endpoint_id) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnRemoteEndpointAccepted")) { return; @@ -415,7 +401,7 @@ void AnalyticsRecorder::OnRemoteEndpointAccepted( } void AnalyticsRecorder::OnLocalEndpointAccepted( - const std::string &remote_endpoint_id) { + const std::string& remote_endpoint_id) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnLocalEndpointAccepted")) { return; @@ -424,7 +410,7 @@ void AnalyticsRecorder::OnLocalEndpointAccepted( } void AnalyticsRecorder::OnRemoteEndpointRejected( - const std::string &remote_endpoint_id) { + const std::string& remote_endpoint_id) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnRemoteEndpointRejected")) { return; @@ -433,7 +419,7 @@ void AnalyticsRecorder::OnRemoteEndpointRejected( } void AnalyticsRecorder::OnLocalEndpointRejected( - const std::string &remote_endpoint_id) { + const std::string& remote_endpoint_id) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnLocalEndpointRejected")) { return; @@ -443,8 +429,8 @@ void AnalyticsRecorder::OnLocalEndpointRejected( void AnalyticsRecorder::OnIncomingConnectionAttempt( ConnectionAttemptType type, Medium medium, ConnectionAttemptResult result, - absl::Duration duration, const std::string &connection_token, - ConnectionAttemptMetadataParams *connection_attempt_metadata_params) { + absl::Duration duration, const std::string& connection_token, + ConnectionAttemptMetadataParams* connection_attempt_metadata_params) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnIncomingConnectionAttempt")) { return; @@ -468,21 +454,18 @@ void AnalyticsRecorder::OnIncomingConnectionAttemptLocked( location::nearby::proto::connections::ConnectionAttemptType type, location::nearby::proto::connections::Medium medium, location::nearby::proto::connections::ConnectionAttemptResult result, - absl::Duration duration, const std::string &connection_token, - ConnectionAttemptMetadataParams *connection_attempt_metadata_params) { - auto *connection_attempt = + absl::Duration duration, const std::string& connection_token, + ConnectionAttemptMetadataParams* connection_attempt_metadata_params) { + auto* connection_attempt = current_strategy_session_->add_connection_attempt(); - if (!no_record_time_millis_) { - connection_attempt->set_duration_millis( - absl::ToInt64Milliseconds(duration)); - } + connection_attempt->set_duration_millis(absl::ToInt64Milliseconds(duration)); connection_attempt->set_type(type); connection_attempt->set_direction(INCOMING); connection_attempt->set_medium(medium); connection_attempt->set_attempt_result(result); connection_attempt->set_connection_token(connection_token); - auto *connection_attempt_metadata = + auto* connection_attempt_metadata = connection_attempt->mutable_connection_attempt_metadata(); connection_attempt_metadata->set_technology( connection_attempt_metadata_params->technology); @@ -520,10 +503,10 @@ void AnalyticsRecorder::OnIncomingConnectionAttemptLocked( } void AnalyticsRecorder::OnOutgoingConnectionAttempt( - const std::string &remote_endpoint_id, ConnectionAttemptType type, + const std::string& remote_endpoint_id, ConnectionAttemptType type, Medium medium, ConnectionAttemptResult result, absl::Duration duration, - const std::string &connection_token, - ConnectionAttemptMetadataParams *connection_attempt_metadata_params) { + const std::string& connection_token, + ConnectionAttemptMetadataParams* connection_attempt_metadata_params) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnOutgoingConnectionAttempt")) { return; @@ -554,23 +537,20 @@ void AnalyticsRecorder::OnOutgoingConnectionAttempt( } void AnalyticsRecorder::OnOutgoingConnectionAttemptLocked( - const std::string &remote_endpoint_id, ConnectionAttemptType type, + const std::string& remote_endpoint_id, ConnectionAttemptType type, Medium medium, ConnectionAttemptResult result, absl::Duration duration, - const std::string &connection_token, - ConnectionAttemptMetadataParams *connection_attempt_metadata_params) { - auto *connection_attempt = + const std::string& connection_token, + ConnectionAttemptMetadataParams* connection_attempt_metadata_params) { + auto* connection_attempt = current_strategy_session_->add_connection_attempt(); - if (!no_record_time_millis_) { - connection_attempt->set_duration_millis( - absl::ToInt64Milliseconds(duration)); - } + connection_attempt->set_duration_millis(absl::ToInt64Milliseconds(duration)); connection_attempt->set_type(type); connection_attempt->set_direction(OUTGOING); connection_attempt->set_medium(medium); connection_attempt->set_attempt_result(result); connection_attempt->set_connection_token(connection_token); - auto *connection_attempt_metadata = + auto* connection_attempt_metadata = connection_attempt->mutable_connection_attempt_metadata(); connection_attempt_metadata->set_technology( connection_attempt_metadata_params->technology); @@ -613,7 +593,7 @@ void AnalyticsRecorder::OnOutgoingConnectionAttemptLocked( // ConnectionRequest that, since the ConnectionAttempt has failed, will // never be delivered to the advertiser. auto pair = outgoing_connection_requests_.extract(it); - std::unique_ptr &connection_request = + std::unique_ptr& connection_request = pair.mapped(); connection_request->set_local_response(NOT_SENT); connection_request->set_remote_response(NOT_SENT); @@ -623,24 +603,24 @@ void AnalyticsRecorder::OnOutgoingConnectionAttemptLocked( } void AnalyticsRecorder::OnConnectionEstablished( - const std::string &endpoint_id, Medium medium, - const std::string &connection_token) { + const std::string& endpoint_id, Medium medium, + const std::string& connection_token) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnConnectionEstablished")) { return; } auto it = active_connections_.find(endpoint_id); if (it != active_connections_.end()) { - const std::unique_ptr &logical_connection = it->second; + const std::unique_ptr& logical_connection = it->second; logical_connection->PhysicalConnectionEstablished(medium, connection_token); } else { active_connections_.insert( - {endpoint_id, std::make_unique( - medium, connection_token, no_record_time_millis_)}); + {endpoint_id, + std::make_unique(medium, connection_token)}); } } -void AnalyticsRecorder::OnConnectionClosed(const std::string &endpoint_id, +void AnalyticsRecorder::OnConnectionClosed(const std::string& endpoint_id, Medium medium, DisconnectionReason reason, SafeDisconnectionResult result) { @@ -665,14 +645,14 @@ void AnalyticsRecorder::OnConnectionClosed(const std::string &endpoint_id, if (it == active_connections_.end()) { return; } - const std::unique_ptr &logical_connection = it->second; + const std::unique_ptr& logical_connection = it->second; logical_connection->PhysicalConnectionClosed(medium, reason, result); if (reason != UPGRADED) { // Unless this is an upgraded connection, remove this from our active // connections. Any future communication with an endpoint will need to be // re-established with a new ConnectionRequest. auto pair = active_connections_.extract(it); - std::unique_ptr &logical_connection = pair.mapped(); + std::unique_ptr& logical_connection = pair.mapped(); absl::c_copy( logical_connection->GetEstablisedConnections(), @@ -682,7 +662,7 @@ void AnalyticsRecorder::OnConnectionClosed(const std::string &endpoint_id, } void AnalyticsRecorder::OnIncomingPayloadStarted( - const std::string &endpoint_id, std::int64_t payload_id, + const std::string& endpoint_id, std::int64_t payload_id, connections::PayloadType type, std::int64_t total_size_bytes) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnIncomingPayloadStarted")) { @@ -692,12 +672,12 @@ void AnalyticsRecorder::OnIncomingPayloadStarted( if (it == active_connections_.end()) { return; } - const std::unique_ptr &logical_connection = it->second; + const std::unique_ptr& logical_connection = it->second; logical_connection->IncomingPayloadStarted( payload_id, PayloadTypeToProtoPayloadType(type), total_size_bytes); } -void AnalyticsRecorder::OnPayloadChunkReceived(const std::string &endpoint_id, +void AnalyticsRecorder::OnPayloadChunkReceived(const std::string& endpoint_id, std::int64_t payload_id, std::int64_t chunk_size_bytes) { MutexLock lock(&mutex_); @@ -708,12 +688,12 @@ void AnalyticsRecorder::OnPayloadChunkReceived(const std::string &endpoint_id, if (it == active_connections_.end()) { return; } - const std::unique_ptr &logical_connection = it->second; + const std::unique_ptr& logical_connection = it->second; logical_connection->ChunkReceived(payload_id, chunk_size_bytes); } void AnalyticsRecorder::OnIncomingPayloadDone( - const std::string &endpoint_id, std::int64_t payload_id, + const std::string& endpoint_id, std::int64_t payload_id, PayloadStatus status, OperationResultCode operation_result_code) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnIncomingPayloadDone")) { @@ -723,30 +703,30 @@ void AnalyticsRecorder::OnIncomingPayloadDone( if (it == active_connections_.end()) { return; } - const std::unique_ptr &logical_connection = it->second; + const std::unique_ptr& logical_connection = it->second; logical_connection->IncomingPayloadDone(payload_id, status, operation_result_code); } void AnalyticsRecorder::OnOutgoingPayloadStarted( - const std::vector &endpoint_ids, std::int64_t payload_id, + const std::vector& endpoint_ids, std::int64_t payload_id, connections::PayloadType type, std::int64_t total_size_bytes) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnOutgoingPayloadStarted")) { return; } - for (const auto &endpoint_id : endpoint_ids) { + for (const auto& endpoint_id : endpoint_ids) { auto it = active_connections_.find(endpoint_id); if (it == active_connections_.end()) { continue; } - const std::unique_ptr &logical_connection = it->second; + const std::unique_ptr& logical_connection = it->second; logical_connection->OutgoingPayloadStarted( payload_id, PayloadTypeToProtoPayloadType(type), total_size_bytes); } } -void AnalyticsRecorder::OnPayloadChunkSent(const std::string &endpoint_id, +void AnalyticsRecorder::OnPayloadChunkSent(const std::string& endpoint_id, std::int64_t payload_id, std::int64_t chunk_size_bytes) { MutexLock lock(&mutex_); @@ -757,12 +737,12 @@ void AnalyticsRecorder::OnPayloadChunkSent(const std::string &endpoint_id, if (it == active_connections_.end()) { return; } - const std::unique_ptr &logical_connection = it->second; + const std::unique_ptr& logical_connection = it->second; logical_connection->ChunkSent(payload_id, chunk_size_bytes); } void AnalyticsRecorder::OnOutgoingPayloadDone( - const std::string &endpoint_id, std::int64_t payload_id, + const std::string& endpoint_id, std::int64_t payload_id, PayloadStatus status, OperationResultCode operation_result_code) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnOutgoingPayloadDone")) { @@ -773,24 +753,22 @@ void AnalyticsRecorder::OnOutgoingPayloadDone( return; } - const std::unique_ptr &logical_connection = it->second; + const std::unique_ptr& logical_connection = it->second; logical_connection->OutgoingPayloadDone(payload_id, status, operation_result_code); } void AnalyticsRecorder::OnBandwidthUpgradeStarted( - const std::string &endpoint_id, Medium from_medium, Medium to_medium, - ConnectionAttemptDirection direction, const std::string &connection_token) { + const std::string& endpoint_id, Medium from_medium, Medium to_medium, + ConnectionAttemptDirection direction, const std::string& connection_token) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnBandwidthUpgradeStarted")) { return; } auto bandwidth_upgrade_attempt = std::make_unique(); - if (!no_record_time_millis_) { - bandwidth_upgrade_attempt->set_duration_millis( - absl::ToUnixMillis(SystemClock::ElapsedRealtime())); - } + bandwidth_upgrade_attempt->set_duration_millis( + absl::ToUnixMillis(SystemClock::ElapsedRealtime())); bandwidth_upgrade_attempt->set_from_medium(from_medium); bandwidth_upgrade_attempt->set_to_medium(to_medium); bandwidth_upgrade_attempt->set_direction(direction); @@ -800,7 +778,7 @@ void AnalyticsRecorder::OnBandwidthUpgradeStarted( } void AnalyticsRecorder::OnBandwidthUpgradeError( - const std::string &endpoint_id, BandwidthUpgradeResult result, + const std::string& endpoint_id, BandwidthUpgradeResult result, BandwidthUpgradeErrorStage error_stage, OperationResultCode operation_result_code) { MutexLock lock(&mutex_); @@ -817,7 +795,7 @@ void AnalyticsRecorder::OnBandwidthUpgradeError( } void AnalyticsRecorder::OnBandwidthUpgradeSuccess( - const std::string &endpoint_id) { + const std::string& endpoint_id) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnBandwidthUpgradeSuccess")) { return; @@ -827,7 +805,7 @@ void AnalyticsRecorder::OnBandwidthUpgradeSuccess( OperationResultCode::DETAIL_SUCCESS); } -void AnalyticsRecorder::OnErrorCode(const ErrorCodeParams ¶ms) { +void AnalyticsRecorder::OnErrorCode(const ErrorCodeParams& params) { MutexLock lock(&mutex_); if (!CanRecordAnalyticsLocked("OnErrorCode")) { return; @@ -912,10 +890,8 @@ void AnalyticsRecorder::LogSession() { return; } FinishStrategySessionLocked(); - if (!no_record_time_millis_) { - client_session_->set_duration_millis(absl::ToInt64Milliseconds( - SystemClock::ElapsedRealtime() - started_client_session_time_)); - } + client_session_->set_duration_millis(absl::ToInt64Milliseconds( + SystemClock::ElapsedRealtime() - started_client_session_time_)); LogClientSessionLocked(); LogEvent(STOP_CLIENT_SESSION); start_client_session_was_logged_ = false; @@ -926,8 +902,8 @@ std::unique_ptr AnalyticsRecorder::BuildAdvertisingMetadataParams( bool is_extended_advertisement_supported, int connected_ap_frequency, bool is_nfc_available, - const std::vector - &operation_result_with_mediums) { + const std::vector& + operation_result_with_mediums) { auto params = std::make_unique(); params->is_extended_advertisement_supported = is_extended_advertisement_supported; @@ -942,8 +918,8 @@ std::unique_ptr AnalyticsRecorder::BuildDiscoveryMetadataParams( bool is_extended_advertisement_supported, int connected_ap_frequency, bool is_nfc_available, - const std::vector - &operation_result_with_mediums) { + const std::vector& + operation_result_with_mediums) { auto params = std::make_unique(); params->is_extended_advertisement_supported = is_extended_advertisement_supported; @@ -957,8 +933,8 @@ AnalyticsRecorder::BuildDiscoveryMetadataParams( std::unique_ptr AnalyticsRecorder::BuildConnectionAttemptMetadataParams( ConnectionTechnology technology, ConnectionBand band, int frequency, - int try_count, const std::string &network_operator, - const std::string &country_code, bool is_tdls_used, + int try_count, const std::string& network_operator, + const std::string& country_code, bool is_tdls_used, bool wifi_hotspot_enabled, int max_wifi_tx_speed, int max_wifi_rx_speed, int channel_width, OperationResultCode operation_result_code) { auto params = std::make_unique(); @@ -1091,8 +1067,7 @@ void AnalyticsRecorder::RecordAdvertisingPhaseDurationAndReasonLocked( "null current_advertising_phase_"; return; } - if (!current_advertising_phase_->has_duration_millis() && - !no_record_time_millis_) { + if (!current_advertising_phase_->has_duration_millis()) { current_advertising_phase_->set_duration_millis(absl::ToInt64Milliseconds( SystemClock::ElapsedRealtime() - started_advertising_phase_time_)); } @@ -1105,11 +1080,11 @@ void AnalyticsRecorder::RecordAdvertisingPhaseDurationAndReasonLocked( void AnalyticsRecorder::FinishAdvertisingPhaseLocked() { if (current_advertising_phase_ != nullptr) { - for (const auto &item : incoming_connection_requests_) { + for (const auto& item : incoming_connection_requests_) { // ConnectionRequests still pending have been ignored by the local or // remote (or both) endpoints. - const std::unique_ptr - &connection_request = item.second; + const std::unique_ptr& + connection_request = item.second; MarkConnectionRequestIgnoredLocked(connection_request.get()); UpdateAdvertiserConnectionRequestLocked(connection_request.get()); } @@ -1132,8 +1107,7 @@ void AnalyticsRecorder::RecordDiscoveryPhaseDurationAndReasonLocked( "null current_discovery_phase_"; return; } - if (!current_discovery_phase_->has_duration_millis() && - !no_record_time_millis_) { + if (!current_discovery_phase_->has_duration_millis()) { current_discovery_phase_->set_duration_millis(absl::ToInt64Milliseconds( SystemClock::ElapsedRealtime() - started_discovery_phase_time_)); } @@ -1147,11 +1121,11 @@ void AnalyticsRecorder::RecordDiscoveryPhaseDurationAndReasonLocked( void AnalyticsRecorder::FinishDiscoveryPhaseLocked() { if (current_discovery_phase_ != nullptr) { - for (const auto &item : outgoing_connection_requests_) { + for (const auto& item : outgoing_connection_requests_) { // ConnectionRequests still pending have been ignored by the local or // remote (or both) endpoints. - const std::unique_ptr - &connection_request = item.second; + const std::unique_ptr& + connection_request = item.second; MarkConnectionRequestIgnoredLocked(connection_request.get()); UpdateDiscovererConnectionRequestLocked(connection_request.get()); } @@ -1168,18 +1142,16 @@ void AnalyticsRecorder::FinishDiscoveryPhaseLocked() { } bool AnalyticsRecorder::UpdateAdvertiserConnectionRequestLocked( - ConnectionsLog::ConnectionRequest *request) { + ConnectionsLog::ConnectionRequest* request) { if (current_advertising_phase_ == nullptr) { LOG(INFO) << "Unable to record advertiser connection request due to null " "current_advertising_phase_"; return false; } if (BothEndpointsRespondedLocked(request)) { - if (!no_record_time_millis_) { - request->set_duration_millis( - absl::ToUnixMillis(SystemClock::ElapsedRealtime()) - - request->duration_millis()); - } + request->set_duration_millis( + absl::ToUnixMillis(SystemClock::ElapsedRealtime()) - + request->duration_millis()); *current_advertising_phase_->add_received_connection_request() = *request; return true; } @@ -1187,7 +1159,7 @@ bool AnalyticsRecorder::UpdateAdvertiserConnectionRequestLocked( } bool AnalyticsRecorder::UpdateDiscovererConnectionRequestLocked( - ConnectionsLog::ConnectionRequest *request) { + ConnectionsLog::ConnectionRequest* request) { if (current_discovery_phase_ == nullptr) { LOG(INFO) << "Unable to record discoverer connection request due " "to null current_discovery_phase_."; @@ -1195,11 +1167,9 @@ bool AnalyticsRecorder::UpdateDiscovererConnectionRequestLocked( } if (BothEndpointsRespondedLocked(request) || request->local_response() == NOT_SENT) { - if (!no_record_time_millis_) { - request->set_duration_millis( - absl::ToUnixMillis(SystemClock::ElapsedRealtime()) - - request->duration_millis()); - } + request->set_duration_millis( + absl::ToUnixMillis(SystemClock::ElapsedRealtime()) - + request->duration_millis()); *current_discovery_phase_->add_sent_connection_request() = *request; return true; } @@ -1207,15 +1177,15 @@ bool AnalyticsRecorder::UpdateDiscovererConnectionRequestLocked( } bool AnalyticsRecorder::BothEndpointsRespondedLocked( - ConnectionsLog::ConnectionRequest *request) { + ConnectionsLog::ConnectionRequest* request) { return request->has_local_response() && request->has_remote_response(); } void AnalyticsRecorder::LocalEndpointRespondedLocked( - const std::string &remote_endpoint_id, ConnectionRequestResponse response) { + const std::string& remote_endpoint_id, ConnectionRequestResponse response) { auto out = outgoing_connection_requests_.find(remote_endpoint_id); if (out != outgoing_connection_requests_.end()) { - ConnectionsLog::ConnectionRequest *connection_request = out->second.get(); + ConnectionsLog::ConnectionRequest* connection_request = out->second.get(); connection_request->set_local_response(response); if (UpdateDiscovererConnectionRequestLocked(connection_request)) { outgoing_connection_requests_.erase(out); @@ -1223,7 +1193,7 @@ void AnalyticsRecorder::LocalEndpointRespondedLocked( } auto in = incoming_connection_requests_.find(remote_endpoint_id); if (in != incoming_connection_requests_.end()) { - ConnectionsLog::ConnectionRequest *connection_request = in->second.get(); + ConnectionsLog::ConnectionRequest* connection_request = in->second.get(); connection_request->set_local_response(response); if (UpdateAdvertiserConnectionRequestLocked(connection_request)) { incoming_connection_requests_.erase(in); @@ -1232,10 +1202,10 @@ void AnalyticsRecorder::LocalEndpointRespondedLocked( } void AnalyticsRecorder::RemoteEndpointRespondedLocked( - const std::string &remote_endpoint_id, ConnectionRequestResponse response) { + const std::string& remote_endpoint_id, ConnectionRequestResponse response) { auto out = outgoing_connection_requests_.find(remote_endpoint_id); if (out != outgoing_connection_requests_.end()) { - ConnectionsLog::ConnectionRequest *connection_request = out->second.get(); + ConnectionsLog::ConnectionRequest* connection_request = out->second.get(); connection_request->set_remote_response(response); if (UpdateDiscovererConnectionRequestLocked(connection_request)) { outgoing_connection_requests_.erase(out); @@ -1243,7 +1213,7 @@ void AnalyticsRecorder::RemoteEndpointRespondedLocked( } auto in = incoming_connection_requests_.find(remote_endpoint_id); if (in != incoming_connection_requests_.end()) { - ConnectionsLog::ConnectionRequest *connection_request = in->second.get(); + ConnectionsLog::ConnectionRequest* connection_request = in->second.get(); connection_request->set_remote_response(response); if (UpdateAdvertiserConnectionRequestLocked(connection_request)) { incoming_connection_requests_.erase(in); @@ -1252,7 +1222,7 @@ void AnalyticsRecorder::RemoteEndpointRespondedLocked( } void AnalyticsRecorder::MarkConnectionRequestIgnoredLocked( - ConnectionsLog::ConnectionRequest *request) { + ConnectionsLog::ConnectionRequest* request) { if (!request->has_local_response()) { request->set_local_response(IGNORED); } @@ -1263,13 +1233,13 @@ void AnalyticsRecorder::MarkConnectionRequestIgnoredLocked( bool AnalyticsRecorder::ConnectionAttemptResultCodeExistedLocked( Medium medium, ConnectionAttemptDirection direction, - const std::string &connection_token, ConnectionAttemptType type, + const std::string& connection_token, ConnectionAttemptType type, OperationResultCode operation_result_code) { if (current_strategy_session_ == nullptr || current_strategy_session_->connection_attempt_size() == 0) { return false; } - for (auto &connection_attempt : + for (auto& connection_attempt : current_strategy_session_->connection_attempt()) { if (connection_attempt.medium() == medium && connection_attempt.direction() == direction && @@ -1288,7 +1258,7 @@ bool AnalyticsRecorder::ConnectionAttemptResultCodeExistedLocked( // stage and result code, we'll drop the duplicate logs for preventing the waste // of log storage space bool AnalyticsRecorder::EraseIfBandwidthUpgradeRecordExistedLocked( - const std::string &endpoint_id, BandwidthUpgradeResult result, + const std::string& endpoint_id, BandwidthUpgradeResult result, BandwidthUpgradeErrorStage error_stage, OperationResultCode operation_result_code) { if (current_strategy_session_ == nullptr) { @@ -1296,8 +1266,8 @@ bool AnalyticsRecorder::EraseIfBandwidthUpgradeRecordExistedLocked( } auto it = bandwidth_upgrade_attempts_.find(endpoint_id); if (it != bandwidth_upgrade_attempts_.end()) { - ConnectionsLog::BandwidthUpgradeAttempt *attempt = it->second.get(); - for (auto &existing_attempt : + ConnectionsLog::BandwidthUpgradeAttempt* attempt = it->second.get(); + for (auto& existing_attempt : current_strategy_session_->upgrade_attempt()) { if (attempt->from_medium() == existing_attempt.from_medium() && attempt->to_medium() == existing_attempt.to_medium() && @@ -1314,7 +1284,7 @@ bool AnalyticsRecorder::EraseIfBandwidthUpgradeRecordExistedLocked( } void AnalyticsRecorder::FinishUpgradeAttemptLocked( - const std::string &endpoint_id, BandwidthUpgradeResult result, + const std::string& endpoint_id, BandwidthUpgradeResult result, BandwidthUpgradeErrorStage error_stage, OperationResultCode operation_result_code, bool erase_item) { if (current_strategy_session_ == nullptr) { @@ -1325,12 +1295,10 @@ void AnalyticsRecorder::FinishUpgradeAttemptLocked( // Add the BandwidthUpgradeAttempt in the current StrategySession. auto it = bandwidth_upgrade_attempts_.find(endpoint_id); if (it != bandwidth_upgrade_attempts_.end()) { - ConnectionsLog::BandwidthUpgradeAttempt *attempt = it->second.get(); - if (!no_record_time_millis_) { - attempt->set_duration_millis( - absl::ToUnixMillis(SystemClock::ElapsedRealtime()) - - attempt->duration_millis()); - } + ConnectionsLog::BandwidthUpgradeAttempt* attempt = it->second.get(); + attempt->set_duration_millis( + absl::ToUnixMillis(SystemClock::ElapsedRealtime()) - + attempt->duration_millis()); attempt->set_error_stage(error_stage); attempt->set_upgrade_result(result); @@ -1353,8 +1321,8 @@ void AnalyticsRecorder::FinishStrategySessionLocked() { FinishDiscoveryPhaseLocked(); // Finish any unfinished LogicalConnections. - for (const auto &item : active_connections_) { - const std::unique_ptr &logical_connection = + for (const auto& item : active_connections_) { + const std::unique_ptr& logical_connection = item.second; logical_connection->CloseAllPhysicalConnections(); absl::c_copy( @@ -1365,7 +1333,7 @@ void AnalyticsRecorder::FinishStrategySessionLocked() { active_connections_.clear(); // Finish any pending upgrade attempts. - for (const auto &item : bandwidth_upgrade_attempts_) { + for (const auto& item : bandwidth_upgrade_attempts_) { FinishUpgradeAttemptLocked( item.first, UNFINISHED_ERROR, UPGRADE_UNFINISHED, OperationResultCode::DEVICE_STATE_ERROR_UNFINISHED_UPGRADE_ATTEMPTS, @@ -1375,11 +1343,8 @@ void AnalyticsRecorder::FinishStrategySessionLocked() { // Add the StrategySession in ClientSession if (current_strategy_session_ != nullptr) { - if (!no_record_time_millis_) { - current_strategy_session_->set_duration_millis( - absl::ToInt64Milliseconds(SystemClock::ElapsedRealtime() - - started_strategy_session_time_)); - } + current_strategy_session_->set_duration_millis(absl::ToInt64Milliseconds( + SystemClock::ElapsedRealtime() - started_strategy_session_time_)); *client_session_->add_strategy_session() = *std::move(current_strategy_session_); } @@ -1427,10 +1392,8 @@ void AnalyticsRecorder::PendingPayload::AddChunk( ConnectionsLog::Payload AnalyticsRecorder::PendingPayload::GetProtoPayload( PayloadStatus status) { ConnectionsLog::Payload payload; - if (!no_record_time_millis_) { - payload.set_duration_millis(absl::ToInt64Milliseconds( - SystemClock::ElapsedRealtime() - start_time_)); - } + payload.set_duration_millis( + absl::ToInt64Milliseconds(SystemClock::ElapsedRealtime() - start_time_)); payload.set_type(type_); payload.set_total_size_bytes(total_size_bytes_); payload.set_num_bytes_transferred(num_bytes_transferred_); @@ -1448,7 +1411,7 @@ ConnectionsLog::Payload AnalyticsRecorder::PendingPayload::GetProtoPayload( } void AnalyticsRecorder::LogicalConnection::PhysicalConnectionEstablished( - Medium medium, const std::string &connection_token) { + Medium medium, const std::string& connection_token) { if (current_medium_ != UNKNOWN_MEDIUM) { LOG(WARNING) << "Unexpected call to PhysicalConnectionEstablished while " "AnalyticsRecorder still has an active current medium."; @@ -1457,10 +1420,8 @@ void AnalyticsRecorder::LogicalConnection::PhysicalConnectionEstablished( auto established_connection = std::make_unique(); established_connection->set_medium(medium); - if (!no_record_time_millis_) { - established_connection->set_duration_millis( - absl::ToUnixMillis(SystemClock::ElapsedRealtime())); - } + established_connection->set_duration_millis( + absl::ToUnixMillis(SystemClock::ElapsedRealtime())); established_connection->set_connection_token(connection_token); auto operation_result_proto = @@ -1496,7 +1457,7 @@ void AnalyticsRecorder::LogicalConnection::PhysicalConnectionClosed( " opened."; return; } - ConnectionsLog::EstablishedConnection *established_connection = + ConnectionsLog::EstablishedConnection* established_connection = it->second.get(); if (established_connection->has_disconnection_reason()) { LOG(WARNING) << "Unexpected call to physicalConnectionClosed() for medium " @@ -1516,8 +1477,8 @@ void AnalyticsRecorder::LogicalConnection::PhysicalConnectionClosed( } void AnalyticsRecorder::LogicalConnection::CloseAllPhysicalConnections() { - for (const auto &physical_connection : physical_connections_) { - ConnectionsLog::EstablishedConnection *established_connection = + for (const auto& physical_connection : physical_connections_) { + ConnectionsLog::EstablishedConnection* established_connection = physical_connection.second.get(); if (!established_connection->has_disconnection_reason()) { FinishPhysicalConnection( @@ -1539,10 +1500,10 @@ AnalyticsRecorder::LogicalConnection::GetEstablisedConnections() { } std::transform(physical_connections_.begin(), physical_connections_.end(), std::back_inserter(established_connections), - [](auto &kv) { return *kv.second; }); + [](auto& kv) { return *kv.second; }); physical_connections_.clear(); - for (auto &established_connection : established_connections) { + for (auto& established_connection : established_connections) { if (absl::Milliseconds(established_connection.duration_millis()) >= kConnectionTokenMaxLife) { LOG(INFO) << "connection token exceed TTL, drop token."; @@ -1556,8 +1517,7 @@ AnalyticsRecorder::LogicalConnection::GetEstablisedConnections() { void AnalyticsRecorder::LogicalConnection::IncomingPayloadStarted( std::int64_t payload_id, PayloadType type, std::int64_t total_size_bytes) { incoming_payloads_.insert( - {payload_id, std::make_unique(type, total_size_bytes, - no_record_time_millis_)}); + {payload_id, std::make_unique(type, total_size_bytes)}); } void AnalyticsRecorder::LogicalConnection::ChunkReceived( @@ -1566,7 +1526,7 @@ void AnalyticsRecorder::LogicalConnection::ChunkReceived( if (it == incoming_payloads_.end()) { return; } - PendingPayload *pending_payload = it->second.get(); + PendingPayload* pending_payload = it->second.get(); pending_payload->AddChunk(size_bytes); } @@ -1580,8 +1540,8 @@ void AnalyticsRecorder::LogicalConnection::IncomingPayloadDone( } auto it = physical_connections_.find(current_medium_); if (it != physical_connections_.end()) { - const std::unique_ptr - &established_connection = it->second; + const std::unique_ptr& + established_connection = it->second; auto it = incoming_payloads_.find(payload_id); if (it != incoming_payloads_.end()) { it->second->SetOperationResultCode(operation_result_code); @@ -1595,8 +1555,7 @@ void AnalyticsRecorder::LogicalConnection::IncomingPayloadDone( void AnalyticsRecorder::LogicalConnection::OutgoingPayloadStarted( std::int64_t payload_id, PayloadType type, std::int64_t total_size_bytes) { outgoing_payloads_.insert( - {payload_id, std::make_unique(type, total_size_bytes, - no_record_time_millis_)}); + {payload_id, std::make_unique(type, total_size_bytes)}); } void AnalyticsRecorder::LogicalConnection::ChunkSent(std::int64_t payload_id, @@ -1605,7 +1564,7 @@ void AnalyticsRecorder::LogicalConnection::ChunkSent(std::int64_t payload_id, if (it == outgoing_payloads_.end()) { return; } - PendingPayload *payload = it->second.get(); + PendingPayload* payload = it->second.get(); payload->AddChunk(size_bytes); } @@ -1619,8 +1578,8 @@ void AnalyticsRecorder::LogicalConnection::OutgoingPayloadDone( } auto it = physical_connections_.find(current_medium_); if (it != physical_connections_.end()) { - const std::unique_ptr - &established_connection = it->second; + const std::unique_ptr& + established_connection = it->second; auto it = outgoing_payloads_.find(payload_id); if (it != outgoing_payloads_.end()) { it->second->SetOperationResultCode(operation_result_code); @@ -1632,15 +1591,13 @@ void AnalyticsRecorder::LogicalConnection::OutgoingPayloadDone( } void AnalyticsRecorder::LogicalConnection::FinishPhysicalConnection( - ConnectionsLog::EstablishedConnection *established_connection, + ConnectionsLog::EstablishedConnection* established_connection, DisconnectionReason reason, SafeDisconnectionResult result) { established_connection->set_disconnection_reason(reason); established_connection->set_safe_disconnection_result(result); - if (!no_record_time_millis_) { - established_connection->set_duration_millis( - absl::ToUnixMillis(SystemClock::ElapsedRealtime()) - - established_connection->duration_millis()); - } + established_connection->set_duration_millis( + absl::ToUnixMillis(SystemClock::ElapsedRealtime()) - + established_connection->duration_millis()); // Add any not-yet-finished payloads to this EstablishedConnection. std::vector in_payloads = @@ -1657,8 +1614,8 @@ void AnalyticsRecorder::LogicalConnection::FinishPhysicalConnection( std::vector AnalyticsRecorder::LogicalConnection::ResolvePendingPayloads( - absl::btree_map> - &pending_payloads, + absl::btree_map>& + pending_payloads, DisconnectionReason reason) { std::vector completed_payloads; absl::btree_map> @@ -1668,8 +1625,8 @@ AnalyticsRecorder::LogicalConnection::ResolvePendingPayloads( OperationResultCode operation_result_code = GetPendingPayloadResultCodeFromReason(reason); - for (const auto &item : pending_payloads) { - const std::unique_ptr &pending_payload = item.second; + for (const auto& item : pending_payloads) { + const std::unique_ptr& pending_payload = item.second; pending_payload->SetOperationResultCode(operation_result_code); ConnectionsLog::Payload proto_payload = pending_payload->GetProtoPayload(status); @@ -1677,9 +1634,9 @@ AnalyticsRecorder::LogicalConnection::ResolvePendingPayloads( if (reason == UPGRADED) { upgraded_payloads.insert( {item.first, - std::make_unique( - pending_payload->type(), pending_payload->total_size_bytes(), - no_record_time_millis_, operation_result_code)}); + std::make_unique(pending_payload->type(), + pending_payload->total_size_bytes(), + operation_result_code)}); } } pending_payloads.clear(); diff --git a/connections/implementation/analytics/analytics_recorder.h b/connections/implementation/analytics/analytics_recorder.h index d063d573..4f1fe1e8 100644 --- a/connections/implementation/analytics/analytics_recorder.h +++ b/connections/implementation/analytics/analytics_recorder.h @@ -42,17 +42,14 @@ namespace analytics { class AnalyticsRecorder { public: - explicit AnalyticsRecorder(::nearby::analytics::EventLogger *event_logger); - // For testing only. - AnalyticsRecorder(::nearby::analytics::EventLogger *event_logger, - bool no_record_time_millis); + explicit AnalyticsRecorder(::nearby::analytics::EventLogger* event_logger); virtual ~AnalyticsRecorder(); // Advertising phase void OnStartAdvertising( connections::Strategy strategy, - const std::vector &mediums, - AdvertisingMetadataParams *advertising_metadata_params) + const std::vector& mediums, + AdvertisingMetadataParams* advertising_metadata_params) ABSL_LOCKS_EXCLUDED(mutex_); void OnStopAdvertising() ABSL_LOCKS_EXCLUDED(mutex_); @@ -70,8 +67,8 @@ class AnalyticsRecorder { // Discovery phase void OnStartDiscovery( connections::Strategy strategy, - const std::vector &mediums, - DiscoveryMetadataParams *discovery_metadata_params) + const std::vector& mediums, + DiscoveryMetadataParams* discovery_metadata_params) ABSL_LOCKS_EXCLUDED(mutex_); void OnStopDiscovery() ABSL_LOCKS_EXCLUDED(mutex_); @@ -84,21 +81,21 @@ class AnalyticsRecorder { ABSL_LOCKS_EXCLUDED(mutex_); // Connection request - void OnRequestConnection(const connections::Strategy &strategy, - const std::string &endpoint_id) + void OnRequestConnection(const connections::Strategy& strategy, + const std::string& endpoint_id) ABSL_LOCKS_EXCLUDED(mutex_); - void OnConnectionRequestReceived(const std::string &remote_endpoint_id) + void OnConnectionRequestReceived(const std::string& remote_endpoint_id) ABSL_LOCKS_EXCLUDED(mutex_); - void OnConnectionRequestSent(const std::string &remote_endpoint_id) + void OnConnectionRequestSent(const std::string& remote_endpoint_id) ABSL_LOCKS_EXCLUDED(mutex_); - void OnRemoteEndpointAccepted(const std::string &remote_endpoint_id) + void OnRemoteEndpointAccepted(const std::string& remote_endpoint_id) ABSL_LOCKS_EXCLUDED(mutex_); - void OnLocalEndpointAccepted(const std::string &remote_endpoint_id) + void OnLocalEndpointAccepted(const std::string& remote_endpoint_id) ABSL_LOCKS_EXCLUDED(mutex_); - void OnRemoteEndpointRejected(const std::string &remote_endpoint_id) + void OnRemoteEndpointRejected(const std::string& remote_endpoint_id) ABSL_LOCKS_EXCLUDED(mutex_); - void OnLocalEndpointRejected(const std::string &remote_endpoint_id) + void OnLocalEndpointRejected(const std::string& remote_endpoint_id) ABSL_LOCKS_EXCLUDED(mutex_); // Connection attempt @@ -108,39 +105,39 @@ class AnalyticsRecorder { location::nearby::proto::connections::ConnectionAttemptType type, location::nearby::proto::connections::Medium medium, location::nearby::proto::connections::ConnectionAttemptResult result, - absl::Duration duration, const std::string &connection_token, - ConnectionAttemptMetadataParams *connection_attempt_metadata_params) + absl::Duration duration, const std::string& connection_token, + ConnectionAttemptMetadataParams* connection_attempt_metadata_params) ABSL_LOCKS_EXCLUDED(mutex_); // Records an attempt with meta data at establishing an outgoing physical // connection. void OnOutgoingConnectionAttempt( - const std::string &remote_endpoint_id, + const std::string& remote_endpoint_id, location::nearby::proto::connections::ConnectionAttemptType type, location::nearby::proto::connections::Medium medium, location::nearby::proto::connections::ConnectionAttemptResult result, - absl::Duration duration, const std::string &connection_token, - ConnectionAttemptMetadataParams *connection_attempt_metadata_params) + absl::Duration duration, const std::string& connection_token, + ConnectionAttemptMetadataParams* connection_attempt_metadata_params) ABSL_LOCKS_EXCLUDED(mutex_); static std::unique_ptr BuildAdvertisingMetadataParams( bool is_extended_advertisement_supported = false, int connected_ap_frequency = 0, bool is_nfc_available = false, const std::vector - &operation_result_with_mediums = {}); + OperationResultWithMedium>& + operation_result_with_mediums = {}); static std::unique_ptr BuildDiscoveryMetadataParams( bool is_extended_advertisement_supported = false, int connected_ap_frequency = 0, bool is_nfc_available = false, const std::vector - &operation_result_with_mediums = {}); + OperationResultWithMedium>& + operation_result_with_mediums = {}); static std::unique_ptr BuildConnectionAttemptMetadataParams( location::nearby::proto::connections::ConnectionTechnology technology, location::nearby::proto::connections::ConnectionBand band, int frequency, - int try_count, const std::string &network_operator = {}, - const std::string &country_code = {}, bool is_tdls_used = false, + int try_count, const std::string& network_operator = {}, + const std::string& country_code = {}, bool is_tdls_used = false, bool wifi_hotspot_enabled = false, int max_wifi_tx_speed = 0, int max_wifi_rx_speed = 0, int channel_width = -1, location::nearby::proto::connections::OperationResultCode @@ -152,11 +149,11 @@ class AnalyticsRecorder { // Connection establishedSafeDisconnectionResult void OnConnectionEstablished( - const std::string &endpoint_id, + const std::string& endpoint_id, location::nearby::proto::connections::Medium medium, - const std::string &connection_token) ABSL_LOCKS_EXCLUDED(mutex_); + const std::string& connection_token) ABSL_LOCKS_EXCLUDED(mutex_); void OnConnectionClosed( - const std::string &endpoint_id, + const std::string& endpoint_id, location::nearby::proto::connections::Medium medium, location::nearby::proto::connections::DisconnectionReason reason, location::nearby::analytics::proto::ConnectionsLog:: @@ -164,55 +161,55 @@ class AnalyticsRecorder { ABSL_LOCKS_EXCLUDED(mutex_); // Payload - void OnIncomingPayloadStarted(const std::string &endpoint_id, + void OnIncomingPayloadStarted(const std::string& endpoint_id, std::int64_t payload_id, connections::PayloadType type, std::int64_t total_size_bytes) ABSL_LOCKS_EXCLUDED(mutex_); - void OnPayloadChunkReceived(const std::string &endpoint_id, + void OnPayloadChunkReceived(const std::string& endpoint_id, std::int64_t payload_id, std::int64_t chunk_size_bytes) ABSL_LOCKS_EXCLUDED(mutex_); void OnIncomingPayloadDone( - const std::string &endpoint_id, std::int64_t payload_id, + const std::string& endpoint_id, std::int64_t payload_id, location::nearby::proto::connections::PayloadStatus status, location::nearby::proto::connections::OperationResultCode operation_result_code) ABSL_LOCKS_EXCLUDED(mutex_); - void OnOutgoingPayloadStarted(const std::vector &endpoint_ids, + void OnOutgoingPayloadStarted(const std::vector& endpoint_ids, std::int64_t payload_id, connections::PayloadType type, std::int64_t total_size_bytes) ABSL_LOCKS_EXCLUDED(mutex_); - void OnPayloadChunkSent(const std::string &endpoint_id, + void OnPayloadChunkSent(const std::string& endpoint_id, std::int64_t payload_id, std::int64_t chunk_size_bytes) ABSL_LOCKS_EXCLUDED(mutex_); void OnOutgoingPayloadDone( - const std::string &endpoint_id, std::int64_t payload_id, + const std::string& endpoint_id, std::int64_t payload_id, location::nearby::proto::connections::PayloadStatus status, location::nearby::proto::connections::OperationResultCode operation_result_code) ABSL_LOCKS_EXCLUDED(mutex_); // BandwidthUpgrade void OnBandwidthUpgradeStarted( - const std::string &endpoint_id, + const std::string& endpoint_id, location::nearby::proto::connections::Medium from_medium, location::nearby::proto::connections::Medium to_medium, location::nearby::proto::connections::ConnectionAttemptDirection direction, - const std::string &connection_token) ABSL_LOCKS_EXCLUDED(mutex_); + const std::string& connection_token) ABSL_LOCKS_EXCLUDED(mutex_); void OnBandwidthUpgradeError( - const std::string &endpoint_id, + const std::string& endpoint_id, location::nearby::proto::connections::BandwidthUpgradeResult result, location::nearby::proto::connections::BandwidthUpgradeErrorStage error_stage, location::nearby::proto::connections::OperationResultCode operation_result_code) ABSL_LOCKS_EXCLUDED(mutex_); - void OnBandwidthUpgradeSuccess(const std::string &endpoint_id) + void OnBandwidthUpgradeSuccess(const std::string& endpoint_id) ABSL_LOCKS_EXCLUDED(mutex_); // Error Code - void OnErrorCode(const ErrorCodeParams ¶ms); + void OnErrorCode(const ErrorCodeParams& params); // Log the start client session event with start client session logging // resources setup (e.g. client_session_, started_client_session_time_) @@ -238,12 +235,12 @@ class AnalyticsRecorder { class PendingPayload { public: PendingPayload(location::nearby::proto::connections::PayloadType type, - std::int64_t total_size_bytes, bool no_record_time_millis) - : PendingPayload(type, total_size_bytes, no_record_time_millis, + std::int64_t total_size_bytes) + : PendingPayload(type, total_size_bytes, location::nearby::proto::connections:: OperationResultCode::DETAIL_UNKNOWN) {} PendingPayload(location::nearby::proto::connections::PayloadType type, - std::int64_t total_size_bytes, bool no_record_time_millis, + std::int64_t total_size_bytes, location::nearby::proto::connections::OperationResultCode operation_result_code) : start_time_(SystemClock::ElapsedRealtime()), @@ -251,8 +248,7 @@ class AnalyticsRecorder { total_size_bytes_(total_size_bytes), num_bytes_transferred_(0), num_chunks_(0), - operation_result_code_(operation_result_code), - no_record_time_millis_(no_record_time_millis) {} + operation_result_code_(operation_result_code) {} ~PendingPayload() = default; void AddChunk(std::int64_t chunk_size_bytes); @@ -281,31 +277,28 @@ class AnalyticsRecorder { location::nearby::proto::connections::OperationResultCode operation_result_code_ = location::nearby::proto::connections:: OperationResultCode::DETAIL_UNKNOWN; - // For testing only. - bool no_record_time_millis_ = false; }; class LogicalConnection { public: LogicalConnection( location::nearby::proto::connections::Medium initial_medium, - const std::string &connection_token, bool no_record_time_millis) - : no_record_time_millis_(no_record_time_millis) { + const std::string& connection_token) { PhysicalConnectionEstablished(initial_medium, connection_token); } - LogicalConnection(const LogicalConnection &) = delete; - LogicalConnection(LogicalConnection &&other) + LogicalConnection(const LogicalConnection&) = delete; + LogicalConnection(LogicalConnection&& other) : current_medium_(std::move(other.current_medium_)), physical_connections_(std::move(other.physical_connections_)), incoming_payloads_(std::move(other.incoming_payloads_)), outgoing_payloads_(std::move(other.outgoing_payloads_)) {} - LogicalConnection &operator=(const LogicalConnection &) = delete; - LogicalConnection &&operator=(LogicalConnection &&) = delete; + LogicalConnection& operator=(const LogicalConnection&) = delete; + LogicalConnection&& operator=(LogicalConnection&&) = delete; ~LogicalConnection() = default; void PhysicalConnectionEstablished( location::nearby::proto::connections::Medium medium, - const std::string &connection_token); + const std::string& connection_token); void PhysicalConnectionClosed( location::nearby::proto::connections::Medium medium, location::nearby::proto::connections::DisconnectionReason reason, @@ -341,14 +334,14 @@ class AnalyticsRecorder { private: void FinishPhysicalConnection( location::nearby::analytics::proto::ConnectionsLog:: - EstablishedConnection *established_connection, + EstablishedConnection* established_connection, location::nearby::proto::connections::DisconnectionReason reason, location::nearby::analytics::proto::ConnectionsLog:: EstablishedConnection::SafeDisconnectionResult result); std::vector ResolvePendingPayloads( - absl::btree_map> - &pending_payloads, + absl::btree_map>& + pending_payloads, location::nearby::proto::connections::DisconnectionReason reason); location::nearby::proto::connections::OperationResultCode GetPendingPayloadResultCodeFromReason( @@ -364,8 +357,6 @@ class AnalyticsRecorder { incoming_payloads_; absl::btree_map> outgoing_payloads_; - // For testing only. - bool no_record_time_millis_ = false; }; bool CanRecordAnalyticsLocked(absl::string_view method_name) @@ -388,57 +379,57 @@ class AnalyticsRecorder { ABSL_SHARED_LOCKS_REQUIRED(mutex_); void FinishDiscoveryPhaseLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_); bool UpdateAdvertiserConnectionRequestLocked( - location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest - *request) ABSL_SHARED_LOCKS_REQUIRED(mutex_); + location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest* + request) ABSL_SHARED_LOCKS_REQUIRED(mutex_); bool UpdateDiscovererConnectionRequestLocked( - location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest - *request) ABSL_SHARED_LOCKS_REQUIRED(mutex_); + location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest* + request) ABSL_SHARED_LOCKS_REQUIRED(mutex_); bool BothEndpointsRespondedLocked( - location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest - *request) ABSL_SHARED_LOCKS_REQUIRED(mutex_); + location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest* + request) ABSL_SHARED_LOCKS_REQUIRED(mutex_); void LocalEndpointRespondedLocked( - const std::string &remote_endpoint_id, + const std::string& remote_endpoint_id, location::nearby::proto::connections::ConnectionRequestResponse response) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_); void RemoteEndpointRespondedLocked( - const std::string &remote_endpoint_id, + const std::string& remote_endpoint_id, location::nearby::proto::connections::ConnectionRequestResponse response) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_); void MarkConnectionRequestIgnoredLocked( - location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest - *request) ABSL_SHARED_LOCKS_REQUIRED(mutex_); + location::nearby::analytics::proto::ConnectionsLog::ConnectionRequest* + request) ABSL_SHARED_LOCKS_REQUIRED(mutex_); void OnIncomingConnectionAttemptLocked( location::nearby::proto::connections::ConnectionAttemptType type, location::nearby::proto::connections::Medium medium, location::nearby::proto::connections::ConnectionAttemptResult result, - absl::Duration duration, const std::string &connection_token, - ConnectionAttemptMetadataParams *connection_attempt_metadata_params) + absl::Duration duration, const std::string& connection_token, + ConnectionAttemptMetadataParams* connection_attempt_metadata_params) ABSL_SHARED_LOCKS_REQUIRED(mutex_); void OnOutgoingConnectionAttemptLocked( - const std::string &remote_endpoint_id, + const std::string& remote_endpoint_id, location::nearby::proto::connections::ConnectionAttemptType type, location::nearby::proto::connections::Medium medium, location::nearby::proto::connections::ConnectionAttemptResult result, - absl::Duration duration, const std::string &connection_token, - ConnectionAttemptMetadataParams *connection_attempt_metadata_params) + absl::Duration duration, const std::string& connection_token, + ConnectionAttemptMetadataParams* connection_attempt_metadata_params) ABSL_SHARED_LOCKS_REQUIRED(mutex_); bool ConnectionAttemptResultCodeExistedLocked( location::nearby::proto::connections::Medium medium, location::nearby::proto::connections::ConnectionAttemptDirection direction, - const std::string &connection_token, + const std::string& connection_token, location::nearby::proto::connections::ConnectionAttemptType type, location::nearby::proto::connections::OperationResultCode operation_result_code) ABSL_SHARED_LOCKS_REQUIRED(mutex_); bool EraseIfBandwidthUpgradeRecordExistedLocked( - const std::string &endpoint_id, + const std::string& endpoint_id, location::nearby::proto::connections::BandwidthUpgradeResult result, location::nearby::proto::connections::BandwidthUpgradeErrorStage error_stage, location::nearby::proto::connections::OperationResultCode operation_result_code) ABSL_SHARED_LOCKS_REQUIRED(mutex_); void FinishUpgradeAttemptLocked( - const std::string &endpoint_id, + const std::string& endpoint_id, location::nearby::proto::connections::BandwidthUpgradeResult result, location::nearby::proto::connections::BandwidthUpgradeErrorStage error_stage, @@ -449,7 +440,7 @@ class AnalyticsRecorder { int GetLatestUpdateIndexLocked( const std::vector &list) + OperationResultWithMedium>& list) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_); location::nearby::proto::connections::ConnectionsStrategy @@ -459,14 +450,11 @@ class AnalyticsRecorder { // Not owned by AnalyticsRecorder. Pointer must refer to a valid object // that outlives the one constructed. - ::nearby::analytics::EventLogger *event_logger_; + ::nearby::analytics::EventLogger* event_logger_; // Protects all sub-protos reading and writing in ConnectionLog. Mutex mutex_; - // For testing only. - bool no_record_time_millis_ = false; - // ClientSession std::unique_ptr< location::nearby::analytics::proto::ConnectionsLog::ClientSession> diff --git a/connections/implementation/analytics/analytics_recorder_test.cc b/connections/implementation/analytics/analytics_recorder_test.cc index 7b27f385..c431e862 100644 --- a/connections/implementation/analytics/analytics_recorder_test.cc +++ b/connections/implementation/analytics/analytics_recorder_test.cc @@ -34,7 +34,9 @@ #include "internal/platform/error_code_params.h" #include "internal/platform/error_code_recorder.h" #include "internal/platform/exception.h" +#include "internal/platform/medium_environment.h" #include "internal/proto/analytics/connections_log.proto.h" +#include "internal/test/fake_clock.h" #include "proto/connections_enums.proto.h" namespace nearby { @@ -142,13 +144,25 @@ class FakeEventLogger : public MockEventLogger { std::vector logged_event_types_; }; +class AnalyticsRecorderTest : public ::testing::Test { + protected: + void SetUp() override { + MediumEnvironment::Instance().Start({.use_simulated_clock = true}); + } + + void TearDown() override { MediumEnvironment::Instance().Stop(); } + + FakeClock& GetFakeClock() const { + return *MediumEnvironment::Instance().GetSimulatedClock().value(); + } +}; + // Test if session_was_logged_ is reset by checking if LogSession can take // effect again or not. -TEST(AnalyticsRecorderTest, SessionOnlyLoggedOnceWorks) { +TEST_F(AnalyticsRecorderTest, SessionOnlyLoggedOnceWorks) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); analytics_recorder.LogSession(); analytics_recorder.LogSession(); @@ -160,13 +174,12 @@ TEST(AnalyticsRecorderTest, SessionOnlyLoggedOnceWorks) { EXPECT_EQ(event_logger.GetLoggedClientSessionCount(), 1); } -TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedAdvertisingCalls) { +TEST_F(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedAdvertisingCalls) { connections::Strategy strategy = connections::Strategy::kP2pStar; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); ConnectionsLog::OperationResultWithMedium operation_result; operation_result.set_medium(BLUETOOTH); @@ -177,24 +190,31 @@ TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedAdvertisingCalls) { analytics_recorder.BuildAdvertisingMetadataParams(); advertising_metadata_params->operation_result_with_mediums = { operation_result}; + GetFakeClock().FastForward(absl::Milliseconds(50)); analytics_recorder.OnStartAdvertising(strategy, /*mediums=*/{BLE, BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStopAdvertising(); operation_result.set_medium(BLE); advertising_metadata_params->operation_result_with_mediums = { operation_result}; + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnStartAdvertising(strategy, /*mediums=*/{BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 650 strategy_session { + duration_millis: 600 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 100 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -210,6 +230,7 @@ TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedAdvertisingCalls) { stop_reason: CLIENT_STOP_ADVERTISING } advertising_phase { + duration_millis: 300 medium: BLUETOOTH advertising_metadata { supports_extended_ble_advertisements: false @@ -229,13 +250,12 @@ TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedAdvertisingCalls) { (EqualsProto(strategy_session_proto))); } -TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedDiscoveryCalls) { +TEST_F(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedDiscoveryCalls) { connections::Strategy strategy = connections::Strategy::kP2pStar; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); ConnectionsLog::OperationResultWithMedium operation_result; operation_result.set_medium(BLUETOOTH); @@ -253,11 +273,16 @@ TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedDiscoveryCalls) { /*is_extended_advertisement_supported*/ true, /*connected_ap_frequency*/ 1, /*is_nfc_available=*/false, {operation_result, operation_result2}); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartDiscovery(strategy, /*mediums=*/{BLE, BLUETOOTH}, discovery_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnStopDiscovery(); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnEndpointFound(BLUETOOTH); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.OnEndpointFound(BLE); + GetFakeClock().FastForward(absl::Milliseconds(500)); auto discovery_metadata_params2 = analytics_recorder.BuildDiscoveryMetadataParams( @@ -266,20 +291,30 @@ TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedDiscoveryCalls) { {operation_result}); analytics_recorder.OnStartDiscovery(strategy, /*mediums=*/{BLUETOOTH}, discovery_metadata_params2.get()); + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 2100 strategy_session { + duration_millis: 2000 strategy: P2P_STAR role: DISCOVERER discovery_phase { + duration_millis: 200 medium: BLE medium: BLUETOOTH - discovered_endpoint { medium: BLUETOOTH } - discovered_endpoint { medium: BLE } + discovered_endpoint { + medium: BLUETOOTH + latency_millis: 500 + } + discovered_endpoint { + medium: BLE + latency_millis: 900 + } discovery_metadata { supports_extended_ble_advertisements: true connected_ap_frequency: 1 @@ -298,6 +333,7 @@ TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedDiscoveryCalls) { stop_reason: CLIENT_STOP_DISCOVERING } discovery_phase { + duration_millis: 600 medium: BLUETOOTH discovery_metadata { supports_extended_ble_advertisements: true @@ -317,37 +353,49 @@ TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedDiscoveryCalls) { EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, - OneStrategySessionForMultipleRoundsOfDiscoveryAdvertising) { +TEST_F(AnalyticsRecorderTest, + OneStrategySessionForMultipleRoundsOfDiscoveryAdvertising) { connections::Strategy strategy = connections::Strategy::kP2pStar; std::vector mediums = {BLE, BLUETOOTH}; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto advertising_metadata_params = analytics_recorder.BuildAdvertisingMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(strategy, mediums, advertising_metadata_params.get()); auto discovery_metadata_params = analytics_recorder.BuildDiscoveryMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnStartDiscovery(strategy, mediums, discovery_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnStopAdvertising(); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.OnStopDiscovery(); + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.OnStartAdvertising(strategy, mediums, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.OnStopAdvertising(); + GetFakeClock().FastForward(absl::Milliseconds(700)); analytics_recorder.OnStartDiscovery(strategy, mediums, discovery_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(800)); analytics_recorder.OnStopDiscovery(); + GetFakeClock().FastForward(absl::Milliseconds(900)); analytics_recorder.OnStartDiscovery(strategy, mediums, {}); + GetFakeClock().FastForward(absl::Milliseconds(1000)); analytics_recorder.OnStartAdvertising(strategy, mediums, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(1100)); analytics_recorder.OnStopDiscovery(); + GetFakeClock().FastForward(absl::Milliseconds(1200)); analytics_recorder.OnStopAdvertising(); + GetFakeClock().FastForward(absl::Milliseconds(1300)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); @@ -358,11 +406,14 @@ TEST(AnalyticsRecorderTest, ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 9100 strategy_session { + duration_millis: 9000 strategy: P2P_STAR role: ADVERTISER role: DISCOVERER discovery_phase { + duration_millis: 700 medium: BLE medium: BLUETOOTH discovery_metadata { @@ -373,6 +424,7 @@ TEST(AnalyticsRecorderTest, stop_reason: CLIENT_STOP_DISCOVERING } discovery_phase { + duration_millis: 800 medium: BLE medium: BLUETOOTH discovery_metadata { @@ -383,6 +435,7 @@ TEST(AnalyticsRecorderTest, stop_reason: CLIENT_STOP_DISCOVERING } discovery_phase { + duration_millis: 2100 medium: BLE medium: BLUETOOTH discovery_metadata { @@ -393,6 +446,7 @@ TEST(AnalyticsRecorderTest, stop_reason: CLIENT_STOP_DISCOVERING } advertising_phase { + duration_millis: 500 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -403,6 +457,7 @@ TEST(AnalyticsRecorderTest, stop_reason: CLIENT_STOP_ADVERTISING } advertising_phase { + duration_millis: 600 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -413,6 +468,7 @@ TEST(AnalyticsRecorderTest, stop_reason: CLIENT_STOP_ADVERTISING } advertising_phase { + duration_millis: 2300 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -428,7 +484,7 @@ TEST(AnalyticsRecorderTest, EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, AdvertiserConnectionRequestsWorks) { +TEST_F(AnalyticsRecorderTest, AdvertiserConnectionRequestsWorks) { std::string endpoint_id_0 = "endpoint_id_0"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; @@ -436,8 +492,7 @@ TEST(AnalyticsRecorderTest, AdvertiserConnectionRequestsWorks) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); ConnectionsLog::OperationResultWithMedium operation_result; operation_result.set_medium(BLE); @@ -448,34 +503,47 @@ TEST(AnalyticsRecorderTest, AdvertiserConnectionRequestsWorks) { analytics_recorder.BuildAdvertisingMetadataParams(); advertising_metadata_params->operation_result_with_mediums = { operation_result}; + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnConnectionRequestReceived(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0); - + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.OnConnectionRequestReceived(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(700)); analytics_recorder.OnRemoteEndpointRejected(endpoint_id_1); - + GetFakeClock().FastForward(absl::Milliseconds(800)); analytics_recorder.OnConnectionRequestReceived(endpoint_id_2); + GetFakeClock().FastForward(absl::Milliseconds(900)); analytics_recorder.OnLocalEndpointRejected(endpoint_id_2); + GetFakeClock().FastForward(absl::Milliseconds(1000)); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_2); - + GetFakeClock().FastForward(absl::Milliseconds(1100)); analytics_recorder.OnConnectionRequestReceived(endpoint_id_3); + GetFakeClock().FastForward(absl::Milliseconds(1200)); analytics_recorder.OnLocalEndpointRejected(endpoint_id_3); + GetFakeClock().FastForward(absl::Milliseconds(1300)); analytics_recorder.OnRemoteEndpointRejected(endpoint_id_3); - + GetFakeClock().FastForward(absl::Milliseconds(1400)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 10500 strategy_session { + duration_millis: 10400 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 10400 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -490,18 +558,26 @@ TEST(AnalyticsRecorderTest, AdvertiserConnectionRequestsWorks) { } stop_reason: FINISH_SESSION_STOP_ADVERTISING received_connection_request { + duration_millis: 700 + request_delay_millis: 200 local_response: ACCEPTED remote_response: ACCEPTED } received_connection_request { + duration_millis: 1300 + request_delay_millis: 1400 local_response: ACCEPTED remote_response: REJECTED } received_connection_request { + duration_millis: 1900 + request_delay_millis: 3500 local_response: REJECTED remote_response: ACCEPTED } received_connection_request { + duration_millis: 2500 + request_delay_millis: 6500 local_response: REJECTED remote_response: REJECTED } @@ -512,7 +588,7 @@ TEST(AnalyticsRecorderTest, AdvertiserConnectionRequestsWorks) { EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, DiscoveryConnectionRequestsWorks) { +TEST_F(AnalyticsRecorderTest, DiscoveryConnectionRequestsWorks) { std::string endpoint_id_0 = "endpoint_id_0"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; @@ -520,8 +596,7 @@ TEST(AnalyticsRecorderTest, DiscoveryConnectionRequestsWorks) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); ConnectionsLog::OperationResultWithMedium operation_result; operation_result.set_medium(BLUETOOTH); @@ -531,35 +606,49 @@ TEST(AnalyticsRecorderTest, DiscoveryConnectionRequestsWorks) { auto discovery_metadata_params = analytics_recorder.BuildDiscoveryMetadataParams(); discovery_metadata_params->operation_result_with_mediums = {operation_result}; + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, discovery_metadata_params.get()); - + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnConnectionRequestSent(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0); - + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.OnConnectionRequestSent(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(700)); analytics_recorder.OnRemoteEndpointRejected(endpoint_id_1); - + GetFakeClock().FastForward(absl::Milliseconds(800)); analytics_recorder.OnConnectionRequestSent(endpoint_id_2); + GetFakeClock().FastForward(absl::Milliseconds(900)); analytics_recorder.OnLocalEndpointRejected(endpoint_id_2); + GetFakeClock().FastForward(absl::Milliseconds(1000)); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_2); + GetFakeClock().FastForward(absl::Milliseconds(1100)); analytics_recorder.OnConnectionRequestSent(endpoint_id_3); + GetFakeClock().FastForward(absl::Milliseconds(1200)); analytics_recorder.OnLocalEndpointRejected(endpoint_id_3); + GetFakeClock().FastForward(absl::Milliseconds(1300)); analytics_recorder.OnRemoteEndpointRejected(endpoint_id_3); + GetFakeClock().FastForward(absl::Milliseconds(1400)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 10500 strategy_session { + duration_millis: 10400 strategy: P2P_STAR role: DISCOVERER discovery_phase { + duration_millis: 10400 medium: BLE medium: BLUETOOTH discovery_metadata { @@ -574,18 +663,26 @@ TEST(AnalyticsRecorderTest, DiscoveryConnectionRequestsWorks) { } stop_reason: FINISH_SESSION_STOP_DISCOVERING sent_connection_request { + duration_millis: 700 + request_delay_millis: 200 local_response: ACCEPTED remote_response: ACCEPTED } sent_connection_request { + duration_millis: 1300 + request_delay_millis: 1400 local_response: ACCEPTED remote_response: REJECTED } sent_connection_request { + duration_millis: 1900 + request_delay_millis: 3500 local_response: REJECTED remote_response: ACCEPTED } sent_connection_request { + duration_millis: 2500 + request_delay_millis: 6500 local_response: REJECTED remote_response: REJECTED } @@ -596,16 +693,15 @@ TEST(AnalyticsRecorderTest, DiscoveryConnectionRequestsWorks) { EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, - AdvertiserUnfinishedConnectionRequestsIncludedAsIgnored) { +TEST_F(AnalyticsRecorderTest, + AdvertiserUnfinishedConnectionRequestsIncludedAsIgnored) { std::string endpoint_id_0 = "endpoint_id_0"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); ConnectionsLog::OperationResultWithMedium operation_result; operation_result.set_medium(BLUETOOTH); @@ -616,29 +712,39 @@ TEST(AnalyticsRecorderTest, analytics_recorder.BuildAdvertisingMetadataParams(); advertising_metadata_params->operation_result_with_mediums = { operation_result}; + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, advertising_metadata_params.get()); // Ignored by local. + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnConnectionRequestReceived(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(400)); // Ignored by remote. analytics_recorder.OnConnectionRequestReceived(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(600)); // Ignored by both. analytics_recorder.OnConnectionRequestReceived(endpoint_id_2); + GetFakeClock().FastForward(absl::Milliseconds(700)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 2800 strategy_session { + duration_millis: 2700 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 2700 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -653,14 +759,20 @@ TEST(AnalyticsRecorderTest, } stop_reason: FINISH_SESSION_STOP_ADVERTISING received_connection_request { + duration_millis: 2500 + request_delay_millis: 200 local_response: IGNORED remote_response: ACCEPTED } received_connection_request { + duration_millis: 1800 + request_delay_millis: 900 local_response: ACCEPTED remote_response: IGNORED } received_connection_request { + duration_millis: 700 + request_delay_millis: 2000 local_response: IGNORED remote_response: IGNORED } @@ -671,16 +783,15 @@ TEST(AnalyticsRecorderTest, EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, - DiscovererUnfinishedConnectionRequestsIncludedAsIgnored) { +TEST_F(AnalyticsRecorderTest, + DiscovererUnfinishedConnectionRequestsIncludedAsIgnored) { std::string endpoint_id_0 = "endpoint_id_0"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); ConnectionsLog::OperationResultWithMedium operation_result; operation_result.set_medium(BLUETOOTH); @@ -690,30 +801,40 @@ TEST(AnalyticsRecorderTest, auto discovery_metadata_params = analytics_recorder.BuildDiscoveryMetadataParams(); discovery_metadata_params->operation_result_with_mediums = {operation_result}; + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, discovery_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); // Ignored by local. analytics_recorder.OnConnectionRequestSent(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(400)); // Ignored by remote. analytics_recorder.OnConnectionRequestSent(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(600)); // Ignored by both. analytics_recorder.OnConnectionRequestSent(endpoint_id_2); + GetFakeClock().FastForward(absl::Milliseconds(700)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 2800 strategy_session { + duration_millis: 2700 strategy: P2P_STAR role: DISCOVERER discovery_phase { + duration_millis: 2700 medium: BLE medium: BLUETOOTH discovery_metadata { @@ -728,14 +849,20 @@ TEST(AnalyticsRecorderTest, } stop_reason: FINISH_SESSION_STOP_DISCOVERING sent_connection_request { + duration_millis: 2500 + request_delay_millis: 200 local_response: IGNORED remote_response: ACCEPTED } sent_connection_request { + duration_millis: 1800 + request_delay_millis: 900 local_response: ACCEPTED remote_response: IGNORED } sent_connection_request { + duration_millis: 700 + request_delay_millis: 2000 local_response: IGNORED remote_response: IGNORED } @@ -746,11 +873,10 @@ TEST(AnalyticsRecorderTest, EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, SuccessfulIncomingConnectionAttempt) { +TEST_F(AnalyticsRecorderTest, SuccessfulIncomingConnectionAttempt) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); ConnectionsLog::OperationResultWithMedium operation_result; operation_result.set_medium(BLUETOOTH); @@ -761,6 +887,7 @@ TEST(AnalyticsRecorderTest, SuccessfulIncomingConnectionAttempt) { analytics_recorder.BuildAdvertisingMetadataParams(); advertising_metadata_params->operation_result_with_mediums = { operation_result}; + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, advertising_metadata_params.get()); @@ -769,20 +896,26 @@ TEST(AnalyticsRecorderTest, SuccessfulIncomingConnectionAttempt) { std::make_unique(); connections_attempt_metadata_params->operation_result_code = OperationResultCode::DETAIL_SUCCESS; + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnIncomingConnectionAttempt( INITIAL, BLUETOOTH, RESULT_SUCCESS, absl::Duration{}, /*connection_token=*/"", connections_attempt_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnStopAdvertising(); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 1000 strategy_session { + duration_millis: 900 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 500 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -798,6 +931,7 @@ TEST(AnalyticsRecorderTest, SuccessfulIncomingConnectionAttempt) { } } connection_attempt { + duration_millis: 0 type: INITIAL direction: INCOMING medium: BLUETOOTH @@ -827,14 +961,13 @@ TEST(AnalyticsRecorderTest, SuccessfulIncomingConnectionAttempt) { EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, - FailedConnectionAttemptUpdatesConnectionRequestNotSent) { +TEST_F(AnalyticsRecorderTest, + FailedConnectionAttemptUpdatesConnectionRequestNotSent) { std::string endpoint_id = "endpoint_id"; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto connections_attempt_metadata_params = analytics_recorder.BuildConnectionAttemptMetadataParams( @@ -849,23 +982,30 @@ TEST(AnalyticsRecorderTest, OperationResultCode::CONNECTIVITY_BT_CLIENT_SOCKET_CREATION_FAILURE); auto discovery_metadata_params = analytics_recorder.BuildDiscoveryMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, discovery_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnConnectionRequestSent(endpoint_id); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnOutgoingConnectionAttempt( endpoint_id, INITIAL, BLUETOOTH, RESULT_ERROR, absl::Duration{}, /*connection_token=*/"", connections_attempt_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 1000 strategy_session { + duration_millis: 900 strategy: P2P_STAR role: DISCOVERER discovery_phase { + duration_millis: 900 medium: BLE medium: BLUETOOTH discovery_metadata { @@ -875,11 +1015,14 @@ TEST(AnalyticsRecorderTest, } stop_reason: FINISH_SESSION_STOP_DISCOVERING sent_connection_request { + duration_millis: 300 + request_delay_millis: 200 local_response: NOT_SENT remote_response: NOT_SENT } } connection_attempt { + duration_millis: 0 type: INITIAL direction: OUTGOING medium: BLUETOOTH @@ -909,37 +1052,45 @@ TEST(AnalyticsRecorderTest, EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, UnfinishedEstablishedConnectionsAddedAsUnfinished) { +TEST_F(AnalyticsRecorderTest, + UnfinishedEstablishedConnectionsAddedAsUnfinished) { std::string endpoint_id = "endpoint_id"; std::string connection_token = "connection_token"; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto advertising_metadata_params = analytics_recorder.BuildAdvertisingMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnConnectionEstablished(endpoint_id, BLUETOOTH, connection_token); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnConnectionClosed( endpoint_id, BLUETOOTH, UPGRADED, ConnectionsLog::EstablishedConnection::UNKNOWN_SAFE_DISCONNECTION_RESULT); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.OnConnectionEstablished(endpoint_id, WIFI_LAN, connection_token); + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 1500 strategy_session { + duration_millis: 1400 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 1400 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -950,6 +1101,7 @@ TEST(AnalyticsRecorderTest, UnfinishedEstablishedConnectionsAddedAsUnfinished) { stop_reason: FINISH_SESSION_STOP_ADVERTISING } established_connection { + duration_millis: 300 medium: BLUETOOTH disconnection_reason: UPGRADED connection_token: "connection_token" @@ -960,6 +1112,7 @@ TEST(AnalyticsRecorderTest, UnfinishedEstablishedConnectionsAddedAsUnfinished) { } } established_connection { + duration_millis: 500 medium: WIFI_LAN disconnection_reason: UNFINISHED connection_token: "connection_token" @@ -975,50 +1128,65 @@ TEST(AnalyticsRecorderTest, UnfinishedEstablishedConnectionsAddedAsUnfinished) { EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, OutgoingPayloadUpgraded) { +TEST_F(AnalyticsRecorderTest, OutgoingPayloadUpgraded) { std::string endpoint_id = "endpoint_id"; std::int64_t payload_id = 123456789; std::string connection_token = "connection_token"; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto advertising_metadata_params = analytics_recorder.BuildAdvertisingMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnConnectionEstablished(endpoint_id, BLUETOOTH, connection_token); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnOutgoingPayloadStarted( {endpoint_id}, payload_id, connections::PayloadType::kFile, 50); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.OnPayloadChunkSent(endpoint_id, payload_id, 10); + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.OnPayloadChunkSent(endpoint_id, payload_id, 10); + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.OnConnectionClosed( endpoint_id, BLUETOOTH, UPGRADED, ConnectionsLog::EstablishedConnection::SAFE_DISCONNECTION); + GetFakeClock().FastForward(absl::Milliseconds(700)); analytics_recorder.OnConnectionEstablished(endpoint_id, WIFI_LAN, connection_token); + GetFakeClock().FastForward(absl::Milliseconds(800)); analytics_recorder.OnPayloadChunkSent(endpoint_id, payload_id, 10); + GetFakeClock().FastForward(absl::Milliseconds(900)); analytics_recorder.OnPayloadChunkSent(endpoint_id, payload_id, 10); + GetFakeClock().FastForward(absl::Milliseconds(1000)); analytics_recorder.OnPayloadChunkSent(endpoint_id, payload_id, 10); + GetFakeClock().FastForward(absl::Milliseconds(1100)); analytics_recorder.OnOutgoingPayloadDone(endpoint_id, payload_id, SUCCESS, OperationResultCode::DETAIL_SUCCESS); + GetFakeClock().FastForward(absl::Milliseconds(1200)); analytics_recorder.OnConnectionClosed( endpoint_id, WIFI_LAN, LOCAL_DISCONNECTION, ConnectionsLog::EstablishedConnection::SAFE_DISCONNECTION); + GetFakeClock().FastForward(absl::Milliseconds(1300)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 9100 strategy_session { + duration_millis: 9000 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 9000 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -1029,8 +1197,10 @@ TEST(AnalyticsRecorderTest, OutgoingPayloadUpgraded) { stop_reason: FINISH_SESSION_STOP_ADVERTISING } established_connection { + duration_millis: 1800 medium: BLUETOOTH sent_payload { + duration_millis: 1500 type: FILE total_size_bytes: 50 num_bytes_transferred: 20 @@ -1050,8 +1220,10 @@ TEST(AnalyticsRecorderTest, OutgoingPayloadUpgraded) { } } established_connection { + duration_millis: 5000 medium: WIFI_LAN sent_payload { + duration_millis: 4500 type: FILE total_size_bytes: 50 num_bytes_transferred: 30 @@ -1076,7 +1248,7 @@ TEST(AnalyticsRecorderTest, OutgoingPayloadUpgraded) { EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) { +TEST_F(AnalyticsRecorderTest, UpgradeAttemptWorks) { std::string endpoint_id = "endpoint_id"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; @@ -1084,39 +1256,48 @@ TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto advertising_metadata_params = analytics_recorder.BuildAdvertisingMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnBandwidthUpgradeStarted(endpoint_id, BLE, WIFI_LAN, INCOMING, connection_token); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnBandwidthUpgradeStarted( endpoint_id_1, BLUETOOTH, WIFI_LAN, INCOMING, connection_token); // Error to upgrade. + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.OnBandwidthUpgradeError( endpoint_id, WIFI_LAN_MEDIUM_ERROR, WIFI_LAN_SOCKET_CREATION, OperationResultCode::CONNECTIVITY_WIFI_LAN_INVALID_CREDENTIAL); // Success to upgrade. + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.OnBandwidthUpgradeSuccess(endpoint_id_1); // Upgrade is unfinished. + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.OnBandwidthUpgradeStarted( endpoint_id_2, BLUETOOTH, WIFI_LAN, INCOMING, connection_token); + GetFakeClock().FastForward(absl::Milliseconds(700)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 2800 strategy_session { + duration_millis: 2700 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 2700 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -1127,6 +1308,7 @@ TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) { stop_reason: FINISH_SESSION_STOP_ADVERTISING } upgrade_attempt { + duration_millis: 700 direction: INCOMING from_medium: BLE to_medium: WIFI_LAN @@ -1139,6 +1321,7 @@ TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) { } } upgrade_attempt { + duration_millis: 900 direction: INCOMING from_medium: BLUETOOTH to_medium: WIFI_LAN @@ -1151,6 +1334,7 @@ TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) { } } upgrade_attempt { + duration_millis: 700 direction: INCOMING from_medium: BLUETOOTH to_medium: WIFI_LAN @@ -1168,7 +1352,7 @@ TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) { EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, StartListeningForIncomingConnectionsWorks) { +TEST_F(AnalyticsRecorderTest, StartListeningForIncomingConnectionsWorks) { std::string endpoint_id = "endpoint_id"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; @@ -1176,34 +1360,42 @@ TEST(AnalyticsRecorderTest, StartListeningForIncomingConnectionsWorks) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartedIncomingConnectionListening( connections::Strategy::kP2pStar); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnBandwidthUpgradeStarted(endpoint_id, BLE, WIFI_LAN, INCOMING, connection_token); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnBandwidthUpgradeStarted( endpoint_id_1, BLUETOOTH, WIFI_LAN, INCOMING, connection_token); + GetFakeClock().FastForward(absl::Milliseconds(400)); // Error to upgrade. analytics_recorder.OnBandwidthUpgradeError( endpoint_id, WIFI_LAN_MEDIUM_ERROR, WIFI_LAN_SOCKET_CREATION, OperationResultCode::CONNECTIVITY_WIFI_LAN_INVALID_CREDENTIAL); + GetFakeClock().FastForward(absl::Milliseconds(500)); // Success to upgrade. analytics_recorder.OnBandwidthUpgradeSuccess(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.LogSession(); // ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 2100 strategy_session { + duration_millis: 2000 strategy: P2P_STAR role: ADVERTISER upgrade_attempt { direction: INCOMING + duration_millis: 700 from_medium: BLE to_medium: WIFI_LAN upgrade_result: WIFI_LAN_MEDIUM_ERROR @@ -1216,6 +1408,7 @@ TEST(AnalyticsRecorderTest, StartListeningForIncomingConnectionsWorks) { } upgrade_attempt { direction: INCOMING + duration_millis: 900 from_medium: BLUETOOTH to_medium: WIFI_LAN upgrade_result: UPGRADE_RESULT_SUCCESS @@ -1232,14 +1425,14 @@ TEST(AnalyticsRecorderTest, StartListeningForIncomingConnectionsWorks) { EqualsProto(strategy_session_proto)); } -TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectly) { +TEST_F(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectly) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto discovery_metadata_params = analytics_recorder.BuildDiscoveryMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, /*mediums=*/{WEB_RTC}, discovery_metadata_params.get()); @@ -1247,7 +1440,9 @@ TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectly) { ErrorCodeParams error_code_params = ErrorCodeRecorder::BuildErrorCodeParams( WEB_RTC, DISCONNECT, DISCONNECT_NETWORK_FAILED, TACHYON_SEND_MESSAGE_STATUS_EXCEPTION, "", "connection_token"); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnErrorCode(error_code_params); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1263,14 +1458,15 @@ TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectly) { EXPECT_THAT(event_logger.GetErrorCode(), EqualsProto(error_code_proto)); } -TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectlyForUnknownDescription) { +TEST_F(AnalyticsRecorderTest, + SetErrorCodeFieldsCorrectlyForUnknownDescription) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto discovery_metadata_params = analytics_recorder.BuildDiscoveryMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, /*mediums=*/{BLUETOOTH}, discovery_metadata_params.get()); @@ -1281,7 +1477,9 @@ TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectlyForUnknownDescription) { error_code_params.event = START_DISCOVERING; error_code_params.start_discovering_error = START_EXTENDED_DISCOVERING_FAILED; error_code_params.connection_token = "connection_token"; + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnErrorCode(error_code_params); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1297,14 +1495,14 @@ TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectlyForUnknownDescription) { EXPECT_THAT(event_logger.GetErrorCode(), EqualsProto(error_code_proto)); } -TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectlyForCommonError) { +TEST_F(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectlyForCommonError) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto discovery_metadata_params = analytics_recorder.BuildDiscoveryMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, /*mediums=*/{BLUETOOTH}, discovery_metadata_params.get()); @@ -1312,7 +1510,9 @@ TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectlyForCommonError) { ErrorCodeParams error_code_params = ErrorCodeRecorder::BuildErrorCodeParams( BLUETOOTH, START_DISCOVERING, INVALID_PARAMETER, NULL_BLUETOOTH_DEVICE_NAME, "", "connection_token"); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnErrorCode(error_code_params); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1328,12 +1528,12 @@ TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectlyForCommonError) { EXPECT_THAT(event_logger.GetErrorCode(), EqualsProto(error_code_proto)); } -TEST(AnalyticsRecorderTest, CheckIfSessionWasLogged) { +TEST_F(AnalyticsRecorderTest, CheckIfSessionWasLogged) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); + GetFakeClock().FastForward(absl::Milliseconds(100)); // LogSession to count down client_session_done_latch. analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1341,15 +1541,14 @@ TEST(AnalyticsRecorderTest, CheckIfSessionWasLogged) { EXPECT_TRUE(analytics_recorder.IsSessionLogged()); } -TEST(AnalyticsRecorderTest, ConstructAnalyticsRecorder) { +TEST_F(AnalyticsRecorderTest, ConstructAnalyticsRecorder) { CountDownLatch client_session_done_latch(0); CountDownLatch start_client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch, &start_client_session_done_latch); // Call the constructor to count down the session_done_latch. - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); ASSERT_TRUE(start_client_session_done_latch.Await(kDefaultTimeout).result()); std::vector event_types = event_logger.GetLoggedEventTypes(); @@ -1357,16 +1556,16 @@ TEST(AnalyticsRecorderTest, ConstructAnalyticsRecorder) { EXPECT_THAT(event_types, Contains(START_CLIENT_SESSION).Times(1)); } -TEST(AnalyticsRecorderTest, - StartClientSessionOnlyLoggedOnceWorksAfterAnalyticsRecorderIsConstructed) { +TEST_F( + AnalyticsRecorderTest, + StartClientSessionOnlyLoggedOnceWorksAfterAnalyticsRecorderIsConstructed) { CountDownLatch client_session_done_latch(0); CountDownLatch start_client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch, &start_client_session_done_latch); // Call the constructor to count down the start_client_session_done_latch. - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); ASSERT_TRUE(start_client_session_done_latch.Await(kDefaultTimeout).result()); // Log start client session once. @@ -1387,16 +1586,15 @@ TEST(AnalyticsRecorderTest, Contains(START_CLIENT_SESSION).Times(1)); } -TEST(AnalyticsRecorderTest, - CanLogStartClientSessionOnceAgainAfterSessionWasLogged) { +TEST_F(AnalyticsRecorderTest, + CanLogStartClientSessionOnceAgainAfterSessionWasLogged) { CountDownLatch client_session_done_latch(0); CountDownLatch start_client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch, &start_client_session_done_latch); // Call the constructor to count down the start_client_session_done_latch. - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); ASSERT_TRUE(start_client_session_done_latch.Await(kDefaultTimeout).result()); // Log start client session once. @@ -1427,23 +1625,27 @@ TEST(AnalyticsRecorderTest, Contains(START_CLIENT_SESSION).Times(2)); } -TEST(AnalyticsRecorderTest, - ClearcIncomingConnectionRequestsAfterSessionWasLogged) { +TEST_F(AnalyticsRecorderTest, + ClearcIncomingConnectionRequestsAfterSessionWasLogged) { std::string endpoint_id_0 = "endpoint_id_0"; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto advertising_metadata_params = analytics_recorder.BuildAdvertisingMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnConnectionRequestReceived(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(500)); // LogSession analytics_recorder.LogSession(); // call ResetClientSessionLoggingResouces @@ -1451,10 +1653,13 @@ TEST(AnalyticsRecorderTest, ConnectionsLog::ClientSession strategy_session_proto1 = ParseTextProtoOrDie(R"pb( + duration_millis: 1500 strategy_session { + duration_millis: 1400 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 1400 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -1464,6 +1669,8 @@ TEST(AnalyticsRecorderTest, } stop_reason: FINISH_SESSION_STOP_ADVERTISING received_connection_request { + duration_millis: 700 + request_delay_millis: 200 local_response: ACCEPTED remote_response: ACCEPTED } @@ -1477,6 +1684,7 @@ TEST(AnalyticsRecorderTest, CountDownLatch new_start_client_session_done_latch(1); event_logger.SetStartClientSessionDoneLatchPtr( &new_start_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.LogStartSession(); ASSERT_TRUE( new_start_client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1485,9 +1693,13 @@ TEST(AnalyticsRecorderTest, CountDownLatch new_client_session_done_latch(1); event_logger.SetClientSessionDoneLatch(new_client_session_done_latch); std::string endpoint_id_1 = "endpoint_id_1"; + GetFakeClock().FastForward(absl::Milliseconds(700)); analytics_recorder.OnConnectionRequestReceived(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(800)); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(900)); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(1000)); analytics_recorder.LogSession(); ASSERT_TRUE(new_client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1497,10 +1709,13 @@ TEST(AnalyticsRecorderTest, // received_connection_request) will append to the strategy_session) ConnectionsLog::ClientSession strategy_session_proto2 = ParseTextProtoOrDie( R"pb( + duration_millis: 0 strategy_session { + duration_millis: 0 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 0 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -1509,11 +1724,14 @@ TEST(AnalyticsRecorderTest, supports_nfc_technology: false } received_connection_request { + duration_millis: 0 + request_delay_millis: 0 local_response: ACCEPTED remote_response: ACCEPTED } } advertising_phase { + duration_millis: 0 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -1522,10 +1740,14 @@ TEST(AnalyticsRecorderTest, supports_nfc_technology: false } received_connection_request { + duration_millis: 0 + request_delay_millis: 0 local_response: ACCEPTED remote_response: ACCEPTED } received_connection_request { + duration_millis: 0 + request_delay_millis: 0 local_response: ACCEPTED remote_response: ACCEPTED } @@ -1535,24 +1757,28 @@ TEST(AnalyticsRecorderTest, Not(EqualsProto(strategy_session_proto2))); } -TEST(AnalyticsRecorderTest, - ClearcOutgoingConnectionRequestsAfterSessionWasLogged) { +TEST_F(AnalyticsRecorderTest, + ClearcOutgoingConnectionRequestsAfterSessionWasLogged) { std::string endpoint_id_0 = "endpoint_id_0"; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto discovery_metadata_params = analytics_recorder.BuildDiscoveryMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, discovery_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnConnectionRequestSent(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0); + GetFakeClock().FastForward(absl::Milliseconds(500)); // LogSession analytics_recorder.LogSession(); // call ResetClientSessionLoggingResouces @@ -1560,10 +1786,13 @@ TEST(AnalyticsRecorderTest, ConnectionsLog::ClientSession strategy_session_proto1 = ParseTextProtoOrDie(R"pb( + duration_millis: 1500 strategy_session { + duration_millis: 1400 strategy: P2P_STAR role: DISCOVERER discovery_phase { + duration_millis: 1400 medium: BLE medium: BLUETOOTH discovery_metadata { @@ -1573,6 +1802,8 @@ TEST(AnalyticsRecorderTest, } stop_reason: FINISH_SESSION_STOP_DISCOVERING sent_connection_request { + duration_millis: 700 + request_delay_millis: 200 local_response: ACCEPTED remote_response: ACCEPTED } @@ -1594,9 +1825,13 @@ TEST(AnalyticsRecorderTest, CountDownLatch new_client_session_done_latch(1); event_logger.SetClientSessionDoneLatch(new_client_session_done_latch); std::string endpoint_id_1 = "endpoint_id_1"; + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.OnConnectionRequestSent(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(700)); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(800)); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_1); + GetFakeClock().FastForward(absl::Milliseconds(900)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1606,10 +1841,13 @@ TEST(AnalyticsRecorderTest, // sent_connection_request) will append to the strategy_session) ConnectionsLog::ClientSession strategy_session_proto2 = ParseTextProtoOrDie(R"pb( + duration_millis: 0 strategy_session { + duration_millis: 0 strategy: P2P_STAR role: DISCOVERER discovery_phase { + duration_millis: 0 medium: BLE medium: BLUETOOTH discovery_metadata { @@ -1618,11 +1856,14 @@ TEST(AnalyticsRecorderTest, supports_nfc_technology: false } sent_connection_request { + duration_millis: 0 + request_delay_millis: 0 local_response: ACCEPTED remote_response: ACCEPTED } } discovery_phase { + duration_millis: 0 medium: BLE medium: BLUETOOTH discovery_metadata { @@ -1631,10 +1872,14 @@ TEST(AnalyticsRecorderTest, supports_nfc_technology: false } sent_connection_request { + duration_millis: 0 + request_delay_millis: 0 local_response: ACCEPTED remote_response: ACCEPTED } sent_connection_request { + duration_millis: 0 + request_delay_millis: 0 local_response: ACCEPTED remote_response: ACCEPTED } @@ -1644,7 +1889,7 @@ TEST(AnalyticsRecorderTest, Not(EqualsProto(strategy_session_proto2))); } -TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { +TEST_F(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { connections::Strategy strategy = connections::Strategy::kP2pStar; std::vector mediums = {BLE, BLUETOOTH}; std::string endpoint_id = "endpoint_id"; @@ -1652,26 +1897,31 @@ TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto advertising_metadata_params = analytics_recorder.BuildAdvertisingMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(strategy, mediums, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnConnectionEstablished(endpoint_id, BLUETOOTH, connection_token); + GetFakeClock().FastForward(absl::Milliseconds(300)); // LogSession analytics_recorder.LogSession(); // call ResetClientSessionLoggingResouces ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto1 = ParseTextProtoOrDie(R"pb( + duration_millis: 600 strategy_session { + duration_millis: 500 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 500 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -1682,6 +1932,7 @@ TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { stop_reason: FINISH_SESSION_STOP_ADVERTISING } established_connection { + duration_millis: 300 medium: BLUETOOTH disconnection_reason: UNFINISHED connection_token: "connection_token" @@ -1700,6 +1951,7 @@ TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { CountDownLatch new_start_client_session_done_latch(1); event_logger.SetStartClientSessionDoneLatchPtr( &new_start_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.LogStartSession(); ASSERT_TRUE( new_start_client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1707,6 +1959,7 @@ TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { // LogSession again CountDownLatch new_client_session_done_latch(1); event_logger.SetClientSessionDoneLatch(new_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1716,10 +1969,13 @@ TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { // established_connection) will stay there. ConnectionsLog::ClientSession strategy_session_proto2 = ParseTextProtoOrDie(R"pb( + duration_millis: 0 strategy_session { + duration_millis: 0 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 0 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -1729,6 +1985,7 @@ TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { } } advertising_phase { + duration_millis: 0 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -1738,6 +1995,7 @@ TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { } } established_connection { + duration_millis: 0 medium: BLUETOOTH disconnection_reason: UNFINISHED connection_token: "connection_token" @@ -1753,8 +2011,8 @@ TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { Not(EqualsProto(strategy_session_proto2))); } -TEST(AnalyticsRecorderTest, - ClearBandwidthUpgradeAttemptsAfterSessionWasLogged) { +TEST_F(AnalyticsRecorderTest, + ClearBandwidthUpgradeAttemptsAfterSessionWasLogged) { std::string endpoint_id = "endpoint_id"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; @@ -1762,31 +2020,37 @@ TEST(AnalyticsRecorderTest, CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto advertising_metadata_params = analytics_recorder.BuildAdvertisingMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnBandwidthUpgradeStarted(endpoint_id, BLE, WIFI_LAN, INCOMING, connection_token); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnBandwidthUpgradeStarted( endpoint_id_1, BLUETOOTH, WIFI_LAN, INCOMING, connection_token); // - Error to upgrade. + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.OnBandwidthUpgradeError( endpoint_id, WIFI_LAN_MEDIUM_ERROR, WIFI_LAN_SOCKET_CREATION, OperationResultCode::CONNECTIVITY_WIFI_LAN_INVALID_CREDENTIAL); // - Success to upgrade. + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.OnBandwidthUpgradeSuccess(endpoint_id_1); // - Upgrade is unfinished. + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.OnBandwidthUpgradeStarted( endpoint_id_2, BLUETOOTH, WIFI_LAN, INCOMING, connection_token); + GetFakeClock().FastForward(absl::Milliseconds(700)); // LogSession analytics_recorder.LogSession(); // call ResetClientSessionLoggingResouces ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1796,10 +2060,13 @@ TEST(AnalyticsRecorderTest, // bandwidth_upgrade_attempts_) will stay there. ConnectionsLog::ClientSession strategy_session_proto1 = ParseTextProtoOrDie(R"pb( + duration_millis: 2800 strategy_session { + duration_millis: 2700 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 2700 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -1811,6 +2078,7 @@ TEST(AnalyticsRecorderTest, } upgrade_attempt { direction: INCOMING + duration_millis: 700 from_medium: BLE to_medium: WIFI_LAN upgrade_result: WIFI_LAN_MEDIUM_ERROR @@ -1823,6 +2091,7 @@ TEST(AnalyticsRecorderTest, } upgrade_attempt { direction: INCOMING + duration_millis: 900 from_medium: BLUETOOTH to_medium: WIFI_LAN upgrade_result: UPGRADE_RESULT_SUCCESS @@ -1835,6 +2104,7 @@ TEST(AnalyticsRecorderTest, } upgrade_attempt { direction: INCOMING + duration_millis: 700 from_medium: BLUETOOTH to_medium: WIFI_LAN upgrade_result: UNFINISHED_ERROR @@ -1853,6 +2123,7 @@ TEST(AnalyticsRecorderTest, CountDownLatch new_start_client_session_done_latch(1); event_logger.SetStartClientSessionDoneLatchPtr( &new_start_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(800)); analytics_recorder.LogStartSession(); ASSERT_TRUE( new_start_client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1860,15 +2131,19 @@ TEST(AnalyticsRecorderTest, // LogSession again CountDownLatch new_client_session_done_latch(1); event_logger.SetClientSessionDoneLatch(new_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(900)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto2 = ParseTextProtoOrDie(R"pb( + duration_millis: 0 strategy_session { + duration_millis: 0 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 0 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -1878,6 +2153,7 @@ TEST(AnalyticsRecorderTest, } } advertising_phase { + duration_millis: 0 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -1930,22 +2206,24 @@ TEST(AnalyticsRecorderTest, // Test if current_strategy_ is reset by checking if the same strategy would // be logged for different client sessions or not. If yes, it should be logged. // Otherwise, not. -TEST(AnalyticsRecorderTest, - CanLogSeparateStartStrategySessionForSameStrategyAfterSessionWasLogged) { +TEST_F(AnalyticsRecorderTest, + CanLogSeparateStartStrategySessionForSameStrategyAfterSessionWasLogged) { connections::Strategy strategy = connections::Strategy::kP2pStar; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto advertising_metadata_params = analytics_recorder.BuildAdvertisingMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, /*mediums=*/{BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnStopAdvertising(); + GetFakeClock().FastForward(absl::Milliseconds(300)); // LogSession analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1959,6 +2237,7 @@ TEST(AnalyticsRecorderTest, CountDownLatch new_start_client_session_done_latch(1); event_logger.SetStartClientSessionDoneLatchPtr( &new_start_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.LogStartSession(); ASSERT_TRUE( new_start_client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1967,9 +2246,12 @@ TEST(AnalyticsRecorderTest, CountDownLatch new_client_session_done_latch(1); event_logger.SetClientSessionDoneLatch(new_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.OnStartAdvertising(strategy, /*mediums=*/{BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.OnStopAdvertising(); + GetFakeClock().FastForward(absl::Milliseconds(700)); analytics_recorder.LogSession(); ASSERT_TRUE(new_client_session_done_latch.Await(kDefaultTimeout).result()); @@ -1980,32 +2262,36 @@ TEST(AnalyticsRecorderTest, // Test if current_strategy_session_ is reset. If not, the same strategy session // proto will be logged. -TEST(AnalyticsRecorderTest, - NotLogSameStrategySessionProtoAfterSessionWasLogged) { +TEST_F(AnalyticsRecorderTest, + NotLogSameStrategySessionProtoAfterSessionWasLogged) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); // Via OnStartAdvertising, current_strategy_session_is set in // UpdateStrategySessionLocked. auto advertising_metadata_params = analytics_recorder.BuildAdvertisingMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnStopAdvertising(); - + GetFakeClock().FastForward(absl::Milliseconds(300)); // LogSession analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 600 strategy_session { + duration_millis: 500 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 200 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -2024,6 +2310,7 @@ TEST(AnalyticsRecorderTest, CountDownLatch new_start_client_session_done_latch(1); event_logger.SetStartClientSessionDoneLatchPtr( &new_start_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.LogStartSession(); ASSERT_TRUE( new_start_client_session_done_latch.Await(kDefaultTimeout).result()); @@ -2033,6 +2320,7 @@ TEST(AnalyticsRecorderTest, // strategy_session_proto will be logged. CountDownLatch new_client_session_done_latch(1); event_logger.SetClientSessionDoneLatch(new_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.LogSession(); ASSERT_TRUE(new_client_session_done_latch.Await(kDefaultTimeout).result()); @@ -2041,20 +2329,22 @@ TEST(AnalyticsRecorderTest, } // Test if current_advertising_phase_ is reset. -TEST(AnalyticsRecorderTest, - NotLogDuplicateAdvertisingPhaseAfterSessionWasLogged) { +TEST_F(AnalyticsRecorderTest, + NotLogDuplicateAdvertisingPhaseAfterSessionWasLogged) { CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto advertising_metadata_params = analytics_recorder.BuildAdvertisingMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising( connections::Strategy::kP2pStar, /*mediums=*/{BLUETOOTH}, advertising_metadata_params.get()); // set current_advertising_phase_ + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnStopAdvertising(); + GetFakeClock().FastForward(absl::Milliseconds(300)); // LogSession analytics_recorder.LogSession(); @@ -2062,10 +2352,13 @@ TEST(AnalyticsRecorderTest, ConnectionsLog::ClientSession strategy_session_proto1 = ParseTextProtoOrDie(R"pb( + duration_millis: 600 strategy_session { + duration_millis: 500 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 200 medium: BLUETOOTH advertising_metadata { supports_extended_ble_advertisements: false @@ -2083,6 +2376,7 @@ TEST(AnalyticsRecorderTest, CountDownLatch new_start_client_session_done_latch(1); event_logger.SetStartClientSessionDoneLatchPtr( &new_start_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.LogStartSession(); ASSERT_TRUE( new_start_client_session_done_latch.Await(kDefaultTimeout).result()); @@ -2093,15 +2387,19 @@ TEST(AnalyticsRecorderTest, // be logged. CountDownLatch new_client_session_done_latch(1); event_logger.SetClientSessionDoneLatch(new_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto2 = ParseTextProtoOrDie(R"pb( + duration_millis: 0 strategy_session { + duration_millis: 0 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 0 medium: BLUETOOTH advertising_metadata { supports_extended_ble_advertisements: false @@ -2110,6 +2408,7 @@ TEST(AnalyticsRecorderTest, } } advertising_phase { + duration_millis: 0 medium: BLUETOOTH advertising_metadata { supports_extended_ble_advertisements: false @@ -2123,37 +2422,45 @@ TEST(AnalyticsRecorderTest, } // Test if current_discovery_phase_ is reset. -TEST(AnalyticsRecorderTest, - NotLogDuplicateDiscoveryPhaseAfterSessionWasLogged) { +TEST_F(AnalyticsRecorderTest, + NotLogDuplicateDiscoveryPhaseAfterSessionWasLogged) { connections::Strategy strategy = connections::Strategy::kP2pStar; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); auto discovery_metadata_params = analytics_recorder.BuildDiscoveryMetadataParams( /*is_extended_advertisement_supported*/ true, /*connected_ap_frequency*/ 1, /*is_nfc_available=*/false); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartDiscovery( strategy, {BLUETOOTH}, discovery_metadata_params.get()); // set current_discovery_phase_ + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnStopDiscovery(); + GetFakeClock().FastForward(absl::Milliseconds(300)); analytics_recorder.OnEndpointFound(BLUETOOTH); - + GetFakeClock().FastForward(absl::Milliseconds(400)); // LogSession analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto1 = ParseTextProtoOrDie(R"pb( + duration_millis: 1000 strategy_session { + duration_millis: 900 strategy: P2P_STAR role: DISCOVERER discovery_phase { + duration_millis: 200 medium: BLUETOOTH - discovered_endpoint { medium: BLUETOOTH } + discovered_endpoint { + medium: BLUETOOTH + latency_millis: 500 + } discovery_metadata { supports_extended_ble_advertisements: true connected_ap_frequency: 1 @@ -2170,6 +2477,7 @@ TEST(AnalyticsRecorderTest, CountDownLatch new_start_client_session_done_latch(1); event_logger.SetStartClientSessionDoneLatchPtr( &new_start_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.LogStartSession(); ASSERT_TRUE( new_start_client_session_done_latch.Await(kDefaultTimeout).result()); @@ -2180,15 +2488,19 @@ TEST(AnalyticsRecorderTest, // logged. CountDownLatch new_client_session_done_latch(1); event_logger.SetClientSessionDoneLatch(new_client_session_done_latch); + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); ConnectionsLog::ClientSession strategy_session_proto2 = ParseTextProtoOrDie(R"pb( + duration_millis: 0 strategy_session { + duration_millis: 0 strategy: P2P_STAR role: DISCOVERER discovery_phase { + duration_millis: 0 medium: BLUETOOTH discovered_endpoint { medium: BLUETOOTH } discovery_metadata { @@ -2199,6 +2511,7 @@ TEST(AnalyticsRecorderTest, stop_reason: CLIENT_STOP_DISCOVERING } discovery_phase { + duration_millis: 0 medium: BLUETOOTH discovery_metadata { supports_extended_ble_advertisements: true @@ -2211,23 +2524,25 @@ TEST(AnalyticsRecorderTest, Not(EqualsProto(strategy_session_proto2))); } -TEST(AnalyticsRecorderOnConnectionClosedTest, - NotAddNewConnectionWithoutCallingOnStartAdvertising) { +TEST_F(AnalyticsRecorderTest, + NotAddNewConnectionWithoutCallingOnStartAdvertising) { std::string endpoint_id = "endpoint_id"; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder(&event_logger, - /*no_record_time_millis=*/true); + AnalyticsRecorder analytics_recorder(&event_logger); // via OnStartAdvertising, current_strategy_session_ is set in // UpdateStrategySessionLocked. auto advertising_metadata_params = analytics_recorder.BuildAdvertisingMetadataParams(); + GetFakeClock().FastForward(absl::Milliseconds(100)); analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, /*mediums=*/{BLE, BLUETOOTH}, advertising_metadata_params.get()); + GetFakeClock().FastForward(absl::Milliseconds(200)); analytics_recorder.OnStopAdvertising(); + GetFakeClock().FastForward(absl::Milliseconds(300)); // LogSession analytics_recorder.LogSession(); @@ -2235,10 +2550,13 @@ TEST(AnalyticsRecorderOnConnectionClosedTest, ConnectionsLog::ClientSession strategy_session_proto = ParseTextProtoOrDie(R"pb( + duration_millis: 600 strategy_session { + duration_millis: 500 strategy: P2P_STAR role: ADVERTISER advertising_phase { + duration_millis: 200 medium: BLE medium: BLUETOOTH advertising_metadata { @@ -2255,12 +2573,14 @@ TEST(AnalyticsRecorderOnConnectionClosedTest, // Without calling OnStartAdvertising won't create new // current_strategy_session_. + GetFakeClock().FastForward(absl::Milliseconds(400)); analytics_recorder.OnConnectionEstablished(endpoint_id, BLUETOOTH, /*connection_token=*/""); + GetFakeClock().FastForward(absl::Milliseconds(500)); analytics_recorder.OnConnectionClosed( endpoint_id, BLUETOOTH, UPGRADED, ConnectionsLog::EstablishedConnection::SAFE_DISCONNECTION); - + GetFakeClock().FastForward(absl::Milliseconds(600)); analytics_recorder.LogSession(); // The proto won't change. diff --git a/internal/platform/implementation/system_clock.h b/internal/platform/implementation/system_clock.h index ad7597f4..e9486c3b 100644 --- a/internal/platform/implementation/system_clock.h +++ b/internal/platform/implementation/system_clock.h @@ -15,7 +15,7 @@ #ifndef PLATFORM_API_SYSTEM_CLOCK_H_ #define PLATFORM_API_SYSTEM_CLOCK_H_ -#include "absl/time/clock.h" +#include "absl/time/time.h" #include "internal/platform/exception.h" namespace nearby { diff --git a/internal/platform/implementation/windows/system_clock.cc b/internal/platform/implementation/windows/system_clock.cc index 6d9acbc0..3d0b42bc 100644 --- a/internal/platform/implementation/windows/system_clock.cc +++ b/internal/platform/implementation/windows/system_clock.cc @@ -16,6 +16,8 @@ #define PLATFORM_IMPL_WINDOWS_SYSTEM_CLOCK_H_ #include "internal/platform/implementation/system_clock.h" +#include "absl/time/clock.h" +#include "absl/time/time.h" namespace nearby {