diff --git a/connections/implementation/analytics/BUILD b/connections/implementation/analytics/BUILD index b27f01c3..63989a25 100644 --- a/connections/implementation/analytics/BUILD +++ b/connections/implementation/analytics/BUILD @@ -30,15 +30,19 @@ cc_library( deps = [ "//connections:core_types", "//internal/analytics:event_logger", - "//internal/platform:base", "//internal/platform:error_code_recorder", "//internal/platform:logging", "//internal/platform:types", + "//internal/platform/implementation:types", "//internal/proto/analytics:connections_log_cc_proto", "//proto:connections_enums_cc_proto", "@com_google_absl//absl/algorithm:container", + "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:btree", "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/meta:type_traits", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", "@com_google_absl//absl/time", ], ) @@ -53,6 +57,8 @@ cc_test( shard_count = 16, deps = [ ":analytics", + "//internal/analytics:event_logger", + "//internal/platform:base", "//internal/platform:comm", "//internal/platform:error_code_recorder", "//internal/platform:logging", @@ -61,9 +67,9 @@ cc_test( "//internal/proto/analytics:connections_log_cc_proto", "//net/proto2/contrib/parse_proto:parse_text_proto", "//proto:connections_enums_cc_proto", + "//third_party/protobuf:protobuf_lite", "@com_github_protobuf_matchers//protobuf-matchers", "@com_google_absl//absl/time", "@com_google_googletest//:gtest_main", - "@com_google_protobuf//:protobuf", ], ) diff --git a/connections/implementation/analytics/analytics_recorder.cc b/connections/implementation/analytics/analytics_recorder.cc index e2bc8d57..3fa691e5 100644 --- a/connections/implementation/analytics/analytics_recorder.cc +++ b/connections/implementation/analytics/analytics_recorder.cc @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2022-2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,19 +15,24 @@ #include "connections/implementation/analytics/analytics_recorder.h" #include +#include #include #include -#include +#include #include #include #include #include "absl/algorithm/container.h" +#include "absl/container/btree_map.h" +#include "absl/strings/string_view.h" #include "absl/time/time.h" #include "internal/analytics/event_logger.h" +#include "internal/platform/error_code_params.h" +#include "internal/platform/implementation/system_clock.h" #include "internal/platform/logging.h" #include "internal/platform/mutex_lock.h" -#include "internal/platform/system_clock.h" +#include "internal/platform/single_thread_executor.h" #include "internal/proto/analytics/connections_log.pb.h" #include "proto/connections_enums.pb.h" diff --git a/connections/implementation/analytics/analytics_recorder.h b/connections/implementation/analytics/analytics_recorder.h index 8418964d..ca8e114b 100644 --- a/connections/implementation/analytics/analytics_recorder.h +++ b/connections/implementation/analytics/analytics_recorder.h @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2022-2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,17 +15,22 @@ #ifndef ANALYTICS_ANALYTICS_RECORDER_H_ #define ANALYTICS_ANALYTICS_RECORDER_H_ +#include #include #include #include +#include +#include "absl/base/thread_annotations.h" #include "absl/container/btree_map.h" +#include "absl/strings/string_view.h" #include "absl/time/time.h" #include "connections/implementation/analytics/connection_attempt_metadata_params.h" -#include "connections/payload.h" +#include "connections/payload_type.h" #include "connections/strategy.h" #include "internal/analytics/event_logger.h" #include "internal/platform/error_code_params.h" +#include "internal/platform/implementation/system_clock.h" #include "internal/platform/mutex.h" #include "internal/platform/single_thread_executor.h" #include "internal/proto/analytics/connections_log.pb.h" diff --git a/connections/implementation/analytics/analytics_recorder_test.cc b/connections/implementation/analytics/analytics_recorder_test.cc index ecfefb37..cda1bd5b 100644 --- a/connections/implementation/analytics/analytics_recorder_test.cc +++ b/connections/implementation/analytics/analytics_recorder_test.cc @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2022-2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ #include "connections/implementation/analytics/analytics_recorder.h" +#include + +#include +#include #include -#include +#include #include "net/proto2/contrib/parse_proto/parse_text_proto.h" -#include "google/protobuf/message_lite.h" #include "gmock/gmock.h" #include "protobuf-matchers/protocol-buffer-matchers.h" #include "gtest/gtest.h" #include "absl/time/time.h" -#include "connections/implementation/analytics/connection_attempt_metadata_params.h" +#include "internal/analytics/event_logger.h" #include "internal/platform/count_down_latch.h" #include "internal/platform/error_code_params.h" #include "internal/platform/error_code_recorder.h" -#include "internal/platform/logging.h" -#include "internal/proto/analytics/connections_log.pb.h" -#include "proto/connections_enums.pb.h" +#include "internal/platform/exception.h" +#include "internal/proto/analytics/connections_log.proto.h" +#include "proto/connections_enums.proto.h" +#include "third_party/protobuf/message_lite.h" namespace nearby { namespace analytics { @@ -159,84 +163,96 @@ TEST(AnalyticsRecorderTest, SessionOnlyLoggedOnceWorks) { TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedAdvertisingCalls) { 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); - analytics_recorder.OnStartAdvertising(strategy, mediums); + analytics_recorder.OnStartAdvertising(strategy, /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnStopAdvertising(); - analytics_recorder.OnStartAdvertising(strategy, {BLUETOOTH}); + analytics_recorder.OnStartAdvertising(strategy, /*mediums=*/{BLUETOOTH}); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - advertising_phase < - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + advertising_phase < + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, SetFieldsCorrectlyForNestedDiscoveryCalls) { 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); - analytics_recorder.OnStartDiscovery(strategy, mediums, true, 1, false); + analytics_recorder.OnStartDiscovery( + strategy, /*mediums=*/{BLE, BLUETOOTH}, + /*is_extended_advertisement_supported=*/true, + /*connected_ap_frequency=*/1, /*is_nfc_available=*/false); analytics_recorder.OnStopDiscovery(); analytics_recorder.OnEndpointFound(BLUETOOTH); analytics_recorder.OnEndpointFound(BLE); - analytics_recorder.OnStartDiscovery(strategy, {BLUETOOTH}, true, 1, false); + analytics_recorder.OnStartDiscovery( + strategy, /*mediums=*/{BLUETOOTH}, + /*is_extended_advertisement_supported=*/true, + /*connected_ap_frequency=*/1, /*is_nfc_available=*/false); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: DISCOVERER - discovery_phase < - medium: BLE - medium: BLUETOOTH - discovered_endpoint < medium: BLUETOOTH > - discovered_endpoint < medium: BLE > - discovery_metadata < - supports_extended_ble_advertisements: true - connected_ap_frequency: 1 - supports_nfc_technology: false - > - > - discovery_phase < - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: true - connected_ap_frequency: 1 - supports_nfc_technology: false - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: DISCOVERER + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovered_endpoint < medium: BLUETOOTH > + discovered_endpoint < medium: BLE > + discovery_metadata < + supports_extended_ble_advertisements: true + connected_ap_frequency: 1 + supports_nfc_technology: false + > + > + discovery_phase < + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: true + connected_ap_frequency: 1 + supports_nfc_technology: false + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, @@ -268,71 +284,73 @@ TEST(AnalyticsRecorderTest, EXPECT_THAT(event_types, Contains(START_STRATEGY_SESSION).Times(1)); EXPECT_THAT(event_types, Contains(STOP_STRATEGY_SESSION).Times(1)); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - role: DISCOVERER - discovery_phase < - medium: BLE - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - discovery_phase < - medium: BLE - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - discovery_phase < - medium: BLE - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + role: DISCOVERER + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, AdvertiserConnectionRequestsWorks) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; std::string endpoint_id_0 = "endpoint_id_0"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; @@ -342,7 +360,8 @@ TEST(AnalyticsRecorderTest, AdvertiserConnectionRequestsWorks) { FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartAdvertising(strategy, mediums); + analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnConnectionRequestReceived(endpoint_id_0); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_0); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0); @@ -362,41 +381,43 @@ TEST(AnalyticsRecorderTest, AdvertiserConnectionRequestsWorks) { analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - received_connection_request < - local_response: ACCEPTED - remote_response: ACCEPTED - > - received_connection_request < - local_response: ACCEPTED - remote_response: REJECTED - > - received_connection_request < - local_response: REJECTED - remote_response: ACCEPTED - > - received_connection_request < - local_response: REJECTED - remote_response: REJECTED - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + received_connection_request < + local_response: ACCEPTED + remote_response: ACCEPTED + > + received_connection_request < + local_response: ACCEPTED + remote_response: REJECTED + > + received_connection_request < + local_response: REJECTED + remote_response: ACCEPTED + > + received_connection_request < + local_response: REJECTED + remote_response: REJECTED + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, DiscoveryConnectionRequestsWorks) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; std::string endpoint_id_0 = "endpoint_id_0"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; @@ -406,7 +427,8 @@ TEST(AnalyticsRecorderTest, DiscoveryConnectionRequestsWorks) { FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartDiscovery(strategy, mediums); + analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnConnectionRequestSent(endpoint_id_0); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_0); @@ -427,42 +449,44 @@ TEST(AnalyticsRecorderTest, DiscoveryConnectionRequestsWorks) { analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: DISCOVERER - discovery_phase < - medium: BLE - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - sent_connection_request < - local_response: ACCEPTED - remote_response: ACCEPTED - > - sent_connection_request < - local_response: ACCEPTED - remote_response: REJECTED - > - sent_connection_request < - local_response: REJECTED - remote_response: ACCEPTED - > - sent_connection_request < - local_response: REJECTED - remote_response: REJECTED - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: DISCOVERER + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + sent_connection_request < + local_response: ACCEPTED + remote_response: ACCEPTED + > + sent_connection_request < + local_response: ACCEPTED + remote_response: REJECTED + > + sent_connection_request < + local_response: REJECTED + remote_response: ACCEPTED + > + sent_connection_request < + local_response: REJECTED + remote_response: REJECTED + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, AdvertiserUnfinishedConnectionRequestsIncludedAsIgnored) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; std::string endpoint_id_0 = "endpoint_id_0"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; @@ -471,7 +495,8 @@ TEST(AnalyticsRecorderTest, FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartAdvertising(strategy, mediums); + analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); // Ignored by local. analytics_recorder.OnConnectionRequestReceived(endpoint_id_0); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0); @@ -486,38 +511,40 @@ TEST(AnalyticsRecorderTest, analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - received_connection_request < - local_response: IGNORED - remote_response: ACCEPTED - > - received_connection_request < - local_response: ACCEPTED - remote_response: IGNORED - > - received_connection_request < - local_response: IGNORED - remote_response: IGNORED - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + received_connection_request < + local_response: IGNORED + remote_response: ACCEPTED + > + received_connection_request < + local_response: ACCEPTED + remote_response: IGNORED + > + received_connection_request < + local_response: IGNORED + remote_response: IGNORED + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, DiscovererUnfinishedConnectionRequestsIncludedAsIgnored) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; std::string endpoint_id_0 = "endpoint_id_0"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; @@ -526,7 +553,8 @@ TEST(AnalyticsRecorderTest, FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartDiscovery(strategy, mediums); + analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); // Ignored by local. analytics_recorder.OnConnectionRequestSent(endpoint_id_0); @@ -542,95 +570,96 @@ TEST(AnalyticsRecorderTest, analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: DISCOVERER - discovery_phase < - medium: BLE - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - sent_connection_request < - local_response: IGNORED - remote_response: ACCEPTED - > - sent_connection_request < - local_response: ACCEPTED - remote_response: IGNORED - > - sent_connection_request < - local_response: IGNORED - remote_response: IGNORED - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: DISCOVERER + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + sent_connection_request < + local_response: IGNORED + remote_response: ACCEPTED + > + sent_connection_request < + local_response: ACCEPTED + remote_response: IGNORED + > + sent_connection_request < + local_response: IGNORED + remote_response: IGNORED + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, SuccessfulIncomingConnectionAttempt) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; - std::string endpoint_id = "endpoint_id"; - std::string connection_token = ""; - CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder{&event_logger}; + AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartAdvertising(strategy, mediums); + analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnIncomingConnectionAttempt( - INITIAL, BLUETOOTH, RESULT_SUCCESS, absl::Duration{}, connection_token, - nullptr); + INITIAL, BLUETOOTH, RESULT_SUCCESS, absl::Duration{}, + /*connection_token=*/"", nullptr); analytics_recorder.OnStopAdvertising(); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - connection_attempt < - type: INITIAL - direction: INCOMING - medium: BLUETOOTH - attempt_result: RESULT_SUCCESS - connection_token: "" - connection_attempt_metadata < - technology: CONNECTION_TECHNOLOGY_UNKNOWN_TECHNOLOGY - band: CONNECTION_BAND_UNKNOWN_BAND - frequency: -1 - network_operator: "" - country_code: "" - is_tdls_used: false - try_counts: 0 - wifi_hotspot_status: false - max_tx_speed: 0 - max_rx_speed: 0 - wifi_channel_width: -1 - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + connection_attempt < + type: INITIAL + direction: INCOMING + medium: BLUETOOTH + attempt_result: RESULT_SUCCESS + connection_token: "" + connection_attempt_metadata < + technology: CONNECTION_TECHNOLOGY_UNKNOWN_TECHNOLOGY + band: CONNECTION_BAND_UNKNOWN_BAND + frequency: -1 + network_operator: "" + country_code: "" + is_tdls_used: false + try_counts: 0 + wifi_hotspot_status: false + max_tx_speed: 0 + max_rx_speed: 0 + wifi_channel_width: -1 + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, FailedConnectionAttemptUpdatesConnectionRequestNotSent) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; std::string endpoint_id = "endpoint_id"; - std::string connection_token = ""; CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); @@ -646,58 +675,61 @@ TEST(AnalyticsRecorderTest, /*country_code*/ {}, /*is_tdls_used*/ false, /*wifi_hotspot_enabled*/ false, /*max_wifi_tx_speed*/ 0, /*max_wifi_rx_speed*/ 0, /*channel_width*/ 0); - analytics_recorder.OnStartDiscovery(strategy, mediums); + analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnConnectionRequestSent(endpoint_id); analytics_recorder.OnOutgoingConnectionAttempt( endpoint_id, INITIAL, BLUETOOTH, RESULT_ERROR, absl::Duration{}, - connection_token, connections_attempt_metadata_params.get()); + /*connection_token=*/"", connections_attempt_metadata_params.get()); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: DISCOVERER - discovery_phase < - medium: BLE - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - sent_connection_request < - local_response: NOT_SENT - remote_response: NOT_SENT - > - > - connection_attempt < - type: INITIAL - direction: OUTGOING - medium: BLUETOOTH - attempt_result: RESULT_ERROR - connection_token: "" - connection_attempt_metadata < - technology: CONNECTION_TECHNOLOGY_HOTSPOT_LOCALONLY - band: CONNECTION_BAND_WIFI_BAND_6GHZ - frequency: 2400 - network_operator: "" - country_code: "" - is_tdls_used: false - try_counts: 0 - wifi_hotspot_status: false - max_tx_speed: 0 - max_rx_speed: 0 - wifi_channel_width: 0 - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: DISCOVERER + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + sent_connection_request < + local_response: NOT_SENT + remote_response: NOT_SENT + > + > + connection_attempt < + type: INITIAL + direction: OUTGOING + medium: BLUETOOTH + attempt_result: RESULT_ERROR + connection_token: "" + connection_attempt_metadata < + technology: CONNECTION_TECHNOLOGY_HOTSPOT_LOCALONLY + band: CONNECTION_BAND_WIFI_BAND_6GHZ + frequency: 2400 + network_operator: "" + country_code: "" + is_tdls_used: false + try_counts: 0 + wifi_hotspot_status: false + max_tx_speed: 0 + max_rx_speed: 0 + wifi_channel_width: 0 + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, UnfinishedEstablishedConnectionsAddedAsUnfinished) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; std::string endpoint_id = "endpoint_id"; std::string connection_token = "connection_token"; @@ -705,7 +737,8 @@ TEST(AnalyticsRecorderTest, UnfinishedEstablishedConnectionsAddedAsUnfinished) { FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartAdvertising(strategy, mediums); + analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnConnectionEstablished(endpoint_id, BLUETOOTH, connection_token); analytics_recorder.OnConnectionClosed(endpoint_id, BLUETOOTH, UPGRADED); @@ -715,35 +748,37 @@ TEST(AnalyticsRecorderTest, UnfinishedEstablishedConnectionsAddedAsUnfinished) { analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - established_connection < - medium: BLUETOOTH - disconnection_reason: UPGRADED - connection_token: "connection_token" - > - established_connection < - medium: WIFI_LAN - disconnection_reason: UNFINISHED - connection_token: "connection_token" - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + established_connection < + medium: BLUETOOTH + disconnection_reason: UPGRADED + connection_token: "connection_token" + > + established_connection < + medium: WIFI_LAN + disconnection_reason: UNFINISHED + connection_token: "connection_token" + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, OutgoingPayloadUpgraded) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; std::string endpoint_id = "endpoint_id"; std::int64_t payload_id = 123456789; std::string connection_token = "connection_token"; @@ -752,7 +787,8 @@ TEST(AnalyticsRecorderTest, OutgoingPayloadUpgraded) { FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartAdvertising(strategy, mediums); + analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnConnectionEstablished(endpoint_id, BLUETOOTH, connection_token); analytics_recorder.OnOutgoingPayloadStarted( @@ -772,49 +808,51 @@ TEST(AnalyticsRecorderTest, OutgoingPayloadUpgraded) { analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - established_connection < - medium: BLUETOOTH - sent_payload < - type: FILE - total_size_bytes: 50 - num_bytes_transferred: 20 - num_chunks: 2 - status: MOVED_TO_NEW_MEDIUM - > - disconnection_reason: UPGRADED - connection_token: "connection_token" - > - established_connection < - medium: WIFI_LAN - sent_payload < - type: FILE - total_size_bytes: 50 - num_bytes_transferred: 30 - num_chunks: 3 - status: SUCCESS - > - disconnection_reason: LOCAL_DISCONNECTION - connection_token: "connection_token" - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + established_connection < + medium: BLUETOOTH + sent_payload < + type: FILE + total_size_bytes: 50 + num_bytes_transferred: 20 + num_chunks: 2 + status: MOVED_TO_NEW_MEDIUM + > + disconnection_reason: UPGRADED + connection_token: "connection_token" + > + established_connection < + medium: WIFI_LAN + sent_payload < + type: FILE + total_size_bytes: 50 + num_bytes_transferred: 30 + num_chunks: 3 + status: SUCCESS + > + disconnection_reason: LOCAL_DISCONNECTION + connection_token: "connection_token" + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; std::string endpoint_id = "endpoint_id"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; @@ -824,7 +862,8 @@ TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) { FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartAdvertising(strategy, mediums); + analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnBandwidthUpgradeStarted(endpoint_id, BLE, WIFI_LAN, INCOMING, connection_token); @@ -843,128 +882,132 @@ TEST(AnalyticsRecorderTest, UpgradeAttemptWorks) { analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - upgrade_attempt < - direction: INCOMING - from_medium: BLE - to_medium: WIFI_LAN - upgrade_result: WIFI_LAN_MEDIUM_ERROR - error_stage: WIFI_LAN_SOCKET_CREATION - connection_token: "connection_token" - > - upgrade_attempt < - direction: INCOMING - from_medium: BLUETOOTH - to_medium: WIFI_LAN - upgrade_result: UPGRADE_RESULT_SUCCESS - error_stage: UPGRADE_SUCCESS - connection_token: "connection_token" - > - upgrade_attempt { - direction: INCOMING - from_medium: BLUETOOTH - to_medium: WIFI_LAN - upgrade_result: UNFINISHED_ERROR - error_stage: UPGRADE_UNFINISHED - connection_token: "connection_token" - } - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + upgrade_attempt < + direction: INCOMING + from_medium: BLE + to_medium: WIFI_LAN + upgrade_result: WIFI_LAN_MEDIUM_ERROR + error_stage: WIFI_LAN_SOCKET_CREATION + connection_token: "connection_token" + > + upgrade_attempt < + direction: INCOMING + from_medium: BLUETOOTH + to_medium: WIFI_LAN + upgrade_result: UPGRADE_RESULT_SUCCESS + error_stage: UPGRADE_SUCCESS + connection_token: "connection_token" + > + upgrade_attempt { + direction: INCOMING + from_medium: BLUETOOTH + to_medium: WIFI_LAN + upgrade_result: UNFINISHED_ERROR + error_stage: UPGRADE_UNFINISHED + connection_token: "connection_token" + } + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto))); } TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectly) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {WEB_RTC}; - std::string connection_token = "connection_token"; - CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartDiscovery(strategy, mediums); + analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, + /*mediums=*/{WEB_RTC}); ErrorCodeParams error_code_params = ErrorCodeRecorder::BuildErrorCodeParams( WEB_RTC, DISCONNECT, DISCONNECT_NETWORK_FAILED, - TACHYON_SEND_MESSAGE_STATUS_EXCEPTION, "", connection_token); + TACHYON_SEND_MESSAGE_STATUS_EXCEPTION, "", "connection_token"); analytics_recorder.OnErrorCode(error_code_params); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetErrorCode(), Partially(EqualsProto(R"pb( - medium: WEB_RTC - event: DISCONNECT - description: TACHYON_SEND_MESSAGE_STATUS_EXCEPTION - disconnect_error: DISCONNECT_NETWORK_FAILED - connection_token: "connection_token" - )pb"))); + ConnectionsLog::ErrorCode error_code_proto = ParseTextProtoOrDie(R"pb( + medium: WEB_RTC + event: DISCONNECT + description: TACHYON_SEND_MESSAGE_STATUS_EXCEPTION + disconnect_error: DISCONNECT_NETWORK_FAILED + connection_token: "connection_token" + )pb"); + + EXPECT_THAT(event_logger.GetErrorCode(), + Partially(EqualsProto(error_code_proto))); } TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectlyForUnknownDescription) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLUETOOTH}; - std::string connection_token = "connection_token"; - CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartDiscovery(strategy, mediums); + analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, + /*mediums=*/{BLUETOOTH}); ErrorCodeParams error_code_params; // Skip setting error_code_params.description error_code_params.medium = BLUETOOTH; error_code_params.event = START_DISCOVERING; error_code_params.start_discovering_error = START_EXTENDED_DISCOVERING_FAILED; - error_code_params.connection_token = connection_token; + error_code_params.connection_token = "connection_token"; analytics_recorder.OnErrorCode(error_code_params); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetErrorCode(), Partially(EqualsProto(R"pb( - medium: BLUETOOTH - event: START_DISCOVERING - description: UNKNOWN - start_discovering_error: START_EXTENDED_DISCOVERING_FAILED - connection_token: "connection_token" - )pb"))); + ConnectionsLog::ErrorCode error_code_proto = ParseTextProtoOrDie(R"pb( + medium: BLUETOOTH + event: START_DISCOVERING + description: UNKNOWN + start_discovering_error: START_EXTENDED_DISCOVERING_FAILED + connection_token: "connection_token" + )pb"); + + EXPECT_THAT(event_logger.GetErrorCode(), + Partially(EqualsProto(error_code_proto))); } TEST(AnalyticsRecorderTest, SetErrorCodeFieldsCorrectlyForCommonError) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLUETOOTH}; - std::string connection_token = "connection_token"; - CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartDiscovery(strategy, mediums); + analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, + /*mediums=*/{BLUETOOTH}); ErrorCodeParams error_code_params = ErrorCodeRecorder::BuildErrorCodeParams( BLUETOOTH, START_DISCOVERING, INVALID_PARAMETER, - NULL_BLUETOOTH_DEVICE_NAME, "", connection_token); + NULL_BLUETOOTH_DEVICE_NAME, "", "connection_token"); analytics_recorder.OnErrorCode(error_code_params); analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetErrorCode(), Partially(EqualsProto(R"pb( - medium: BLUETOOTH - event: START_DISCOVERING - description: NULL_BLUETOOTH_DEVICE_NAME - common_error: INVALID_PARAMETER - connection_token: "connection_token" - )pb"))); + ConnectionsLog::ErrorCode error_code_proto = ParseTextProtoOrDie(R"pb( + medium: BLUETOOTH + event: START_DISCOVERING + description: NULL_BLUETOOTH_DEVICE_NAME + common_error: INVALID_PARAMETER + connection_token: "connection_token" + )pb"); + + EXPECT_THAT(event_logger.GetErrorCode(), + Partially(EqualsProto(error_code_proto))); } TEST(AnalyticsRecorderTest, CheckIfSessionWasLogged) { @@ -1064,15 +1107,14 @@ TEST(AnalyticsRecorderTest, TEST(AnalyticsRecorderTest, ClearcIncomingConnectionRequestsAfterSessionWasLogged) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; 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); - analytics_recorder.OnStartAdvertising(strategy, mediums); + analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnConnectionRequestReceived(endpoint_id_0); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_0); analytics_recorder.OnRemoteEndpointAccepted(endpoint_id_0); @@ -1081,24 +1123,28 @@ TEST(AnalyticsRecorderTest, analytics_recorder.LogSession(); // call ResetClientSessionLoggingResouces ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - received_connection_request < - local_response: ACCEPTED - remote_response: ACCEPTED - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto1 = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + received_connection_request < + local_response: ACCEPTED + remote_response: ACCEPTED + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto1))); // LogStartSession CountDownLatch new_start_client_session_done_latch(1); @@ -1122,55 +1168,56 @@ TEST(AnalyticsRecorderTest, // - if the current_strategy_session_ and current_advertising_phase_ are not // reset, the duplicate advertising_phase (with the additional // received_connection_request) will append to the strategy_session) + ConnectionsLog::ClientSession strategy_session_proto2 = ParseTextProtoOrDie( + R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + received_connection_request < + local_response: ACCEPTED + remote_response: ACCEPTED + > + > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + received_connection_request < + local_response: ACCEPTED + remote_response: ACCEPTED + > + received_connection_request < + local_response: ACCEPTED + remote_response: ACCEPTED + > + > + >)pb"); EXPECT_THAT(event_logger.GetLoggedClientSession(), - Not(Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - received_connection_request < - local_response: ACCEPTED - remote_response: ACCEPTED - > - > - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - received_connection_request < - local_response: ACCEPTED - remote_response: ACCEPTED - > - received_connection_request < - local_response: ACCEPTED - remote_response: ACCEPTED - > - > - >)pb")))); + Not(Partially(EqualsProto(strategy_session_proto2)))); } TEST(AnalyticsRecorderTest, ClearcOutgoingConnectionRequestsAfterSessionWasLogged) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; 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); - analytics_recorder.OnStartDiscovery(strategy, mediums); + analytics_recorder.OnStartDiscovery(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnConnectionRequestSent(endpoint_id_0); analytics_recorder.OnLocalEndpointAccepted(endpoint_id_0); @@ -1180,24 +1227,28 @@ TEST(AnalyticsRecorderTest, analytics_recorder.LogSession(); // call ResetClientSessionLoggingResouces ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: DISCOVERER - discovery_phase < - medium: BLE - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - sent_connection_request < - local_response: ACCEPTED - remote_response: ACCEPTED - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto1 = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: DISCOVERER + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + sent_connection_request < + local_response: ACCEPTED + remote_response: ACCEPTED + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto1))); // LogStartSession CountDownLatch new_start_client_session_done_latch(1); @@ -1221,42 +1272,44 @@ TEST(AnalyticsRecorderTest, // - if the current_strategy_session_ and current_discovery_phase_ are // not reset, the duplicate discovery_phase (with the additional // sent_connection_request) will append to the strategy_session) + ConnectionsLog::ClientSession strategy_session_proto2 = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: DISCOVERER + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + sent_connection_request < + local_response: ACCEPTED + remote_response: ACCEPTED + > + > + discovery_phase < + medium: BLE + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + sent_connection_request < + local_response: ACCEPTED + remote_response: ACCEPTED + > + sent_connection_request < + local_response: ACCEPTED + remote_response: ACCEPTED + > + > + >)pb"); EXPECT_THAT(event_logger.GetLoggedClientSession(), - Not(Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: DISCOVERER - discovery_phase < - medium: BLE - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - sent_connection_request < - local_response: ACCEPTED - remote_response: ACCEPTED - > - > - discovery_phase < - medium: BLE - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - sent_connection_request < - local_response: ACCEPTED - remote_response: ACCEPTED - > - sent_connection_request < - local_response: ACCEPTED - remote_response: ACCEPTED - > - > - >)pb")))); + Not(Partially(EqualsProto(strategy_session_proto2)))); } TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { @@ -1277,26 +1330,29 @@ TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { // LogSession analytics_recorder.LogSession(); // call ResetClientSessionLoggingResouces ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); + ConnectionsLog::ClientSession strategy_session_proto1 = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + established_connection < + medium: BLUETOOTH + disconnection_reason: UNFINISHED + connection_token: "connection_token" + > + >)pb"); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - established_connection < - medium: BLUETOOTH - disconnection_reason: UNFINISHED - connection_token: "connection_token" - > - >)pb"))); + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto1))); // LogStartSession CountDownLatch new_start_client_session_done_latch(1); @@ -1316,41 +1372,42 @@ TEST(AnalyticsRecorderTest, ClearcActiveConnectionsAfterSessionWasLogged) { // reset, the duplicate advertising_phase_ (with the additional // will append to the strategy_session), and the active connection (i.e. // established_connection) will stay there. + ConnectionsLog::ClientSession strategy_session_proto2 = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + established_connection < + medium: BLUETOOTH + disconnection_reason: UNFINISHED + connection_token: "connection_token" + > + >)pb"); + EXPECT_THAT(event_logger.GetLoggedClientSession(), - Not(Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - established_connection < - medium: BLUETOOTH - disconnection_reason: UNFINISHED - connection_token: "connection_token" - > - >)pb")))); + Not(Partially(EqualsProto(strategy_session_proto2)))); } TEST(AnalyticsRecorderTest, ClearBandwidthUpgradeAttemptsAfterSessionWasLogged) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; std::string endpoint_id = "endpoint_id"; std::string endpoint_id_1 = "endpoint_id_1"; std::string endpoint_id_2 = "endpoint_id_2"; @@ -1360,7 +1417,8 @@ TEST(AnalyticsRecorderTest, FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartAdvertising(strategy, mediums); + analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnBandwidthUpgradeStarted(endpoint_id, BLE, WIFI_LAN, INCOMING, connection_token); @@ -1384,44 +1442,47 @@ TEST(AnalyticsRecorderTest, // - if the current_strategy_session_ and advertising_phase_ are not // reset, the duplicate advertising_phase_, and the upgrade_attempts (i.e. // bandwidth_upgrade_attempts_) will stay there. - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - upgrade_attempt < - direction: INCOMING - from_medium: BLE - to_medium: WIFI_LAN - upgrade_result: WIFI_LAN_MEDIUM_ERROR - error_stage: WIFI_LAN_SOCKET_CREATION - connection_token: "connection_token" - > - upgrade_attempt < - direction: INCOMING - from_medium: BLUETOOTH - to_medium: WIFI_LAN - upgrade_result: UPGRADE_RESULT_SUCCESS - error_stage: UPGRADE_SUCCESS - connection_token: "connection_token" - > - upgrade_attempt { - direction: INCOMING - from_medium: BLUETOOTH - to_medium: WIFI_LAN - upgrade_result: UNFINISHED_ERROR - error_stage: UPGRADE_UNFINISHED - connection_token: "connection_token" - } - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto1 = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + upgrade_attempt < + direction: INCOMING + from_medium: BLE + to_medium: WIFI_LAN + upgrade_result: WIFI_LAN_MEDIUM_ERROR + error_stage: WIFI_LAN_SOCKET_CREATION + connection_token: "connection_token" + > + upgrade_attempt < + direction: INCOMING + from_medium: BLUETOOTH + to_medium: WIFI_LAN + upgrade_result: UPGRADE_RESULT_SUCCESS + error_stage: UPGRADE_SUCCESS + connection_token: "connection_token" + > + upgrade_attempt { + direction: INCOMING + from_medium: BLUETOOTH + to_medium: WIFI_LAN + upgrade_result: UNFINISHED_ERROR + error_stage: UPGRADE_UNFINISHED + connection_token: "connection_token" + } + >)pb"); + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto1))); // LogStartSession CountDownLatch new_start_client_session_done_latch(1); @@ -1437,54 +1498,56 @@ TEST(AnalyticsRecorderTest, analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); + ConnectionsLog::ClientSession strategy_session_proto2 = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + upgrade_attempt < + direction: INCOMING + from_medium: BLE + to_medium: WIFI_LAN + upgrade_result: WIFI_LAN_MEDIUM_ERROR + error_stage: WIFI_LAN_SOCKET_CREATION + connection_token: "connection_token" + > + upgrade_attempt < + direction: INCOMING + from_medium: BLUETOOTH + to_medium: WIFI_LAN + upgrade_result: UPGRADE_RESULT_SUCCESS + error_stage: UPGRADE_SUCCESS + connection_token: "connection_token" + > + upgrade_attempt { + direction: INCOMING + from_medium: BLUETOOTH + to_medium: WIFI_LAN + upgrade_result: UNFINISHED_ERROR + error_stage: UPGRADE_UNFINISHED + connection_token: "connection_token" + } + >)pb"); EXPECT_THAT(event_logger.GetLoggedClientSession(), - Not(Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - upgrade_attempt < - direction: INCOMING - from_medium: BLE - to_medium: WIFI_LAN - upgrade_result: WIFI_LAN_MEDIUM_ERROR - error_stage: WIFI_LAN_SOCKET_CREATION - connection_token: "connection_token" - > - upgrade_attempt < - direction: INCOMING - from_medium: BLUETOOTH - to_medium: WIFI_LAN - upgrade_result: UPGRADE_RESULT_SUCCESS - error_stage: UPGRADE_SUCCESS - connection_token: "connection_token" - > - upgrade_attempt { - direction: INCOMING - from_medium: BLUETOOTH - to_medium: WIFI_LAN - upgrade_result: UNFINISHED_ERROR - error_stage: UPGRADE_UNFINISHED - connection_token: "connection_token" - } - >)pb")))); + Not(Partially(EqualsProto(strategy_session_proto2)))); } // Test if current_strategy_ is reset by checking if the same strategy would @@ -1498,17 +1561,18 @@ TEST(AnalyticsRecorderTest, FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartAdvertising(strategy, {BLUETOOTH}); + analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, + /*mediums=*/{BLUETOOTH}); analytics_recorder.OnStopAdvertising(); // LogSession analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); + //// The same strategy session shouldn't be logged again with the same client + //// session. EXPECT_THAT(event_logger.GetLoggedEventTypes(), - Contains(START_STRATEGY_SESSION) - .Times(1)); // the same strategy session shouldn't be logged - // again with the same client sesssion. + Contains(START_STRATEGY_SESSION).Times(1)); // LogStartSession CountDownLatch new_start_client_session_done_latch(1); @@ -1521,7 +1585,7 @@ TEST(AnalyticsRecorderTest, // LogSession again CountDownLatch new_client_session_done_latch(1); event_logger.SetClientSessionDoneLatch(new_client_session_done_latch); - analytics_recorder.OnStartAdvertising(strategy, {BLUETOOTH}); + analytics_recorder.OnStartAdvertising(strategy, /*mediums=*/{BLUETOOTH}); analytics_recorder.OnStopAdvertising(); analytics_recorder.LogSession(); @@ -1535,38 +1599,35 @@ TEST(AnalyticsRecorderTest, // proto will be logged. TEST(AnalyticsRecorderTest, NotLogSameStrategySessionProtoAfterSessionWasLogged) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - std::vector mediums = {BLE, BLUETOOTH}; - std::string endpoint_id = "endpoint_id"; - std::string connection_token = ""; - CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); - AnalyticsRecorder analytics_recorder{&event_logger}; + AnalyticsRecorder analytics_recorder(&event_logger); - analytics_recorder.OnStartAdvertising( - strategy, mediums); // via OnStartAdvertising, current_strategy_session_ - // is set in UpdateStrategySessionLocked. + //// Via OnStartAdvertising, current_strategy_session_is set in + //// UpdateStrategySessionLocked. + analytics_recorder.OnStartAdvertising(connections::Strategy::kP2pStar, + /*mediums=*/{BLE, BLUETOOTH}); analytics_recorder.OnStopAdvertising(); // LogSession analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - std::string strategy_session_proto = R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLE - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - >)pb"; + ConnectionsLog::ClientSession strategy_session_proto = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLE + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + >)pb"); EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(strategy_session_proto))); @@ -1594,33 +1655,36 @@ TEST(AnalyticsRecorderTest, // Test if current_advertising_phase_ is reset. TEST(AnalyticsRecorderTest, NotLogDuplicateAdvertisingPhaseAfterSessionWasLogged) { - connections::Strategy strategy = connections::Strategy::kP2pStar; - CountDownLatch client_session_done_latch(1); FakeEventLogger event_logger(client_session_done_latch); AnalyticsRecorder analytics_recorder(&event_logger); analytics_recorder.OnStartAdvertising( - strategy, {BLUETOOTH}); // set current_advertising_phase_ + connections::Strategy::kP2pStar, + /*mediums=*/{BLUETOOTH}); // set current_advertising_phase_ analytics_recorder.OnStopAdvertising(); // LogSession analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto1 = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto1))); // LogStartSession CountDownLatch new_start_client_session_done_latch(1); @@ -1639,28 +1703,30 @@ TEST(AnalyticsRecorderTest, analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); + ConnectionsLog::ClientSession strategy_session_proto2 = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: ADVERTISER + advertising_phase < + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + advertising_phase < + medium: BLUETOOTH + advertising_metadata < + supports_extended_ble_advertisements: false + connected_ap_frequency: 0 + supports_nfc_technology: false + > + > + >)pb"); EXPECT_THAT(event_logger.GetLoggedClientSession(), - Not(Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: ADVERTISER - advertising_phase < - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - advertising_phase < - medium: BLUETOOTH - advertising_metadata < - supports_extended_ble_advertisements: false - connected_ap_frequency: 0 - supports_nfc_technology: false - > - > - >)pb")))); + Not(Partially(EqualsProto(strategy_session_proto2)))); } // Test if current_discovery_phase_ is reset. @@ -1683,19 +1749,23 @@ TEST(AnalyticsRecorderTest, analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); - EXPECT_THAT(event_logger.GetLoggedClientSession(), Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: DISCOVERER - discovery_phase < - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: true - connected_ap_frequency: 1 - supports_nfc_technology: false - > - > - >)pb"))); + ConnectionsLog::ClientSession strategy_session_proto1 = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: DISCOVERER + discovery_phase < + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: true + connected_ap_frequency: 1 + supports_nfc_technology: false + > + > + >)pb"); + + EXPECT_THAT(event_logger.GetLoggedClientSession(), + Partially(EqualsProto(strategy_session_proto1))); // LogStartSession CountDownLatch new_start_client_session_done_latch(1); @@ -1714,28 +1784,30 @@ TEST(AnalyticsRecorderTest, analytics_recorder.LogSession(); ASSERT_TRUE(client_session_done_latch.Await(kDefaultTimeout).result()); + ConnectionsLog::ClientSession strategy_session_proto2 = + ParseTextProtoOrDie(R"pb( + strategy_session < + strategy: P2P_STAR + role: DISCOVERER + discovery_phase < + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: true + connected_ap_frequency: 1 + supports_nfc_technology: false + > + > + discovery_phase < + medium: BLUETOOTH + discovery_metadata < + supports_extended_ble_advertisements: true + connected_ap_frequency: 1 + supports_nfc_technology: false + > + > + >)pb"); EXPECT_THAT(event_logger.GetLoggedClientSession(), - Not(Partially(EqualsProto(R"pb( - strategy_session < - strategy: P2P_STAR - role: DISCOVERER - discovery_phase < - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: true - connected_ap_frequency: 1 - supports_nfc_technology: false - > - > - discovery_phase < - medium: BLUETOOTH - discovery_metadata < - supports_extended_ble_advertisements: true - connected_ap_frequency: 1 - supports_nfc_technology: false - > - > - >)pb")))); + Not(Partially(EqualsProto(strategy_session_proto2)))); } TEST(AnalyticsRecorderOnConnectionClosedTest, diff --git a/connections/implementation/analytics/connection_attempt_metadata_params.h b/connections/implementation/analytics/connection_attempt_metadata_params.h index e1e07146..65af75ab 100644 --- a/connections/implementation/analytics/connection_attempt_metadata_params.h +++ b/connections/implementation/analytics/connection_attempt_metadata_params.h @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2022-2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/connections/implementation/analytics/packet_meta_data.h b/connections/implementation/analytics/packet_meta_data.h index e45021f8..09d2a85a 100644 --- a/connections/implementation/analytics/packet_meta_data.h +++ b/connections/implementation/analytics/packet_meta_data.h @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2022-2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ #define NEARBY_CONNECTIONS_IMPLEMENTATION_ANALYTICS_PACKET_META_DATA_H_ #include -#include #include "absl/time/time.h" +#include "internal/platform/implementation/system_clock.h" #include "internal/platform/system_clock.h" namespace nearby { diff --git a/connections/implementation/analytics/throughput_recorder.cc b/connections/implementation/analytics/throughput_recorder.cc index 0f8fd218..51f4c492 100644 --- a/connections/implementation/analytics/throughput_recorder.cc +++ b/connections/implementation/analytics/throughput_recorder.cc @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2022-2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,9 +14,19 @@ #include "connections/implementation/analytics/throughput_recorder.h" +#include + +#include +#include #include +#include #include +#include "absl/container/flat_hash_map.h" +#include "absl/meta/type_traits.h" +#include "absl/strings/str_format.h" +#include "absl/time/time.h" +#include "internal/platform/implementation/system_clock.h" #include "internal/platform/logging.h" #include "internal/platform/mutex_lock.h" diff --git a/connections/implementation/analytics/throughput_recorder.h b/connections/implementation/analytics/throughput_recorder.h index 3deaa811..d2bacd9c 100644 --- a/connections/implementation/analytics/throughput_recorder.h +++ b/connections/implementation/analytics/throughput_recorder.h @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2022-2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,7 +19,9 @@ #include #include +#include "absl/base/thread_annotations.h" #include "absl/container/flat_hash_map.h" +#include "absl/time/time.h" #include "connections/implementation/analytics/packet_meta_data.h" #include "connections/payload_type.h" #include "internal/platform/mutex.h" diff --git a/connections/implementation/analytics/throughput_recorder_test.cc b/connections/implementation/analytics/throughput_recorder_test.cc index 64169723..c037993c 100644 --- a/connections/implementation/analytics/throughput_recorder_test.cc +++ b/connections/implementation/analytics/throughput_recorder_test.cc @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2022-2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -14,12 +14,16 @@ #include "connections/implementation/analytics/throughput_recorder.h" -#include "gmock/gmock.h" -#include "protobuf-matchers/protocol-buffer-matchers.h" +#include + +#include +#include + #include "gtest/gtest.h" #include "absl/time/clock.h" +#include "absl/time/time.h" #include "internal/platform/logging.h" -#include "proto/connections_enums.proto.h" +#include "proto/connections_enums.pb.h" namespace nearby { namespace analytics { diff --git a/internal/platform/implementation/BUILD b/internal/platform/implementation/BUILD index 7c323b4f..4bead8ee 100644 --- a/internal/platform/implementation/BUILD +++ b/internal/platform/implementation/BUILD @@ -39,6 +39,7 @@ cc_library( "timer.h", ], visibility = [ + "//connections/implementation/analytics:__subpackages__", "//fastpair:__subpackages__", "//internal/crypto:__pkg__", "//internal/platform:__pkg__",