Skip to content

Commit 44fff3f

Browse files
committed
CSHARP-2822: StartTransaction doesn't throw an exception when connected to Standalone nodes.
1 parent 02322bc commit 44fff3f

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Please see our [guidelines](CONTRIBUTING.md) for contributing to the driver.
130130
131131
* Chuck Lu https://github.com/chucklu
132132
* Alex Lyman [email protected]
133+
* Tomasz Masternak https://github.com/tmasternak
133134
* John Murphy https://github.com/jsmurphy
134135
* Alexander Nagy [email protected]
135136
* Sridhar Nanjundeswaran https://github.com/sridharn

src/MongoDB.Driver.Core/Core/Bindings/CoreSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,9 @@ private void EnsureTransactionsAreSupported()
469469
{
470470
var serverType = connectedDataBearingServer.Type;
471471

472-
if(serverType == ServerType.Standalone || serverType == ServerType.Unknown)
472+
if (serverType == ServerType.Standalone)
473473
{
474-
throw new NotSupportedException("Transactions are supported only in sharded cluster of replica set deployments.");
474+
throw new NotSupportedException("Standalone servers do not support transactions.");
475475
}
476476
else if (serverType == ServerType.ShardRouter)
477477
{

tests/MongoDB.Driver.Core.Tests/Core/Bindings/CoreSessionTests.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,14 @@ public void EnsureTransactionsAreSupported_should_throw_when_there_are_no_connec
325325
}
326326

327327
[Theory]
328-
[InlineData("NT")]
329-
[InlineData("UT")]
330-
[InlineData("PN")]
331-
[InlineData("PN,ST")]
332-
[InlineData("PT,SN")]
333-
[InlineData("RN")]
334-
[InlineData("RN,RT")]
335-
[InlineData("RT,RN")]
336-
public void EnsureTransactionsAreSupported_should_throw_when_any_connected_data_bearing_server_does_not_support_transactions(string scenarios)
328+
[InlineData("NT", "Standalone servers do not support transactions.")]
329+
[InlineData("PN", "Server version 3.99.99 does not support the Transactions feature.")]
330+
[InlineData("PN,ST", "Server version 3.99.99 does not support the Transactions feature.")]
331+
[InlineData("PT,SN", "Server version 3.99.99 does not support the Transactions feature.")]
332+
[InlineData("RN", "Server version 4.1.5 does not support the ShardedTransactions feature.")]
333+
[InlineData("RN,RT", "Server version 4.1.5 does not support the ShardedTransactions feature.")]
334+
[InlineData("RT,RN", "Server version 4.1.5 does not support the ShardedTransactions feature.")]
335+
public void EnsureTransactionsAreSupported_should_throw_when_any_connected_data_bearing_server_does_not_support_transactions(string scenarios, string expectedMesage)
337336
{
338337
var clusterId = new ClusterId(1);
339338
string unsupportedFeatureName = null;
@@ -360,11 +359,7 @@ public void EnsureTransactionsAreSupported_should_throw_when_any_connected_data_
360359
var exception = Record.Exception(() => subject.EnsureTransactionsAreSupported());
361360

362361
var e = exception.Should().BeOfType<NotSupportedException>().Subject;
363-
e.Message.Should().Match<string>(
364-
s => s.Contains($"does not support the {unsupportedFeatureName} feature.") ||
365-
s.Contains("Transactions are supported only in sharded cluster of replica set deployments.") ||
366-
s.Contains("StartTransaction cannot determine if transactions are supported because there are no connected servers.")
367-
);
362+
e.Message.Should().Be(expectedMesage);
368363
}
369364

370365
// private methods

0 commit comments

Comments
 (0)