Skip to content

Commit 0c91f30

Browse files
committed
CSHARP-3303: Test for isMaster check frequency added
1 parent f4e6f6e commit 0c91f30

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/MongoDB.Driver.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringProseTests.cs

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

1616
using System;
1717
using System.Collections.Concurrent;
18+
using System.Diagnostics;
1819
using System.Linq;
1920
using System.Threading;
2021
using FluentAssertions;
@@ -74,6 +75,48 @@ public void Heartbeat_should_work_as_expected()
7475
}
7576
}
7677

78+
[SkippableFact]
79+
public void Monitor_sleep_at_least_minHeartbeatFreqencyMS_between_checks()
80+
{
81+
var minVersion = new SemanticVersion(4, 9, 0, "");
82+
RequireServer.Check().VersionGreaterThanOrEqualTo(minVersion);
83+
84+
const string appName = "SDAMMinHeartbeatFrequencyTest";
85+
86+
var failPointCommand = BsonDocument.Parse(
87+
$@"{{
88+
configureFailPoint : 'failCommand',
89+
mode : {{ 'times' : 5 }},
90+
data :
91+
{{
92+
failCommands : [ 'isMaster' ],
93+
errorCode : 1234,
94+
appName : '{appName}'
95+
}}
96+
}}");
97+
98+
var settings = DriverTestConfiguration.GetClientSettings();
99+
100+
// set settings.DirectConnection = true after removing obsolete ConnectionMode
101+
#pragma warning disable CS0618 // Type or member is obsolete
102+
settings.ConnectionMode = ConnectionMode.Direct;
103+
#pragma warning restore CS0618 // Type or member is obsolete
104+
105+
settings.ApplicationName = appName;
106+
settings.ServerSelectionTimeout = TimeSpan.FromSeconds(5);
107+
108+
var cluster = DriverTestConfiguration.Client.Cluster;
109+
using var failPoint = FailPoint.Configure(cluster, NoCoreSession.NewHandle(), failPointCommand);
110+
using var client = DriverTestConfiguration.CreateDisposableClient(settings);
111+
112+
var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName);
113+
var sw = Stopwatch.StartNew();
114+
_ = database.RunCommand<BsonDocument>("{ ping : 1 }");
115+
sw.Stop();
116+
117+
sw.ElapsedMilliseconds.Should().BeInRange(2000, 3500);
118+
}
119+
77120
[SkippableFact]
78121
public void RoundTimeTrip_test()
79122
{

0 commit comments

Comments
 (0)