Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/MongoDB.Driver/Core/Configuration/ConnectionString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,11 @@ string ProtectConnectionString(string connectionString)
var protectedString = Regex.Replace(connectionString, @"(?<=://)[^/]*(?=@)", "<hidden>");
return protectedString;
}

if (_minPoolSize > _maxPoolSize)
{
throw new MongoConfigurationException("MaxPoolSize should be >= MinPoolSize.");
}
}

private void ParseOption(string name, string value)
Expand Down Expand Up @@ -1055,7 +1060,7 @@ private void ParseOption(string name, string value)
{
throw new MongoConfigurationException("Multiple proxyHost options are not allowed.");
}

_proxyHost = value;
if (_proxyHost.Length == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,25 @@ public void Invalid_srvMaxHosts_configuration_should_throw(string connectionStri
exception.Should().BeOfType<MongoConfigurationException>();
}

[Theory]
[InlineData("mongodb://localhost?maxPoolSize=5&minPoolSize=10", true)]
[InlineData("mongodb://localhost?maxPoolSize=10&minPoolSize=10", false)]
[InlineData("mongodb://localhost?maxPoolSize=10&minPoolSize=5", false)]
[InlineData("mongodb://localhost?maxPoolSize=10", false)]
public void MaxPoolSize_less_than_MinPoolSize_should_throw(string connectionString, bool shouldThrow)
{
var exception = Record.Exception(() => new ConnectionString(connectionString));

if (shouldThrow)
{
exception.Should().BeOfType<MongoConfigurationException>();
}
else
{
exception.Should().BeNull();
}
}

[Fact]
public void When_calling_resolve_on_a_srv_connection_string()
{
Expand Down
6 changes: 3 additions & 3 deletions tests/MongoDB.Driver.Tests/MongoClientSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void TestClone()
var connectionString =
"mongodb://user1:password1@somehost/?appname=app;" +
"connect=direct;connectTimeout=123;ipv6=true;heartbeatInterval=1m;heartbeatTimeout=2m;localThreshold=128;loadBalanced=false;" +
"maxConnecting=3;maxIdleTime=124;maxLifeTime=125;maxPoolSize=126;minPoolSize=127;readConcernLevel=majority;" +
"maxConnecting=3;maxIdleTime=124;maxLifeTime=125;maxPoolSize=127;minPoolSize=126;readConcernLevel=majority;" +
"readPreference=secondary;readPreferenceTags=a:1,b:2;readPreferenceTags=c:3,d:4;socketTimeout=129;" +
"serverMonitoringMode=Stream;serverSelectionTimeout=20s;ssl=true;sslVerifyCertificate=false;waitqueuesize=130;waitQueueTimeout=131;" +
"w=1;fsync=true;journal=true;w=2;wtimeout=131;gssapiServiceName=other;tlsInsecure=true";
Expand Down Expand Up @@ -586,7 +586,7 @@ public void TestFromUrl()
var connectionString =
"mongodb://user1:password1@somehost/?appname=app1;authSource=db;authMechanismProperties=CANONICALIZE_HOST_NAME:true;" +
"compressors=zlib,snappy;zlibCompressionLevel=9;connectTimeout=123;directConnection=true;ipv6=true;heartbeatInterval=1m;heartbeatTimeout=2m;loadBalanced=false;localThreshold=128;" +
"maxConnecting=3;maxIdleTime=124;maxLifeTime=125;maxPoolSize=126;minPoolSize=127;readConcernLevel=majority;" +
"maxConnecting=3;maxIdleTime=124;maxLifeTime=125;maxPoolSize=127;minPoolSize=126;readConcernLevel=majority;" +
"readPreference=secondary;readPreferenceTags=a:1,b:2;readPreferenceTags=c:3,d:4;retryReads=false;retryWrites=true;socketTimeout=129;" +
"serverMonitoringMode=Stream;serverSelectionTimeout=20s;tls=true;sslVerifyCertificate=false;waitqueuesize=130;waitQueueTimeout=131;" +
"w=1;fsync=true;journal=true;w=2;wtimeout=131;gssapiServiceName=other" +
Expand Down Expand Up @@ -686,7 +686,7 @@ public void TestFromUrlTlsInsecure()

[Theory]
[InlineData(0, int.MaxValue)]
[InlineData(126, 126)]
[InlineData(127, 127)]
public void TestFromUrlWithMaxPoolSize(int inputValue, int expectedValue)
{
var connectionString = $"mongodb://the-next-generation/?maxPoolSize={inputValue}";
Expand Down
12 changes: 6 additions & 6 deletions tests/MongoDB.Driver.Tests/MongoUrlBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public void TestAll()
MaxConnecting = 3,
MaxConnectionIdleTime = TimeSpan.FromSeconds(2),
MaxConnectionLifeTime = TimeSpan.FromSeconds(3),
MaxConnectionPoolSize = 4,
MinConnectionPoolSize = 5,
MaxConnectionPoolSize = 5,
MinConnectionPoolSize = 4,
Password = "password",
ReadConcernLevel = ReadConcernLevel.Majority,
ReadPreference = readPreference,
Expand Down Expand Up @@ -138,8 +138,8 @@ public void TestAll()
"maxConnecting=3",
"maxIdleTime=2s",
"maxLifeTime=3s",
"maxPoolSize=4",
"minPoolSize=5",
"maxPoolSize=5",
"minPoolSize=4",
"serverMonitoringMode=Poll",
"serverSelectionTimeout=10s",
"socketTimeout=7s",
Expand Down Expand Up @@ -177,8 +177,8 @@ public void TestAll()
Assert.Equal(TimeSpan.FromSeconds(2), builder.MaxConnectionIdleTime);
Assert.Equal(TimeSpan.FromSeconds(3), builder.MaxConnectionLifeTime);
Assert.Equal(3, builder.MaxConnecting);
Assert.Equal(4, builder.MaxConnectionPoolSize);
Assert.Equal(5, builder.MinConnectionPoolSize);
Assert.Equal(4, builder.MinConnectionPoolSize);
Assert.Equal(5, builder.MaxConnectionPoolSize);
Assert.Equal("password", builder.Password);
Assert.Equal(ReadConcernLevel.Majority, builder.ReadConcernLevel);
Assert.Equal(readPreference, builder.ReadPreference);
Expand Down
13 changes: 6 additions & 7 deletions tests/MongoDB.Driver.Tests/MongoUrlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using MongoDB.Driver.Core.Servers;
using MongoDB.TestHelpers.XunitExtensions;
using Xunit;

namespace MongoDB.Driver.Tests
{
[Trait("Category", "ConnectionString")]
Expand Down Expand Up @@ -172,8 +171,8 @@ public void TestAll()
MaxConnecting = 3,
MaxConnectionIdleTime = TimeSpan.FromSeconds(2),
MaxConnectionLifeTime = TimeSpan.FromSeconds(3),
MaxConnectionPoolSize = 4,
MinConnectionPoolSize = 5,
MaxConnectionPoolSize = 5,
MinConnectionPoolSize = 4,
Password = "password",
ReadConcernLevel = ReadConcernLevel.Majority,
ReadPreference = readPreference,
Expand Down Expand Up @@ -223,8 +222,8 @@ public void TestAll()
"maxConnecting=3",
"maxIdleTime=2s",
"maxLifeTime=3s",
"maxPoolSize=4",
"minPoolSize=5",
"maxPoolSize=5",
"minPoolSize=4",
"serverMonitoringMode=Poll",
"serverSelectionTimeout=10s",
"socketTimeout=7s",
Expand Down Expand Up @@ -260,8 +259,8 @@ public void TestAll()
Assert.Equal(3, url.MaxConnecting);
Assert.Equal(TimeSpan.FromSeconds(2), url.MaxConnectionIdleTime);
Assert.Equal(TimeSpan.FromSeconds(3), url.MaxConnectionLifeTime);
Assert.Equal(4, url.MaxConnectionPoolSize);
Assert.Equal(5, url.MinConnectionPoolSize);
Assert.Equal(5, url.MaxConnectionPoolSize);
Assert.Equal(4, url.MinConnectionPoolSize);
Assert.Equal("password", url.Password);
Assert.Equal(ReadConcernLevel.Majority, url.ReadConcernLevel);
Assert.Equal(readPreference, url.ReadPreference);
Expand Down