Skip to content

Commit 19eefd9

Browse files
committed
CSHARP-2285: Disable group command tests for servers that do not support the group command
1 parent eea00c7 commit 19eefd9

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

src/MongoDB.Driver.Core/Core/Misc/Feature.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class Feature
4747
private static readonly Feature __failPoints = new Feature("FailPoints", new SemanticVersion(2, 4, 0));
4848
private static readonly Feature __findAndModifyWriteConcern = new Feature("FindAndModifyWriteConcern", new SemanticVersion(3, 2, 0));
4949
private static readonly Feature __findCommand = new Feature("FindCommand", new SemanticVersion(3, 2, 0));
50+
private static readonly Feature __groupCommand = new Feature("GroupCommand", new SemanticVersion(1, 0, 0), new SemanticVersion(4, 0, 0, "rc1"));
5051
private static readonly Feature __listCollectionsCommand = new Feature("ListCollectionsCommand", new SemanticVersion(3, 0, 0));
5152
private static readonly Feature __listDatabasesFilter = new Feature("ListDatabasesFilter", new SemanticVersion(3, 4, 2));
5253
private static readonly Feature __listDatabasesNameOnlyOption = new Feature("ListDatabasesNameOnlyOption", new SemanticVersion(3, 4, 3));
@@ -182,6 +183,11 @@ public class Feature
182183
/// Gets the find command feature.
183184
/// </summary>
184185
public static Feature FindCommand => __findCommand;
186+
187+
/// <summary>
188+
/// Gets the grouop command feature.
189+
/// </summary>
190+
public static Feature GroupCommand => __groupCommand;
185191

186192
/// <summary>
187193
/// Gets the index options defaults feature.
@@ -261,16 +267,20 @@ public class Feature
261267

262268
private readonly string _name;
263269
private readonly SemanticVersion _firstSupportedVersion;
270+
private readonly SemanticVersion _supportRemovedVersion;
271+
264272

265273
/// <summary>
266274
/// Initializes a new instance of the <see cref="Feature"/> class.
267275
/// </summary>
268276
/// <param name="name">The name of the feature.</param>
269277
/// <param name="firstSupportedVersion">The first server version that supports the feature.</param>
270-
public Feature(string name, SemanticVersion firstSupportedVersion)
278+
/// /// <param name="supportRemovedVersion">The server version that stops support the feature.</param>
279+
public Feature(string name, SemanticVersion firstSupportedVersion, SemanticVersion supportRemovedVersion = null)
271280
{
272281
_name = name;
273282
_firstSupportedVersion = firstSupportedVersion;
283+
_supportRemovedVersion = supportRemovedVersion;
274284
}
275285

276286
/// <summary>
@@ -295,7 +305,9 @@ public Feature(string name, SemanticVersion firstSupportedVersion)
295305
/// <returns>Whether a feature is supported by a version of the server.</returns>
296306
public bool IsSupported(SemanticVersion serverVersion)
297307
{
298-
return serverVersion >= _firstSupportedVersion;
308+
return _supportRemovedVersion != null
309+
? serverVersion >= _firstSupportedVersion && serverVersion < _supportRemovedVersion
310+
: serverVersion >= _firstSupportedVersion;
299311
}
300312

301313
/// <summary>

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,13 @@ public void CreateCommand_should_return_expected_result_when_MaxTime_is_set(long
361361
result["maxTimeMS"].BsonType.Should().Be(BsonType.Int32);
362362
}
363363

364-
[Theory]
364+
[SkippableTheory]
365365
[ParameterAttributeData]
366366
public void Execute_should_return_expected_result_when_key_is_used(
367367
[Values(false, true)]
368368
bool async)
369369
{
370-
RequireServer.Check();
370+
RequireServer.Check().Supports(Feature.GroupCommand);
371371
EnsureTestData();
372372
var subject = new GroupOperation<BsonDocument>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings);
373373

@@ -379,13 +379,13 @@ public void Execute_should_return_expected_result_when_key_is_used(
379379
BsonDocument.Parse("{ x : 3, count : 3 }"));
380380
}
381381

382-
[Theory]
382+
[SkippableTheory]
383383
[ParameterAttributeData]
384384
public void Execute_should_return_expected_result_when_keyFunction_is_used(
385385
[Values(false, true)]
386386
bool async)
387387
{
388-
RequireServer.Check();
388+
RequireServer.Check().Supports(Feature.GroupCommand);
389389
EnsureTestData();
390390
var subject = new GroupOperation<BsonDocument>(_collectionNamespace, _keyFunction, _initial, _reduceFunction, null, _messageEncoderSettings);
391391

@@ -405,7 +405,7 @@ public void Execute_should_return_expected_result_when_Collation_is_set(
405405
[Values(false, true)]
406406
bool async)
407407
{
408-
RequireServer.Check().Supports(Feature.Collation);
408+
RequireServer.Check().Supports(Feature.GroupCommand, Feature.Collation);
409409
EnsureTestData();
410410
var collation = new Collation("en_US", caseLevel: caseSensitive, strength: CollationStrength.Primary);
411411
var filter = BsonDocument.Parse("{ y : 'a' }");
@@ -437,13 +437,13 @@ public void Execute_should_return_expected_result_when_Collation_is_set(
437437
result.Should().Equal(expectedResult);
438438
}
439439

440-
[Theory]
440+
[SkippableTheory]
441441
[ParameterAttributeData]
442442
public void Execute_should_return_expected_result_when_FinalizeFunction_is_set(
443443
[Values(false, true)]
444444
bool async)
445445
{
446-
RequireServer.Check();
446+
RequireServer.Check().Supports(Feature.GroupCommand);
447447
EnsureTestData();
448448
var subject = new GroupOperation<BsonDocument>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings)
449449
{
@@ -458,15 +458,15 @@ public void Execute_should_return_expected_result_when_FinalizeFunction_is_set(
458458
BsonDocument.Parse("{ x : 3, count : -3 }"));
459459
}
460460

461-
[Theory]
461+
[SkippableTheory]
462462
[ParameterAttributeData]
463463
public void Execute_should_return_expected_result_when_MaxTime_is_used(
464464
[Values(null, 1000)]
465465
int? seconds,
466466
[Values(false, true)]
467467
bool async)
468468
{
469-
RequireServer.Check();
469+
RequireServer.Check().Supports(Feature.GroupCommand);
470470
EnsureTestData();
471471
var maxTime = seconds.HasValue ? TimeSpan.FromSeconds(seconds.Value) : (TimeSpan?)null;
472472
var subject = new GroupOperation<BsonDocument>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings)
@@ -483,13 +483,13 @@ public void Execute_should_return_expected_result_when_MaxTime_is_used(
483483
BsonDocument.Parse("{ x : 3, count : 3 }"));
484484
}
485485

486-
[Theory]
486+
[SkippableTheory]
487487
[ParameterAttributeData]
488488
public void Execute_should_return_expected_result_when_ResultSerializer_is_used(
489489
[Values(false, true)]
490490
bool async)
491491
{
492-
RequireServer.Check();
492+
RequireServer.Check().Supports(Feature.GroupCommand);
493493
EnsureTestData();
494494
var resultSerializer = new ElementDeserializer<int>("x", new Int32Serializer());
495495
var subject = new GroupOperation<int>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings)
@@ -502,7 +502,7 @@ public void Execute_should_return_expected_result_when_ResultSerializer_is_used(
502502
result.Should().Equal(1, 2, 3);
503503
}
504504

505-
[Theory]
505+
[SkippableTheory]
506506
[ParameterAttributeData]
507507
public void Execute_should_throw_when_binding_is_null(
508508
[Values(false, true)]
@@ -532,7 +532,7 @@ public void Execute_should_throw_when_Collation_is_set_but_not_supported(
532532
[Values(false, true)]
533533
bool async)
534534
{
535-
RequireServer.Check().DoesNotSupport(Feature.Collation);
535+
RequireServer.Check().Supports(Feature.GroupCommand).DoesNotSupport(Feature.Collation);
536536
EnsureTestData();
537537
var subject = new GroupOperation<BsonDocument>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings)
538538
{
@@ -549,7 +549,7 @@ public void Execute_should_throw_when_Collation_is_set_but_not_supported(
549549
public void Execute_should_send_session_id_when_supported(
550550
[Values(false, true)] bool async)
551551
{
552-
RequireServer.Check();
552+
RequireServer.Check().Supports(Feature.GroupCommand);
553553
EnsureTestData();
554554
var subject = new GroupOperation<BsonDocument>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings);
555555

@@ -561,7 +561,7 @@ public void Execute_should_send_session_id_when_supported(
561561
public void Execute_should_throw_when_maxTime_is_exceeded(
562562
[Values(false, true)] bool async)
563563
{
564-
RequireServer.Check().Supports(Feature.FailPoints).ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet);
564+
RequireServer.Check().Supports(Feature.GroupCommand, Feature.FailPoints).ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet);
565565
var subject = new GroupOperation<BsonDocument>(_collectionNamespace, _key, _initial, _reduceFunction, null, _messageEncoderSettings);
566566
subject.MaxTime = TimeSpan.FromSeconds(9001);
567567

tests/MongoDB.Driver.Legacy.Tests/MongoCollectionTests.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,9 +2045,10 @@ public void TestGetMore()
20452045
_collection.FindAll().ToList();
20462046
}
20472047

2048-
[Fact]
2048+
[SkippableFact]
20492049
public void TestGroupWithFinalizeFunction()
20502050
{
2051+
RequireServer.Check().Supports(Feature.GroupCommand);
20512052
_collection.Drop();
20522053
_collection.Insert(new BsonDocument("x", 1));
20532054
_collection.Insert(new BsonDocument("x", 1));
@@ -2073,9 +2074,10 @@ public void TestGroupWithFinalizeFunction()
20732074
Assert.Equal(-3, results[2]["count"].ToInt32());
20742075
}
20752076

2076-
[Fact]
2077+
[SkippableFact]
20772078
public void TestGroupWithKeyFields()
20782079
{
2080+
RequireServer.Check().Supports(Feature.GroupCommand);
20792081
_collection.Drop();
20802082
_collection.Insert(new BsonDocument("x", 1));
20812083
_collection.Insert(new BsonDocument("x", 1));
@@ -2100,9 +2102,10 @@ public void TestGroupWithKeyFields()
21002102
Assert.Equal(3, results[2]["count"].ToInt32());
21012103
}
21022104

2103-
[Fact]
2105+
[SkippableFact]
21042106
public void TestGroupWithKeyFunction()
21052107
{
2108+
RequireServer.Check().Supports(Feature.GroupCommand);
21062109
_collection.Drop();
21072110
_collection.Insert(new BsonDocument("x", 1));
21082111
_collection.Insert(new BsonDocument("x", 1));
@@ -2127,9 +2130,10 @@ public void TestGroupWithKeyFunction()
21272130
Assert.Equal(3, results[2]["count"].ToInt32());
21282131
}
21292132

2130-
[Fact]
2133+
[SkippableFact]
21312134
public void TestGroupWithMaxTime()
21322135
{
2136+
RequireServer.Check().Supports(Feature.GroupCommand);
21332137
if (_primary.Supports(FeatureId.MaxTime))
21342138
{
21352139
using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary))
@@ -2153,9 +2157,10 @@ public void TestGroupWithMaxTime()
21532157
}
21542158
}
21552159

2156-
[Fact]
2160+
[SkippableFact]
21572161
public void TestGroupWithQuery()
21582162
{
2163+
RequireServer.Check().Supports(Feature.GroupCommand);
21592164
_collection.Drop();
21602165
_collection.Insert(new BsonDocument("x", 1));
21612166
_collection.Insert(new BsonDocument("x", 1));

0 commit comments

Comments
 (0)