Skip to content

Commit 8099d50

Browse files
CSHARP-3290: LocalThreshold no longer accepts infinite timespan. (#616)
1 parent 877a6e8 commit 8099d50

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public ClusterSettings(
9999
_endPoints = Ensure.IsNotNull(endPoints.WithDefault(__defaultEndPoints), "endPoints").ToList();
100100
_kmsProviders = kmsProviders.WithDefault(null);
101101
_loadBalanced = loadBalanced.WithDefault(false);
102-
_localThreshold = Ensure.IsGreaterThanOrEqualToZero(localThreshold.WithDefault(TimeSpan.FromMilliseconds(15)), "localThreshold");
102+
_localThreshold = Ensure.IsInfiniteOrGreaterThanOrEqualToZero(localThreshold.WithDefault(TimeSpan.FromMilliseconds(15)), "localThreshold");
103103
_maxServerSelectionWaitQueueSize = Ensure.IsGreaterThanOrEqualToZero(maxServerSelectionWaitQueueSize.WithDefault(500), "maxServerSelectionWaitQueueSize");
104104
_replicaSetName = replicaSetName.WithDefault(null);
105105
_serverApi = serverApi.WithDefault(null);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using System;
1717
using System.Net;
18+
using System.Threading;
1819
using FluentAssertions;
1920
using MongoDB.Bson.TestHelpers.EqualityComparers;
2021
using MongoDB.Driver.Core.Clusters;
@@ -153,6 +154,22 @@ public void constructor_with_locadBalanced_should_initialize_instance()
153154
subject.ServerSelectionTimeout.Should().Be(__defaults.ServerSelectionTimeout);
154155
}
155156

157+
[Fact]
158+
public void constructor_with_infinite_localThreshold_should_initialize_instance()
159+
{
160+
#pragma warning disable CS0618 // Type or member is obsolete
161+
var subject = new ClusterSettings(localThreshold: Timeout.InfiniteTimeSpan);
162+
subject.ConnectionMode.Should().Be(__defaults.ConnectionMode);
163+
#pragma warning restore CS0618 // Type or member is obsolete
164+
subject.EndPoints.Should().EqualUsing(__defaults.EndPoints, EndPointHelper.EndPointEqualityComparer);
165+
subject.LoadBalanced.Should().BeFalse();
166+
subject.LocalThreshold.Should().Be(Timeout.InfiniteTimeSpan);
167+
subject.MaxServerSelectionWaitQueueSize.Should().Be(__defaults.MaxServerSelectionWaitQueueSize);
168+
subject.ReplicaSetName.Should().Be(__defaults.ReplicaSetName);
169+
subject.Scheme.Should().Be(__defaults.Scheme);
170+
subject.ServerSelectionTimeout.Should().Be(__defaults.ServerSelectionTimeout);
171+
}
172+
156173
[Fact]
157174
public void constructor_with_localThreshold_should_initialize_instance()
158175
{

0 commit comments

Comments
 (0)