mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Disable medium env by default.
MediumEnvironment's initial state will now match the state after calling `Stop()`. Cleaned up tests that were calling Stop() before test start. PiperOrigin-RevId: 486277290
This commit is contained in:
committed by
Copybara-Service
parent
5faa395f24
commit
a90b7f85fc
@@ -20,10 +20,10 @@
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "connections/implementation/mediums/bluetooth_radio.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/ble.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
@@ -50,8 +50,6 @@ class BleTest : public ::testing::TestWithParam<FeatureFlags> {
|
||||
protected:
|
||||
using DiscoveredPeripheralCallback = BleMedium::DiscoveredPeripheralCallback;
|
||||
|
||||
BleTest() { env_.Stop(); }
|
||||
|
||||
MediumEnvironment& env_{MediumEnvironment::Instance()};
|
||||
};
|
||||
|
||||
|
||||
@@ -47,8 +47,6 @@ constexpr absl::string_view kAdvertisementString = "\x0a\x0b\x0c\x0d";
|
||||
|
||||
class BleV2Test : public testing::TestWithParam<FeatureFlags> {
|
||||
protected:
|
||||
BleV2Test() { env_.Stop(); }
|
||||
|
||||
MediumEnvironment& env_{MediumEnvironment::Instance()};
|
||||
};
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "connections/implementation/mediums/bluetooth_radio.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/bluetooth_classic.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/system_clock.h"
|
||||
|
||||
namespace location {
|
||||
@@ -51,7 +51,6 @@ class BluetoothClassicTest : public ::testing::TestWithParam<FeatureFlags> {
|
||||
|
||||
BluetoothClassicTest() {
|
||||
env_.Start();
|
||||
env_.Reset();
|
||||
radio_a_ = std::make_unique<BluetoothRadio>();
|
||||
radio_b_ = std::make_unique<BluetoothRadio>();
|
||||
bt_a_ = std::make_unique<BluetoothClassic>(*radio_a_);
|
||||
@@ -72,7 +71,6 @@ class BluetoothClassicTest : public ::testing::TestWithParam<FeatureFlags> {
|
||||
env_.Sync(false);
|
||||
radio_a_.reset();
|
||||
radio_b_.reset();
|
||||
env_.Reset();
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
#include "connections/implementation/mediums/webrtc/session_description_wrapper.h"
|
||||
#include "connections/implementation/mediums/webrtc_socket.h"
|
||||
#include "internal/platform/byte_array.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/webrtc.h"
|
||||
#include "webrtc/api/data_channel_interface.h"
|
||||
#include "webrtc/api/jsep.h"
|
||||
@@ -41,9 +41,9 @@ namespace {
|
||||
class ConnectionFlowTest : public ::testing::Test {
|
||||
protected:
|
||||
ConnectionFlowTest() {
|
||||
MediumEnvironment::Instance().Stop();
|
||||
MediumEnvironment::Instance().Start({.webrtc_enabled = true});
|
||||
}
|
||||
~ConnectionFlowTest() override { MediumEnvironment::Instance().Stop(); }
|
||||
};
|
||||
|
||||
std::unique_ptr<webrtc::IceCandidateInterface> CopyCandidate(
|
||||
|
||||
@@ -47,8 +47,6 @@ class WebRtcTest : public ::testing::TestWithParam<FeatureFlags> {
|
||||
using MockAcceptedCallback = testing::MockFunction<void(
|
||||
const std::string& service_id, WebRtcSocketWrapper socket)>;
|
||||
|
||||
WebRtcTest() { env_.Stop(); }
|
||||
|
||||
MediumEnvironment& env_{MediumEnvironment::Instance()};
|
||||
};
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/nsd_service_info.h"
|
||||
#include "internal/platform/wifi_lan.h"
|
||||
|
||||
namespace location {
|
||||
@@ -52,8 +52,6 @@ class WifiLanTest : public ::testing::TestWithParam<FeatureFlags> {
|
||||
protected:
|
||||
using DiscoveredServiceCallback = WifiLanMedium::DiscoveredServiceCallback;
|
||||
|
||||
WifiLanTest() { env_.Stop(); }
|
||||
|
||||
MediumEnvironment& env_{MediumEnvironment::Instance()};
|
||||
};
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "connections/implementation/offline_simulation_user.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/output_stream.h"
|
||||
#include "internal/platform/pipe.h"
|
||||
#include "internal/platform/system_clock.h"
|
||||
|
||||
@@ -75,8 +75,6 @@ constexpr BooleanMediumSelector kTestCases[] = {
|
||||
class OfflineServiceControllerTest
|
||||
: public ::testing::TestWithParam<BooleanMediumSelector> {
|
||||
protected:
|
||||
OfflineServiceControllerTest() { env_.Stop(); }
|
||||
|
||||
bool SetupConnection(OfflineSimulationUser& user_a,
|
||||
OfflineSimulationUser& user_b) {
|
||||
user_a.StartAdvertising(std::string(kServiceId), &connect_latch_);
|
||||
|
||||
@@ -68,7 +68,6 @@ class P2pClusterPcpHandlerTest
|
||||
protected:
|
||||
void SetUp() override {
|
||||
NEARBY_LOG(INFO, "SetUp: begin");
|
||||
env_.Stop();
|
||||
FeatureFlags::GetMutableFlagsForTesting().support_ble_v2 =
|
||||
std::get<1>(GetParam());
|
||||
if (advertising_options_.allowed.ble) {
|
||||
|
||||
@@ -100,8 +100,6 @@ class PayloadSimulationUser : public SimulationUser {
|
||||
class PayloadManagerTest
|
||||
: public ::testing::TestWithParam<BooleanMediumSelector> {
|
||||
protected:
|
||||
PayloadManagerTest() { env_.Stop(); }
|
||||
|
||||
bool SetupConnection(PayloadSimulationUser& user_a,
|
||||
PayloadSimulationUser& user_b) {
|
||||
user_a.StartAdvertising(std::string(kServiceId), &connection_latch_);
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#include "absl/time/time.h"
|
||||
#include "connections/implementation/endpoint_channel_manager.h"
|
||||
#include "connections/implementation/simulation_user.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
@@ -67,8 +67,6 @@ constexpr BooleanMediumSelector kTestCases[] = {
|
||||
|
||||
class PcpManagerTest : public ::testing::TestWithParam<BooleanMediumSelector> {
|
||||
protected:
|
||||
PcpManagerTest() { env_.Stop(); }
|
||||
|
||||
MediumEnvironment& env_{MediumEnvironment::Instance()};
|
||||
};
|
||||
|
||||
|
||||
@@ -29,10 +29,7 @@ constexpr absl::Duration kWaitDuration = absl::Milliseconds(1000);
|
||||
|
||||
class WifiHotspotTest : public testing::Test {
|
||||
protected:
|
||||
WifiHotspotTest() {
|
||||
env_.Stop();
|
||||
env_.Start();
|
||||
}
|
||||
WifiHotspotTest() { env_.Start(); }
|
||||
~WifiHotspotTest() override { env_.Stop(); }
|
||||
|
||||
MediumEnvironment& env_{MediumEnvironment::Instance()};
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
@@ -48,8 +48,6 @@ class BleMediumTest : public ::testing::TestWithParam<FeatureFlags> {
|
||||
using DiscoveredPeripheralCallback = BleMedium::DiscoveredPeripheralCallback;
|
||||
using AcceptedConnectionCallback = BleMedium::AcceptedConnectionCallback;
|
||||
|
||||
BleMediumTest() { env_.Stop(); }
|
||||
|
||||
MediumEnvironment& env_{MediumEnvironment::Instance()};
|
||||
};
|
||||
|
||||
|
||||
@@ -69,8 +69,6 @@ class BlePeripheralStub : public api::ble_v2::BlePeripheral {
|
||||
|
||||
class BleV2MediumTest : public ::testing::TestWithParam<FeatureFlags> {
|
||||
protected:
|
||||
BleV2MediumTest() { env_.Stop(); }
|
||||
|
||||
MediumEnvironment& env_{MediumEnvironment::Instance()};
|
||||
};
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "absl/time/time.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/bluetooth_adapter.h"
|
||||
#include "internal/platform/count_down_latch.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/medium_environment.h"
|
||||
#include "internal/platform/single_thread_executor.h"
|
||||
|
||||
namespace location {
|
||||
@@ -47,7 +47,6 @@ class BluetoothClassicMediumTest
|
||||
using DiscoveryCallback = BluetoothClassicMedium::DiscoveryCallback;
|
||||
BluetoothClassicMediumTest() {
|
||||
env_.Start();
|
||||
env_.Reset();
|
||||
adapter_a_ = std::make_unique<BluetoothAdapter>();
|
||||
adapter_b_ = std::make_unique<BluetoothAdapter>();
|
||||
bt_a_ = std::make_unique<BluetoothClassicMedium>(*adapter_a_);
|
||||
@@ -67,7 +66,6 @@ class BluetoothClassicMediumTest
|
||||
env_.Sync(false);
|
||||
adapter_a_.reset();
|
||||
adapter_b_.reset();
|
||||
env_.Reset();
|
||||
env_.Stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -436,7 +436,7 @@ class MediumEnvironment {
|
||||
|
||||
void RunOnMediumEnvironmentThread(std::function<void()> runnable);
|
||||
|
||||
std::atomic_bool enabled_ = true;
|
||||
std::atomic_bool enabled_ = false;
|
||||
std::atomic_int job_count_ = 0;
|
||||
std::atomic_bool enable_notifications_ = false;
|
||||
SingleThreadExecutor executor_;
|
||||
|
||||
@@ -48,10 +48,7 @@ constexpr absl::Duration kWaitDuration = absl::Milliseconds(100);
|
||||
|
||||
class WifiDirectMediumTest : public testing::TestWithParam<FeatureFlags> {
|
||||
protected:
|
||||
WifiDirectMediumTest() {
|
||||
env_.Stop();
|
||||
env_.Start();
|
||||
}
|
||||
WifiDirectMediumTest() { env_.Start(); }
|
||||
~WifiDirectMediumTest() override {
|
||||
absl::SleepFor(kWaitDuration);
|
||||
EXPECT_TRUE(env_.IsWifiDirectMediumsEmpty());
|
||||
|
||||
@@ -50,8 +50,6 @@ class WifiLanMediumTest : public ::testing::TestWithParam<FeatureFlags> {
|
||||
protected:
|
||||
using DiscoveredServiceCallback = WifiLanMedium::DiscoveredServiceCallback;
|
||||
|
||||
WifiLanMediumTest() { env_.Stop(); }
|
||||
|
||||
MediumEnvironment& env_{MediumEnvironment::Instance()};
|
||||
};
|
||||
|
||||
@@ -377,8 +375,7 @@ TEST_F(WifiLanMediumTest, CanDiscoverMultipleAdvertisementsOnSameService) {
|
||||
|
||||
NsdServiceInfo nsd_service_info_1;
|
||||
nsd_service_info_1.SetServiceName("service1");
|
||||
nsd_service_info_1.SetTxtRecord(std::string(kEndpointInfoKey),
|
||||
"endpoint1");
|
||||
nsd_service_info_1.SetTxtRecord(std::string(kEndpointInfoKey), "endpoint1");
|
||||
nsd_service_info_1.SetServiceType(service_type);
|
||||
|
||||
// Setup second advertising device.
|
||||
@@ -388,8 +385,7 @@ TEST_F(WifiLanMediumTest, CanDiscoverMultipleAdvertisementsOnSameService) {
|
||||
|
||||
NsdServiceInfo nsd_service_info_2;
|
||||
nsd_service_info_2.SetServiceName("service2");
|
||||
nsd_service_info_2.SetTxtRecord(std::string(kEndpointInfoKey),
|
||||
"endpoint2");
|
||||
nsd_service_info_2.SetTxtRecord(std::string(kEndpointInfoKey), "endpoint2");
|
||||
nsd_service_info_2.SetServiceType(service_type);
|
||||
|
||||
EXPECT_TRUE(wifi_lan_advertising_1.StartAdvertising(nsd_service_info_1));
|
||||
@@ -399,7 +395,6 @@ TEST_F(WifiLanMediumTest, CanDiscoverMultipleAdvertisementsOnSameService) {
|
||||
EXPECT_TRUE(wifi_lan_advertising_2.StopAdvertising(nsd_service_info_2));
|
||||
EXPECT_TRUE(lost_latch.Await(kWaitDuration).result());
|
||||
|
||||
|
||||
// Stop to descovery
|
||||
EXPECT_TRUE(wifi_lan_discovery.StopDiscovery(service_type));
|
||||
env_.Stop();
|
||||
|
||||
@@ -87,7 +87,6 @@ class BleTest : public testing::TestWithParam<FeatureFlags> {
|
||||
};
|
||||
|
||||
protected:
|
||||
BleTest() { env_.Stop(); }
|
||||
absl::optional<BleV2MediumStatus> GetBleStatus(const Ble& ble) {
|
||||
return env_.GetBleV2MediumStatus(*ble.GetImpl());
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace {
|
||||
|
||||
class PresenceClientTest : public testing::Test {
|
||||
protected:
|
||||
PresenceClientTest() { env_.Stop(); }
|
||||
location::nearby::MediumEnvironment& env_{
|
||||
location::nearby::MediumEnvironment::Instance()};
|
||||
};
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace {
|
||||
|
||||
class PresenceServiceTest : public testing::Test {
|
||||
protected:
|
||||
PresenceServiceTest() { env_.Stop(); }
|
||||
location::nearby::MediumEnvironment& env_{
|
||||
location::nearby::MediumEnvironment::Instance()};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user