Skip to content

Commit d3ad5ae

Browse files
CSHARP-4071: Fix flaky Connection_timeout_should_throw_expected_exception test. (mongodb#744)
1 parent 5d8edc1 commit d3ad5ae

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

tests/MongoDB.Driver.Tests/Jira/CSharp3188Tests.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ public void Connection_timeout_should_throw_expected_exception([Values(false, tr
7474
mongoConnectionException.ContainsSocketTimeoutException.Should().BeFalse();
7575
#pragma warning restore CS0618 // Type or member is obsolete
7676
mongoConnectionException.ContainsTimeoutException.Should().BeTrue();
77-
mongoConnectionException
78-
.InnerException.Should().BeOfType<TimeoutException>().Subject
79-
.InnerException.Should().BeNull();
77+
var baseException = GetBaseException(mongoConnectionException);
78+
baseException.Should().BeOfType<TimeoutException>().Which.InnerException.Should().BeNull();
8079
}
8180
else
8281
{
@@ -87,13 +86,23 @@ public void Connection_timeout_should_throw_expected_exception([Values(false, tr
8786
mongoConnectionException.ContainsSocketTimeoutException.Should().BeTrue();
8887
#pragma warning restore CS0618 // Type or member is obsolete
8988
mongoConnectionException.ContainsTimeoutException.Should().BeTrue();
90-
var socketException = mongoConnectionException
91-
.InnerException.Should().BeOfType<IOException>().Subject
92-
.InnerException.Should().BeOfType<SocketException>().Subject;
89+
var baseException = GetBaseException(mongoConnectionException);
90+
var socketException = baseException.Should().BeOfType<IOException>()
91+
.Which.InnerException.Should().BeOfType<SocketException>().Subject;
9392
socketException.SocketErrorCode.Should().Be(SocketError.TimedOut);
9493
socketException.InnerException.Should().BeNull();
9594
}
9695
}
96+
97+
Exception GetBaseException(MongoConnectionException mongoConnectionException)
98+
{
99+
while (mongoConnectionException.InnerException is MongoConnectionException innerException)
100+
{
101+
// https://jira.mongodb.org/browse/CSHARP-3895
102+
mongoConnectionException = innerException;
103+
}
104+
return mongoConnectionException.InnerException;
105+
}
97106
}
98107
}
99108
}

0 commit comments

Comments
 (0)