Skip to content

Commit ce8ec24

Browse files
DmitryLukyanovJamesKovacs
authored andcommitted
CSHARP-4202: Specify correct max supported wire version. (#816)
1 parent d2106d6 commit ce8ec24

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ internal static class WireVersion
114114
new WireVersionInfo(wireVersion: 14, major: 5, minor: 1),
115115
new WireVersionInfo(wireVersion: 15, major: 5, minor: 2),
116116
new WireVersionInfo(wireVersion: 16, major: 5, minor: 3),
117-
new WireVersionInfo(wireVersion: 17, major: 6, minor: 0),
117+
new WireVersionInfo(wireVersion: 17, major: 6, minor: 0)
118118
};
119119

120-
private static Range<int> __supportedWireVersionRange = CreateSupportedWireVersionRange(minWireVersion: 6, maxWireVersion: 15);
120+
private static Range<int> __supportedWireVersionRange = CreateSupportedWireVersionRange(minWireVersion: 6, maxWireVersion: 17);
121121

122122
private static Range<int> CreateSupportedWireVersionRange(int minWireVersion, int maxWireVersion)
123123
{

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ public RequireServer Serverless(bool require = true)
140140
throw new SkipException("Test skipped because serverless is " + (require ? "required" : "not required") + ".");
141141
}
142142

143+
public RequireServer StableServer(bool stable = true)
144+
{
145+
var serverVersion = CoreTestConfiguration.ServerVersion;
146+
var isStableServer = serverVersion.PreRelease == null;
147+
148+
if (isStableServer == stable)
149+
{
150+
return this;
151+
}
152+
153+
throw new SkipException($"Test skipped because {(stable ? "GA" : "prerelease")} server version is expected, but found {serverVersion}.");
154+
}
155+
143156
public RequireServer Supports(Feature feature)
144157
{
145158
if (feature.IsSupported(_maxWireVersion))

tests/MongoDB.Driver.Core.Tests/Core/Clusters/ClusterDescriptionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void IsCompatibleWithDriver_should_return_expected_result(int[] wireRange
167167
var endPoint = new DnsEndPoint("localhost", i);
168168
var serverId = new ServerId(clusterId, endPoint);
169169
var wireRange = wireRanges[i];
170-
var wireVersionRange = wireRange == 0 ? new Range<int>(0, 0) : wireRange == 1 ? new Range<int>(6, 15) : null;
170+
var wireVersionRange = wireRange == 0 ? new Range<int>(0, 0) : wireRange == 1 ? Cluster.SupportedWireVersionRange : null;
171171
var server = new ServerDescription(serverId, endPoint, wireVersionRange: wireVersionRange, type: ServerType.Standalone);
172172
subject = subject.WithServerDescription(server);
173173
}
@@ -204,7 +204,7 @@ public void IsCompatibleWithDriver_should_return_true_if_server_unknown(int[] wi
204204
var endPoint = new DnsEndPoint("localhost", i);
205205
var serverId = new ServerId(clusterId, endPoint);
206206
var wireRange = wireRanges[i];
207-
var wireVersionRange = wireRange == 0 ? new Range<int>(0, 0) : wireRange == 1 ? new Range<int>(6, 15) : null;
207+
var wireVersionRange = wireRange == 0 ? new Range<int>(0, 0) : wireRange == 1 ? Cluster.SupportedWireVersionRange : null;
208208
var server = new ServerDescription(serverId, endPoint, wireVersionRange: wireVersionRange, type: ServerType.Unknown);
209209
subject = subject.WithServerDescription(server);
210210
}

tests/MongoDB.Driver.Core.Tests/Core/Clusters/ClusterTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void SupportedWireVersionRange_should_return_expected_result()
6060
{
6161
var result = Cluster.SupportedWireVersionRange;
6262

63-
result.Should().Be(new Range<int>(6, 15));
63+
result.Should().Be(new Range<int>(6, 17));
6464
}
6565

6666
[Fact]
@@ -325,8 +325,8 @@ public void SelectServer_should_throw_if_the_matched_server_cannot_be_found_and_
325325
[Theory]
326326
[InlineData(0, 0, false)]
327327
[InlineData(0, 0, true)]
328-
[InlineData(16, 17, false)]
329-
[InlineData(16, 17, true)]
328+
[InlineData(18, 19, false)]
329+
[InlineData(18, 19, true)]
330330
public void SelectServer_should_throw_if_any_servers_are_incompatible(int min, int max, bool async)
331331
{
332332
var subject = CreateSubject();

tests/MongoDB.Driver.Core.Tests/Core/Misc/WireVersionTests.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,25 @@
1616
using System;
1717
using FluentAssertions;
1818
using MongoDB.Driver.Core.Misc;
19+
using MongoDB.Driver.Core.TestHelpers.XunitExtensions;
1920
using Xunit;
2021

2122
namespace MongoDB.Driver.Core.Tests.Core.Misc
2223
{
2324
public class WireVersionTests
2425
{
26+
[SkippableFact]
27+
public void Server_maxWireVersion_should_be_in_supported_range()
28+
{
29+
RequireServer.Check().StableServer(stable: true);
30+
31+
var serverMaxWireVersion = CoreTestConfiguration.MaxWireVersion;
32+
33+
var isOverlaped = WireVersion.SupportedWireVersionRange.Overlaps(new Range<int>(serverMaxWireVersion, serverMaxWireVersion));
34+
35+
isOverlaped.Should().BeTrue();
36+
}
37+
2538
[Theory]
2639
[InlineData(14, "5.1")]
2740
[InlineData(1000, "Unknown (wire version 1000)")]
@@ -33,7 +46,7 @@ public void GetServerVersionForErrorMessage_should_return_expected_serverVersion
3346
[Fact]
3447
public void SupportedWireRange_should_be_correct()
3548
{
36-
WireVersion.SupportedWireVersionRange.Should().Be(new Range<int>(6, 15));
49+
WireVersion.SupportedWireVersionRange.Should().Be(new Range<int>(6, 17));
3750
}
3851

3952
[Fact]
@@ -46,6 +59,7 @@ public void ToServerVersion_should_throw_if_wireVersion_less_than_0()
4659

4760
[Theory]
4861
[InlineData(99, null, null)]
62+
[InlineData(19, null, null)]
4963
[InlineData(18, null, null)]
5064
[InlineData(17, 6, 0)]
5165
[InlineData(16, 5, 3)]

tests/MongoDB.Driver.Core.Tests/Core/Servers/ServerDescriptionTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,8 @@ public void Equals_should_return_true_when_all_fields_are_equal()
277277
[InlineData(new[] { 13, 15 }, true)]
278278
[InlineData(new[] { 14, 15 }, true)]
279279
[InlineData(new[] { 15, 16 }, true)]
280-
[InlineData(new[] { 16, 17 }, false)]
280+
[InlineData(new[] { 16, 17 }, true)]
281+
[InlineData(new[] { 18, 19 }, false)]
281282
public void IsCompatibleWithDriver_should_return_expected_result(int[] minMaxWireVersions, bool expectedResult)
282283
{
283284
var clusterId = new ClusterId(1);

0 commit comments

Comments
 (0)