Skip to content

CSHARP-4031: Update load balancer tests to support dedicated load balancer port. #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions evergreen/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ functions:
script: |
${PREPARE_SHELL}
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
LOAD_BALANCER=${LOAD_BALANCER} \
MONGODB_VERSION=${VERSION} \
TOPOLOGY=${TOPOLOGY} \
AUTH=${AUTH} \
Expand Down Expand Up @@ -865,6 +866,8 @@ tasks:
- name: test-load-balancer-netstandard20
commands:
- func: bootstrap-mongo-orchestration
vars:
LOAD_BALANCER: 'true'
- func: run-load-balancer
- func: run-load-balancer-tests
vars:
Expand All @@ -874,6 +877,8 @@ tasks:
- name: test-load-balancer-netstandard21
commands:
- func: bootstrap-mongo-orchestration
vars:
LOAD_BALANCER: 'true'
- func: run-load-balancer
- func: run-load-balancer-tests
vars:
Expand Down Expand Up @@ -1588,14 +1593,14 @@ buildvariants:
- name: plain-auth-tests

- matrix_name: load-balancer-tests
matrix_spec: { version: ["5.0", "latest"], auth: "noauth", ssl: "nossl", topology: "sharded-cluster", os: "ubuntu-1804" }
matrix_spec: { version: ["latest"], auth: "noauth", ssl: "nossl", topology: "sharded-cluster", os: "ubuntu-1804" }
display_name: "Load Balancer ${version} ${auth} ${ssl} ${os}"
tasks:
- name: "test-load-balancer-netstandard20"
- name: "test-load-balancer-netstandard21"

- matrix_name: load-balancer-tests-secure
matrix_spec: { version: ["5.0", "latest"], auth: "auth", ssl: "ssl", topology: "sharded-cluster", os: "ubuntu-1804" }
matrix_spec: { version: ["latest"], auth: "auth", ssl: "ssl", topology: "sharded-cluster", os: "ubuntu-1804" }
display_name: "Load Balancer ${version} ${auth} ${ssl} ${os}"
tasks:
- name: "test-load-balancer-netstandard20"
Expand Down
12 changes: 2 additions & 10 deletions src/MongoDB.Driver.Core/Core/Connections/HelloResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public ServerType ServerType

if (ServiceId != null)
{
return ServerType.LoadBalanced; // TODO: change when Service Id will be supported by server
return ServerType.LoadBalanced;
}

return ServerType.Standalone;
Expand All @@ -344,15 +344,7 @@ public ObjectId? ServiceId
}
else
{
if (ServiceIdHelper.IsServiceIdEmulationEnabled)
{
// TODO: temporary solution until server will actually support serviceId
return TopologyVersion?.ProcessId;
}
else
{
return null;
}
return null;
}
}
}
Expand Down
25 changes: 0 additions & 25 deletions src/MongoDB.Driver.Core/ServiceIdHelper.cs

This file was deleted.

76 changes: 33 additions & 43 deletions tests/MongoDB.Driver.Core.TestHelpers/CoreTestConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,25 +253,13 @@ public static ConnectionString CreateConnectionString()
}
}

var connectionString = new ConnectionString(uri);
if (connectionString.LoadBalanced)
{
// TODO: temporary solution until server will actually support serviceId
ServiceIdHelper.IsServiceIdEmulationEnabled = true;
}
return connectionString;
return new ConnectionString(uri);
}

private static ConnectionString GetConnectionStringWithMultipleShardRouters()
{
var uri = Environment.GetEnvironmentVariable("MONGODB_URI_WITH_MULTIPLE_MONGOSES") ?? "mongodb://localhost,localhost:27018";
var connectionString = new ConnectionString(uri);
if (connectionString.LoadBalanced)
{
// TODO: temporary solution until server will actually support serviceId
ServiceIdHelper.IsServiceIdEmulationEnabled = true;
}
return connectionString;
return new ConnectionString(uri);
}

private static DatabaseNamespace GetDatabaseNamespace()
Expand Down Expand Up @@ -451,37 +439,39 @@ private static string GetStorageEngine()
string result;

var clusterType = __cluster.Value.Description.Type;
if (clusterType == ClusterType.Sharded || clusterType == ClusterType.LoadBalanced)
{
// mongos cannot provide this data directly, so we need connection to a particular mongos shard
var shardsCollection = new CollectionNamespace("config", "shards");
var shards = FindDocuments(__cluster.Value, shardsCollection).FirstOrDefault();
if (shards != null)
{
var fullHosts = shards["host"].AsString; // for example: "shard01/localhost:27018,localhost:27019,localhost:27020"
var firstHost = fullHosts.Substring(fullHosts.IndexOf('/') + 1).Split(',')[0];
using (var cluster = CreateCluster(
configurator => configurator.ConfigureCluster(cs => cs.With(endPoints: new[] { EndPointHelper.Parse(firstHost) })),
allowDataBearingServers: true))
{
result = GetStorageEngineForCluster(cluster);
}
}
else
{
if (Serverless)
switch (clusterType)
{
case ClusterType.LoadBalanced:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoadBalanced can use the same workaround as we used for serverless

case var _ when Serverless:
// Load balancing and serverless are only supported for servers higher than 50
result = "wiredTiger";
break;
case ClusterType.Sharded:
{
result = "wiredTiger";
}
else
{
throw new InvalidOperationException("mongos has not been found.");
// mongos cannot provide this data directly, so we need connection to a particular mongos shard
var shardsCollection = new CollectionNamespace("config", "shards");
var shards = FindDocuments(__cluster.Value, shardsCollection).FirstOrDefault();
if (shards != null)
{
var fullHosts = shards["host"].AsString; // for example: "shard01/localhost:27018,localhost:27019,localhost:27020"
var firstHost = fullHosts.Substring(fullHosts.IndexOf('/') + 1).Split(',')[0];
using (var cluster = CreateCluster(
configurator => configurator.ConfigureCluster(cs => cs.With(endPoints: new[] { EndPointHelper.Parse(firstHost) })),
allowDataBearingServers: true))
{
result = GetStorageEngineForCluster(cluster);
}
}
else
{
throw new InvalidOperationException("mongos has not been found.");
}
break;
}
}
}
else
{
result = GetStorageEngineForCluster(__cluster.Value);

default:
result = GetStorageEngineForCluster(__cluster.Value);
break;
}

return result ?? "mmapv1";
Expand Down
14 changes: 0 additions & 14 deletions tests/MongoDB.Driver.Core.Tests/LoadBalancingIntergationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public void BulkWrite_should_pin_connection_as_expected(

SetupData();

ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response

var eventCapturer = new EventCapturer()
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
Expand Down Expand Up @@ -104,8 +102,6 @@ public void BulkWrite_and_cursor_should_share_pinned_connection_under_the_same_t

SetupData();

ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response

var eventCapturer = new EventCapturer()
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
Expand Down Expand Up @@ -179,8 +175,6 @@ public void BulkWrite_and_cursor_should_share_pinned_connection_under_the_same_t

SetupData();

ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response

var eventCapturer = new EventCapturer()
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
Expand Down Expand Up @@ -249,8 +243,6 @@ public void Cursor_should_pin_connection_as_expected(

SetupData();

ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response

var eventCapturer = new EventCapturer()
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
Expand Down Expand Up @@ -321,8 +313,6 @@ public void Cursor_should_pin_connection_in_transaction_with_new_sessions_as_exp

SetupData();

ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response

var eventCapturer = new EventCapturer()
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
Expand Down Expand Up @@ -397,8 +387,6 @@ public void Cursor_should_pin_connection_in_transaction_with_the_same_session_as

SetupData();

ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response

var eventCapturer = new EventCapturer()
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
Expand Down Expand Up @@ -476,8 +464,6 @@ public void Cursor_should_unpin_connection_for_operations_under_the_same_transac

SetupData();

ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response

var eventCapturer = new EventCapturer()
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
Expand Down
Loading