Skip to content

Commit 81c1adb

Browse files
CSHARP-3714: Implement missing test from Versioned API specification (#563)
1 parent e5cbf26 commit 81c1adb

File tree

22 files changed

+224
-82
lines changed

22 files changed

+224
-82
lines changed

build.cake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ Task("Test")
121121
.Where(name => !name.ToString().Contains("Atlas")),
122122
testProject =>
123123
{
124+
if (Environment.GetEnvironmentVariable("MONGODB_API_VERSION") != null &&
125+
testProject.ToString().Contains("Legacy"))
126+
{
127+
return; // Legacy tests are exempt from Version API testing
128+
}
129+
124130
var testWithDefaultGuidRepresentationMode = Environment.GetEnvironmentVariable("TEST_WITH_DEFAULT_GUID_REPRESENTATION_MODE");
125131
if (testWithDefaultGuidRepresentationMode != null)
126132
{

evergreen/evergreen.yml

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ functions:
202202
params:
203203
script: |
204204
${PREPARE_SHELL}
205+
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
205206
MONGODB_VERSION=${VERSION} \
206207
TOPOLOGY=${TOPOLOGY} \
207208
AUTH=${AUTH} \
@@ -290,15 +291,18 @@ functions:
290291
. ./evergreen/set-virtualenv.sh
291292
. ./evergreen/set-temp-fle-aws-creds.sh
292293
${PREPARE_SHELL}
293-
SSL=${SSL} OS=${OS} evergreen/add-certs-if-needed.sh
294+
SSL=${SSL} \
295+
OS=${OS} \
296+
evergreen/add-certs-if-needed.sh
294297
AUTH=${AUTH} \
295-
SSL=${SSL} \
296-
MONGODB_URI="${MONGODB_URI}" \
297-
TOPOLOGY=${TOPOLOGY} \
298-
OS=${OS} \
299-
COMPRESSOR=${COMPRESSOR} \
300-
CLIENT_PEM=${DRIVERS_TOOLS}/.evergreen/x509gen/client.pem \
301-
FRAMEWORK=${FRAMEWORK} \
298+
SSL=${SSL} \
299+
MONGODB_URI="${MONGODB_URI}" \
300+
TOPOLOGY=${TOPOLOGY} \
301+
OS=${OS} \
302+
COMPRESSOR=${COMPRESSOR} \
303+
CLIENT_PEM=${DRIVERS_TOOLS}/.evergreen/x509gen/client.pem \
304+
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
305+
FRAMEWORK=${FRAMEWORK} \
302306
evergreen/run-tests.sh
303307
echo "Skipping certificate removal..."
304308
@@ -787,6 +791,46 @@ tasks:
787791
- func: run-aws-auth-test-with-aws-EC2-credentials
788792
# ECS test is skipped untill testing on Linux becomes possible
789793

794+
- name: versioned-api-tests-net452
795+
commands:
796+
- func: bootstrap-mongo-orchestration
797+
vars:
798+
REQUIRE_API_VERSION: true
799+
- func: run-tests
800+
vars:
801+
FRAMEWORK: net452
802+
REQUIRE_API_VERSION: true
803+
804+
- name: versioned-api-tests-netstandard15
805+
commands:
806+
- func: bootstrap-mongo-orchestration
807+
vars:
808+
REQUIRE_API_VERSION: true
809+
- func: run-tests
810+
vars:
811+
FRAMEWORK: netstandard15
812+
REQUIRE_API_VERSION: true
813+
814+
- name: versioned-api-tests-netstandard20
815+
commands:
816+
- func: bootstrap-mongo-orchestration
817+
vars:
818+
REQUIRE_API_VERSION: true
819+
- func: run-tests
820+
vars:
821+
FRAMEWORK: netstandard20
822+
REQUIRE_API_VERSION: true
823+
824+
- name: versioned-api-tests-netstandard21
825+
commands:
826+
- func: bootstrap-mongo-orchestration
827+
vars:
828+
REQUIRE_API_VERSION: true
829+
- func: run-tests
830+
vars:
831+
FRAMEWORK: netstandard21
832+
REQUIRE_API_VERSION: true
833+
790834
- name: atlas-data-lake-test
791835
commands:
792836
- func: bootstrap-mongohoused
@@ -1379,6 +1423,17 @@ buildvariants:
13791423
tasks:
13801424
- name: aws-auth-tests
13811425

1426+
- matrix_name: versioned-api-tests
1427+
matrix_spec: { version: ["5.0", "latest"], topology: "standalone", auth: "auth", ssl: "nossl", os: "windows-64" }
1428+
display_name: "Versioned API ${version} ${topology} ${auth} ${ssl} ${os}"
1429+
run_on:
1430+
- windows-64-vs2017-test
1431+
tasks:
1432+
- name: versioned-api-tests-net452
1433+
- name: versioned-api-tests-netstandard15
1434+
- name: versioned-api-tests-netstandard20
1435+
- name: versioned-api-tests-netstandard21
1436+
13821437
- matrix_name: plain-auth-tests
13831438
matrix_spec: { os: "*" }
13841439
display_name: "PLAIN (LDAP) Auth Tests"
@@ -1433,4 +1488,3 @@ buildvariants:
14331488
- name: test-gssapi-netstandard15
14341489
- name: test-gssapi-netstandard20
14351490
- name: test-gssapi-netstandard21
1436-

evergreen/run-tests.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set -o errexit # Exit the script with error if any of the commands fail
99
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
1010
# TOPOLOGY Allows you to modify variables and the MONGODB_URI based on test topology
1111
# Supported values: "server", "replica_set", "sharded_cluster"
12+
# REQUIRE_API_VERSION Flag to require API version. Values: "true" / nil (default)
1213
# CLIENT_PEM Path to mongo-orchestration's client.pem
1314
# OCSP_TLS_SHOULD_SUCCEED Set to test OCSP. Values are true/false/nil
1415
# MONGODB_X509_CLIENT_P12_PATH Absolute path to client certificate in p12 format
@@ -19,6 +20,7 @@ set -o errexit # Exit the script with error if any of the commands fail
1920
# Environment variables produced as output:
2021
# MONGODB_X509_CLIENT_P12_PATH Absolute path to client certificate in p12 format
2122
# MONGO_X509_CLIENT_CERTIFICATE_PASSWORD Password for client certificate
23+
# MONGODB_API_VERSION Server API version to use in every client
2224

2325
AUTH=${AUTH:-noauth}
2426
SSL=${SSL:-nossl}
@@ -91,6 +93,11 @@ fi
9193

9294
echo "Running $AUTH tests over $SSL for $TOPOLOGY with $COMPRESSOR compressor and connecting to $MONGODB_URI"
9395

96+
if [ ! -z "$REQUIRE_API_VERSION" ]; then
97+
export MONGODB_API_VERSION="1"
98+
echo "Server API version is set to $MONGODB_API_VERSION"
99+
fi
100+
94101
export TARGET="Test${FRAMEWORK}"
95102
if [[ "$OS" =~ Windows|windows ]]; then
96103
if [ "$OCSP_TLS_SHOULD_SUCCEED" != "nil" ]; then

src/MongoDB.Driver.Core/Core/Configuration/ClusterBuilderExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ public static ClusterBuilder ConfigureWithConnectionString(
235235
{
236236
builder = builder.ConfigureCluster(s => s.With(serverSelectionTimeout: connectionString.ServerSelectionTimeout.Value));
237237
}
238+
if (serverApi != null)
239+
{
240+
builder = builder.ConfigureCluster(s => s.With(serverApi: serverApi));
241+
}
238242

239243
return builder;
240244
}

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static class CoreTestConfiguration
4545
private static Lazy<DatabaseNamespace> __databaseNamespace = new Lazy<DatabaseNamespace>(GetDatabaseNamespace, isThreadSafe: true);
4646
private static Lazy<BuildInfoResult> _buildInfo = new Lazy<BuildInfoResult>(RunBuildInfo, isThreadSafe: true);
4747
private static MessageEncoderSettings __messageEncoderSettings = new MessageEncoderSettings();
48+
private static Lazy<ServerApi> __serverApi = new Lazy<ServerApi>(GetServerApi, isThreadSafe: true);
4849
private static TraceSource __traceSource;
4950

5051
// static properties
@@ -73,6 +74,16 @@ public static MessageEncoderSettings MessageEncoderSettings
7374
get { return __messageEncoderSettings; }
7475
}
7576

77+
public static bool RequireApiVersion
78+
{
79+
get { return __serverApi.Value != null; }
80+
}
81+
82+
public static ServerApi ServerApi
83+
{
84+
get { return __serverApi.Value; }
85+
}
86+
7687
public static SemanticVersion ServerVersion
7788
{
7889
get
@@ -108,7 +119,7 @@ public static ClusterBuilder ConfigureCluster(ClusterBuilder builder)
108119
}
109120

110121
builder = builder
111-
.ConfigureWithConnectionString(__connectionString.Value)
122+
.ConfigureWithConnectionString(__connectionString.Value, __serverApi.Value)
112123
.ConfigureCluster(c => c.With(serverSelectionTimeout: TimeSpan.FromMilliseconds(int.Parse(serverSelectionTimeoutString))));
113124

114125
if (__connectionString.Value.Tls.HasValue &&
@@ -271,6 +282,23 @@ private static DatabaseNamespace GetDatabaseNamespace()
271282
return new DatabaseNamespace("Tests" + timestamp);
272283
}
273284

285+
private static ServerApi GetServerApi()
286+
{
287+
var serverApiVersion = Environment.GetEnvironmentVariable("MONGODB_API_VERSION");
288+
289+
if (serverApiVersion == null)
290+
{
291+
return null;
292+
}
293+
294+
if (serverApiVersion != "1")
295+
{
296+
throw new ArgumentException($"Server API version \"{serverApiVersion}\" is not supported");
297+
}
298+
299+
return new ServerApi(ServerApiVersion.V1);
300+
}
301+
274302
public static DatabaseNamespace GetDatabaseNamespaceForTestClass(Type testClassType)
275303
{
276304
var databaseName = TruncateDatabaseNameIfTooLong(__databaseNamespace.Value.DatabaseName + "-" + testClassType.Name);
@@ -345,8 +373,7 @@ public static ICoreSessionHandle StartSession(ICluster cluster, CoreSessionOptio
345373

346374
private static bool IsReplicaSet(string uri)
347375
{
348-
var clusterBuilder = new ClusterBuilder();
349-
clusterBuilder.ConfigureWithConnectionString(uri);
376+
var clusterBuilder = new ClusterBuilder().ConfigureWithConnectionString(uri, __serverApi.Value);
350377

351378
using (var cluster = clusterBuilder.BuildCluster())
352379
{

tests/MongoDB.Driver.Core.TestHelpers/XunitExtensions/RequireServer.cs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ public RequireServer ClusterTypes(params ClusterType[] clusterTypes)
7373
throw new SkipException($"Test skipped because cluster type is {actualClusterType} and not one of ({clusterTypesString}).");
7474
}
7575

76+
public RequireServer DoesNotSupport(Feature feature)
77+
{
78+
if (!feature.IsSupported(_serverVersion))
79+
{
80+
return this;
81+
}
82+
throw new SkipException($"Test skipped because server version {_serverVersion} does support the {feature.Name} feature.");
83+
}
84+
85+
public RequireServer DoesNotSupport(params Feature[] features)
86+
{
87+
foreach (var feature in features)
88+
{
89+
DoesNotSupport(feature);
90+
}
91+
return this;
92+
}
93+
7694
public RequireServer LoadBalancing(bool enabled)
7795
{
7896
var isLoadBalancing = CoreTestConfiguration.ConnectionString.LoadBalanced;
@@ -83,6 +101,16 @@ public RequireServer LoadBalancing(bool enabled)
83101
throw new SkipException($"Test skipped because load balancing mode is {(isLoadBalancing ? "on" : "off")}.");
84102
}
85103

104+
public RequireServer RequireApiVersion(bool require = true)
105+
{
106+
if (CoreTestConfiguration.RequireApiVersion == require)
107+
{
108+
return this;
109+
}
110+
111+
throw new SkipException("Test skipped because API version is " + (require ? "required" : "not required") + ".");
112+
}
113+
86114
public RequireServer RunOn(BsonArray requirements)
87115
{
88116
var cluster = CoreTestConfiguration.Cluster;
@@ -129,24 +157,6 @@ public RequireServer SupportsSessions()
129157
throw new SkipException($"Test skipped because the cluster does not support sessions.");
130158
}
131159

132-
public RequireServer DoesNotSupport(Feature feature)
133-
{
134-
if (!feature.IsSupported(_serverVersion))
135-
{
136-
return this;
137-
}
138-
throw new SkipException($"Test skipped because server version {_serverVersion} does support the {feature.Name} feature.");
139-
}
140-
141-
public RequireServer DoesNotSupport(params Feature[] features)
142-
{
143-
foreach (var feature in features)
144-
{
145-
DoesNotSupport(feature);
146-
}
147-
return this;
148-
}
149-
150160
public RequireServer StorageEngine(string storageEngine)
151161
{
152162
var actualStorageEngine = CoreTestConfiguration.GetStorageEngine();

tests/MongoDB.Driver.Core.Tests/Core/Operations/BulkMixedWriteOperationTests.cs

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,14 +1446,22 @@ public void Execute_with_update_should_send_session_id_when_supported(
14461446
}
14471447

14481448
[SkippableTheory]
1449-
[InlineData(new[] { 1 }, new[] { 1 })]
1450-
[InlineData(new[] { 1, 1 }, new[] { 2 })]
1451-
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000 }, new[] { 4 })]
1452-
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999887 }, new[] { 5 })]
1453-
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999888 }, new[] { 4, 1 })]
1454-
public void Execute_with_multiple_deletes_should_split_batches_as_expected_when_using_write_commands_via_opmessage(int[] requestSizes, int[] expectedBatchCounts)
1449+
[InlineData(new[] { 1 }, new[] { 1 }, false)]
1450+
[InlineData(new[] { 1, 1 }, new[] { 2 }, false)]
1451+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000 }, new[] { 4 }, false)]
1452+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999887 }, new[] { 5 }, false)]
1453+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999888 }, new[] { 4, 1 }, false)]
1454+
[InlineData(new[] { 1 }, new[] { 1 }, true)]
1455+
[InlineData(new[] { 1, 1 }, new[] { 2 }, true)]
1456+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000 }, new[] { 4 }, true)]
1457+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999869 }, new[] { 5 }, true)]
1458+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999870 }, new[] { 4, 1 }, true)]
1459+
public void Execute_with_multiple_deletes_should_split_batches_as_expected_when_using_write_commands_via_opmessage(
1460+
int[] requestSizes,
1461+
int[] expectedBatchCounts,
1462+
bool requireApiVersion)
14551463
{
1456-
RequireServer.Check().Supports(Feature.CommandMessage);
1464+
RequireServer.Check().Supports(Feature.CommandMessage).RequireApiVersion(requireApiVersion);
14571465
DropCollection();
14581466

14591467
using (EventContext.BeginOperation())
@@ -1509,14 +1517,22 @@ public void Execute_with_multiple_deletes_should_split_batches_as_expected_when_
15091517
}
15101518

15111519
[SkippableTheory]
1512-
[InlineData(new[] { 1 }, new[] { 1 })]
1513-
[InlineData(new[] { 1, 1 }, new[] { 2 })]
1514-
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000 }, new[] { 4 })]
1515-
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999885 }, new[] { 5 })]
1516-
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999886 }, new[] { 4, 1 })]
1517-
public void Execute_with_multiple_inserts_should_split_batches_as_expected_when_using_write_commands_via_opmessage(int[] documentSizes, int[] expectedBatchCounts)
1520+
[InlineData(new[] { 1 }, new[] { 1 }, false)]
1521+
[InlineData(new[] { 1, 1 }, new[] { 2 }, false)]
1522+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000 }, new[] { 4 }, false)]
1523+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999885 }, new[] { 5 }, false)]
1524+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999886 }, new[] { 4, 1 }, false)]
1525+
[InlineData(new[] { 1 }, new[] { 1 }, true)]
1526+
[InlineData(new[] { 1, 1 }, new[] { 2 }, true)]
1527+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000 }, new[] { 4 }, true)]
1528+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999867 }, new[] { 5 }, true)]
1529+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999868 }, new[] { 4, 1 }, true)]
1530+
public void Execute_with_multiple_inserts_should_split_batches_as_expected_when_using_write_commands_via_opmessage(
1531+
int[] documentSizes,
1532+
int[] expectedBatchCounts,
1533+
bool requireApiVersion)
15181534
{
1519-
RequireServer.Check().Supports(Feature.CommandMessage);
1535+
RequireServer.Check().Supports(Feature.CommandMessage).RequireApiVersion(requireApiVersion);
15201536
DropCollection();
15211537

15221538
using (EventContext.BeginOperation())
@@ -1575,14 +1591,22 @@ public void Execute_with_multiple_inserts_should_split_batches_as_expected_when_
15751591
}
15761592

15771593
[SkippableTheory]
1578-
[InlineData(new[] { 1 }, new[] { 1 })]
1579-
[InlineData(new[] { 1, 1 }, new[] { 2 })]
1580-
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000 }, new[] { 4 })]
1581-
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999887 }, new[] { 5 })]
1582-
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999888 }, new[] { 4, 1 })]
1583-
public void Execute_with_multiple_updates_should_split_batches_as_expected_when_using_write_commands_via_opmessage(int[] requestSizes, int[] expectedBatchCounts)
1594+
[InlineData(new[] { 1 }, new[] { 1 }, false)]
1595+
[InlineData(new[] { 1, 1 }, new[] { 2 }, false)]
1596+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000 }, new[] { 4 }, false)]
1597+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999887 }, new[] { 5 }, false)]
1598+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999888 }, new[] { 4, 1 }, false)]
1599+
[InlineData(new[] { 1 }, new[] { 1 }, true)]
1600+
[InlineData(new[] { 1, 1 }, new[] { 2 }, true)]
1601+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000 }, new[] { 4 }, true)]
1602+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999869 }, new[] { 5 }, true)]
1603+
[InlineData(new[] { 10000000, 10000000, 10000000, 10000000, 7999870 }, new[] { 4, 1 }, true)]
1604+
public void Execute_with_multiple_updates_should_split_batches_as_expected_when_using_write_commands_via_opmessage(
1605+
int[] requestSizes,
1606+
int[] expectedBatchCounts,
1607+
bool requireApiVersion)
15841608
{
1585-
RequireServer.Check().Supports(Feature.CommandMessage);
1609+
RequireServer.Check().Supports(Feature.CommandMessage).RequireApiVersion(requireApiVersion);
15861610
DropCollection();
15871611

15881612
using (EventContext.BeginOperation())

tests/MongoDB.Driver.Core.Tests/Specifications/connection-monitoring-and-pooling/tests/pool-checkout-maxConnecting-is-enforced.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
},
1515
"data": {
1616
"failCommands": [
17-
"isMaster"
17+
"isMaster",
18+
"hello"
1819
],
1920
"closeConnection": false,
2021
"blockConnection": true,

0 commit comments

Comments
 (0)