Check listening options as well when we want to enforce topology constraints

PiperOrigin-RevId: 543497497
This commit is contained in:
Anay Wadhera
2023-06-26 11:40:17 -07:00
committed by Copybara-Service
parent 7a25b33603
commit 7f1d6a4bba
5 changed files with 63 additions and 17 deletions
@@ -18,6 +18,7 @@
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
@@ -144,6 +145,23 @@ class ClientProxyTest : public ::testing::TestWithParam<FeatureFlags::Flags> {
EXPECT_TRUE(client->HasPendingConnectionToEndpoint(endpoint.id));
}
Endpoint StartListeningForIncomingConnections(
ClientProxy* client, v3::ConnectionListener listener,
v3::ConnectionListeningOptions options = {}) {
Endpoint endpoint{
.info = ByteArray{"advertising endpoint name"},
.id = client->GetLocalEndpointId(),
};
client->StartedListeningForIncomingConnections(
service_id_, strategy_, std::move(listener), options);
return endpoint;
}
void StopListeningForIncomingConnections(ClientProxy* client) {
client->StoppedListeningForIncomingConnections();
EXPECT_FALSE(client->IsListeningForIncomingConnections());
}
Endpoint StartDiscovery(ClientProxy* client, DiscoveryListener listener) {
Endpoint endpoint{
.info = ByteArray{"discovery endpoint name"},
@@ -1064,6 +1082,30 @@ TEST_F(ClientProxyTest, TestGetIncomingConnectionListener) {
EXPECT_TRUE(disconnect_latch.Await().Ok());
}
TEST_F(ClientProxyTest, EnforceTopologyWhenRequestedAdvertising) {
EXPECT_FALSE(client1_.ShouldEnforceTopologyConstraints());
StartAdvertising(&client1_, advertising_connection_listener_,
{.enforce_topology_constraints = true});
EXPECT_TRUE(client1_.ShouldEnforceTopologyConstraints());
}
TEST_F(ClientProxyTest, EnforceTopologyWhenRequestedListeningWithStrategy) {
EXPECT_FALSE(client1_.ShouldEnforceTopologyConstraints());
StartListeningForIncomingConnections(&client1_,
{},
{.strategy = Strategy::kP2pCluster,
.enforce_topology_constraints = true});
EXPECT_TRUE(client1_.ShouldEnforceTopologyConstraints());
}
TEST_F(ClientProxyTest, DontEnforceTopologyWhenRequestedWithNoStrategy) {
EXPECT_FALSE(client1_.ShouldEnforceTopologyConstraints());
StartListeningForIncomingConnections(&client1_,
{},
{.strategy = Strategy::kNone});
EXPECT_TRUE(client1_.ShouldEnforceTopologyConstraints());
}
} // namespace
} // namespace connections
} // namespace nearby