Skip to content

Commit 1263050

Browse files
DmitryLukyanovBorisDog
authored andcommitted
CSHARP-4031: Update load balancer tests to support dedicated load balancer port. (#752)
CSHARP-4031: Update load balancer tests to support dedicated load balancer port.
1 parent 9db5b2f commit 1263050

24 files changed

+174
-184
lines changed

evergreen/evergreen.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ functions:
203203
script: |
204204
${PREPARE_SHELL}
205205
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
206+
LOAD_BALANCER=${LOAD_BALANCER} \
206207
MONGODB_VERSION=${VERSION} \
207208
TOPOLOGY=${TOPOLOGY} \
208209
AUTH=${AUTH} \
@@ -865,6 +866,8 @@ tasks:
865866
- name: test-load-balancer-netstandard20
866867
commands:
867868
- func: bootstrap-mongo-orchestration
869+
vars:
870+
LOAD_BALANCER: 'true'
868871
- func: run-load-balancer
869872
- func: run-load-balancer-tests
870873
vars:
@@ -874,6 +877,8 @@ tasks:
874877
- name: test-load-balancer-netstandard21
875878
commands:
876879
- func: bootstrap-mongo-orchestration
880+
vars:
881+
LOAD_BALANCER: 'true'
877882
- func: run-load-balancer
878883
- func: run-load-balancer-tests
879884
vars:
@@ -1588,14 +1593,14 @@ buildvariants:
15881593
- name: plain-auth-tests
15891594

15901595
- matrix_name: load-balancer-tests
1591-
matrix_spec: { version: ["5.0", "latest"], auth: "noauth", ssl: "nossl", topology: "sharded-cluster", os: "ubuntu-1804" }
1596+
matrix_spec: { version: ["latest"], auth: "noauth", ssl: "nossl", topology: "sharded-cluster", os: "ubuntu-1804" }
15921597
display_name: "Load Balancer ${version} ${auth} ${ssl} ${os}"
15931598
tasks:
15941599
- name: "test-load-balancer-netstandard20"
15951600
- name: "test-load-balancer-netstandard21"
15961601

15971602
- matrix_name: load-balancer-tests-secure
1598-
matrix_spec: { version: ["5.0", "latest"], auth: "auth", ssl: "ssl", topology: "sharded-cluster", os: "ubuntu-1804" }
1603+
matrix_spec: { version: ["latest"], auth: "auth", ssl: "ssl", topology: "sharded-cluster", os: "ubuntu-1804" }
15991604
display_name: "Load Balancer ${version} ${auth} ${ssl} ${os}"
16001605
tasks:
16011606
- name: "test-load-balancer-netstandard20"

src/MongoDB.Driver.Core/Core/Connections/HelloResult.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public ServerType ServerType
321321

322322
if (ServiceId != null)
323323
{
324-
return ServerType.LoadBalanced; // TODO: change when Service Id will be supported by server
324+
return ServerType.LoadBalanced;
325325
}
326326

327327
return ServerType.Standalone;
@@ -344,15 +344,7 @@ public ObjectId? ServiceId
344344
}
345345
else
346346
{
347-
if (ServiceIdHelper.IsServiceIdEmulationEnabled)
348-
{
349-
// TODO: temporary solution until server will actually support serviceId
350-
return TopologyVersion?.ProcessId;
351-
}
352-
else
353-
{
354-
return null;
355-
}
347+
return null;
356348
}
357349
}
358350
}

src/MongoDB.Driver.Core/ServiceIdHelper.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/MongoDB.Driver.Core.TestHelpers/CoreTestConfiguration.cs

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -263,25 +263,13 @@ public static ConnectionString CreateConnectionString()
263263
}
264264
}
265265

266-
var connectionString = new ConnectionString(uri);
267-
if (connectionString.LoadBalanced)
268-
{
269-
// TODO: temporary solution until server will actually support serviceId
270-
ServiceIdHelper.IsServiceIdEmulationEnabled = true;
271-
}
272-
return connectionString;
266+
return new ConnectionString(uri);
273267
}
274268

275269
private static ConnectionString GetConnectionStringWithMultipleShardRouters()
276270
{
277271
var uri = Environment.GetEnvironmentVariable("MONGODB_URI_WITH_MULTIPLE_MONGOSES") ?? "mongodb://localhost,localhost:27018";
278-
var connectionString = new ConnectionString(uri);
279-
if (connectionString.LoadBalanced)
280-
{
281-
// TODO: temporary solution until server will actually support serviceId
282-
ServiceIdHelper.IsServiceIdEmulationEnabled = true;
283-
}
284-
return connectionString;
272+
return new ConnectionString(uri);
285273
}
286274

287275
private static DatabaseNamespace GetDatabaseNamespace()
@@ -472,37 +460,39 @@ private static string GetStorageEngine()
472460
string result;
473461

474462
var clusterType = __cluster.Value.Description.Type;
475-
if (clusterType == ClusterType.Sharded || clusterType == ClusterType.LoadBalanced)
476-
{
477-
// mongos cannot provide this data directly, so we need connection to a particular mongos shard
478-
var shardsCollection = new CollectionNamespace("config", "shards");
479-
var shards = FindDocuments(__cluster.Value, shardsCollection).FirstOrDefault();
480-
if (shards != null)
481-
{
482-
var fullHosts = shards["host"].AsString; // for example: "shard01/localhost:27018,localhost:27019,localhost:27020"
483-
var firstHost = fullHosts.Substring(fullHosts.IndexOf('/') + 1).Split(',')[0];
484-
using (var cluster = CreateCluster(
485-
configurator => configurator.ConfigureCluster(cs => cs.With(endPoints: new[] { EndPointHelper.Parse(firstHost) })),
486-
allowDataBearingServers: true))
487-
{
488-
result = GetStorageEngineForCluster(cluster);
489-
}
490-
}
491-
else
492-
{
493-
if (Serverless)
463+
switch (clusterType)
464+
{
465+
case ClusterType.LoadBalanced:
466+
case var _ when Serverless:
467+
// Load balancing and serverless are only supported for servers higher than 50
468+
result = "wiredTiger";
469+
break;
470+
case ClusterType.Sharded:
494471
{
495-
result = "wiredTiger";
496-
}
497-
else
498-
{
499-
throw new InvalidOperationException("mongos has not been found.");
472+
// mongos cannot provide this data directly, so we need connection to a particular mongos shard
473+
var shardsCollection = new CollectionNamespace("config", "shards");
474+
var shards = FindDocuments(__cluster.Value, shardsCollection).FirstOrDefault();
475+
if (shards != null)
476+
{
477+
var fullHosts = shards["host"].AsString; // for example: "shard01/localhost:27018,localhost:27019,localhost:27020"
478+
var firstHost = fullHosts.Substring(fullHosts.IndexOf('/') + 1).Split(',')[0];
479+
using (var cluster = CreateCluster(
480+
configurator => configurator.ConfigureCluster(cs => cs.With(endPoints: new[] { EndPointHelper.Parse(firstHost) })),
481+
allowDataBearingServers: true))
482+
{
483+
result = GetStorageEngineForCluster(cluster);
484+
}
485+
}
486+
else
487+
{
488+
throw new InvalidOperationException("mongos has not been found.");
489+
}
490+
break;
500491
}
501-
}
502-
}
503-
else
504-
{
505-
result = GetStorageEngineForCluster(__cluster.Value);
492+
493+
default:
494+
result = GetStorageEngineForCluster(__cluster.Value);
495+
break;
506496
}
507497

508498
return result ?? "mmapv1";

tests/MongoDB.Driver.Core.Tests/LoadBalancingIntergationTests.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ public void BulkWrite_should_pin_connection_as_expected(
5555

5656
SetupData();
5757

58-
ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response
59-
6058
var eventCapturer = new EventCapturer()
6159
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
6260
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
@@ -104,8 +102,6 @@ public void BulkWrite_and_cursor_should_share_pinned_connection_under_the_same_t
104102

105103
SetupData();
106104

107-
ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response
108-
109105
var eventCapturer = new EventCapturer()
110106
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
111107
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
@@ -179,8 +175,6 @@ public void BulkWrite_and_cursor_should_share_pinned_connection_under_the_same_t
179175

180176
SetupData();
181177

182-
ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response
183-
184178
var eventCapturer = new EventCapturer()
185179
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
186180
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
@@ -249,8 +243,6 @@ public void Cursor_should_pin_connection_as_expected(
249243

250244
SetupData();
251245

252-
ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response
253-
254246
var eventCapturer = new EventCapturer()
255247
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
256248
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
@@ -321,8 +313,6 @@ public void Cursor_should_pin_connection_in_transaction_with_new_sessions_as_exp
321313

322314
SetupData();
323315

324-
ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response
325-
326316
var eventCapturer = new EventCapturer()
327317
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
328318
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
@@ -397,8 +387,6 @@ public void Cursor_should_pin_connection_in_transaction_with_the_same_session_as
397387

398388
SetupData();
399389

400-
ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response
401-
402390
var eventCapturer = new EventCapturer()
403391
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
404392
.Capture<ConnectionPoolCheckingOutConnectionEvent>()
@@ -476,8 +464,6 @@ public void Cursor_should_unpin_connection_for_operations_under_the_same_transac
476464

477465
SetupData();
478466

479-
ServiceIdHelper.IsServiceIdEmulationEnabled = true; // TODO: temporary solution to enable emulating serviceId in a server response
480-
481467
var eventCapturer = new EventCapturer()
482468
.Capture<ConnectionPoolCheckedOutConnectionEvent>()
483469
.Capture<ConnectionPoolCheckingOutConnectionEvent>()

0 commit comments

Comments
 (0)