Skip to content

Commit 29b13b0

Browse files
committed
CSHARP-1720: Code review changes.
1 parent 02558cb commit 29b13b0

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

src/MongoDB.Driver.Core/Core/Clusters/ServerSelectors/ReadPreferenceServerSelector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private IEnumerable<ServerDescription> SelectForReplicaSet(ClusterDescription cl
137137
var minHeartBeatIntervalTicks = servers.Select(s => s.HeartbeatInterval.Ticks).Min();
138138
if (_maxStaleness.Value.Ticks < 2 * minHeartBeatIntervalTicks)
139139
{
140-
throw new MongoClientException("MaxStaleness must be at least twice the heartbeat frequency.");
140+
throw new MongoClientException("MaxStaleness must be at least twice the heartbeat interval.");
141141
}
142142

143143
servers = new CachedEnumerable<ServerDescription>(SelectFreshServers(cluster, servers)); // prevent multiple enumeration

src/MongoDB.Driver/MongoUrlBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public TimeSpan HeartbeatTimeout
256256
{
257257
if (value < TimeSpan.Zero && value != Timeout.InfiniteTimeSpan)
258258
{
259-
throw new ArgumentOutOfRangeException("value", "HeartbeatInterval must be greater than or equal to zero.");
259+
throw new ArgumentOutOfRangeException("value", "HeartbeatTimeout must be greater than or equal to zero.");
260260
}
261261
_heartbeatTimeout = value;
262262
}

tests/MongoDB.Driver.Core.Tests/Core/Configuration/ConnectionStringTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ public void When_gssapiServiceName_is_specified(string connectionString, string
342342
[InlineData("mongodb://localhost?heartbeatInterval=15s", 1000 * 15)]
343343
[InlineData("mongodb://localhost?heartbeatInterval=15m", 1000 * 60 * 15)]
344344
[InlineData("mongodb://localhost?heartbeatInterval=15h", 1000 * 60 * 60 * 15)]
345+
[InlineData("mongodb://localhost?heartbeatFrequency=15ms", 15)]
346+
[InlineData("mongodb://localhost?heartbeatFrequencyMS=15", 15)]
347+
[InlineData("mongodb://localhost?heartbeatFrequency=15", 1000 * 15)]
348+
[InlineData("mongodb://localhost?heartbeatFrequency=15s", 1000 * 15)]
349+
[InlineData("mongodb://localhost?heartbeatFrequency=15m", 1000 * 60 * 15)]
350+
[InlineData("mongodb://localhost?heartbeatFrequency=15h", 1000 * 60 * 60 * 15)]
345351
public void When_heartbeat_interval_is_specified(string connectionString, int milliseconds)
346352
{
347353
var subject = new ConnectionString(connectionString);

tests/MongoDB.Driver.Core.Tests/Core/Configuration/ServerSettingsTests.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,21 @@ namespace MongoDB.Driver.Core.Configuration
2121
{
2222
public class ServerSettingsTests
2323
{
24-
private static readonly ServerSettings __defaults = new ServerSettings();
24+
[Fact]
25+
public void DefaultHeartbeatInterval_should_return_expected_result()
26+
{
27+
var result = ServerSettings.DefaultHeartbeatInterval;
28+
29+
result.Should().Be(TimeSpan.FromSeconds(10));
30+
}
31+
32+
[Fact]
33+
public void DefaultHeartbeatTimeout_should_return_expected_result()
34+
{
35+
var result = ServerSettings.DefaultHeartbeatTimeout;
36+
37+
result.Should().Be(TimeSpan.FromSeconds(10));
38+
}
2539

2640
[Fact]
2741
public void constructor_should_initialize_instance()
@@ -56,7 +70,7 @@ public void constructor_with_heartbeatInterval_should_initialize_instance()
5670
var subject = new ServerSettings(heartbeatInterval: heartbeatInterval);
5771

5872
subject.HeartbeatInterval.Should().Be(heartbeatInterval);
59-
subject.HeartbeatTimeout.Should().Be(__defaults.HeartbeatTimeout);
73+
subject.HeartbeatTimeout.Should().Be(ServerSettings.DefaultHeartbeatTimeout);
6074
}
6175

6276
[Fact]
@@ -66,7 +80,7 @@ public void constructor_with_heartbeatTimeout_should_initialize_instance()
6680

6781
var subject = new ServerSettings(heartbeatTimeout: heartbeatTimeout);
6882

69-
subject.HeartbeatInterval.Should().Be(subject.HeartbeatInterval);
83+
subject.HeartbeatInterval.Should().Be(ServerSettings.DefaultHeartbeatInterval);
7084
subject.HeartbeatTimeout.Should().Be(heartbeatTimeout);
7185
}
7286

tests/MongoDB.Driver.Tests/MongoUrlBuilderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public void TestHeartbeatInterval(int? ms, string formatString, string[] values)
457457
var built = new MongoUrlBuilder { Server = _localhost };
458458
if (heartbeatInterval != null) { built.HeartbeatInterval = heartbeatInterval.Value; }
459459

460-
var canonicalConnectionString = string.Format(formatString, values[0]).Replace("/?heartbeatFrequency=10s", "");
460+
var canonicalConnectionString = string.Format(formatString, values[0]).Replace("/?heartbeatInterval=10s", "");
461461
foreach (var builder in EnumerateBuiltAndParsedBuilders(built, formatString, values))
462462
{
463463
Assert.Equal(heartbeatInterval ?? ServerSettings.DefaultHeartbeatInterval, builder.HeartbeatInterval);

0 commit comments

Comments
 (0)