From bac51f3498a4f300e8b7679d605cabeea6f5b761 Mon Sep 17 00:00:00 2001 From: Oleksandr Poliakov Date: Thu, 18 Sep 2025 16:34:43 -0700 Subject: [PATCH] CSHARP-5738: Increase heartbeat interval and timeout if debugger is attached --- .../Core/CoreTestConfiguration.cs | 12 ++++++++++-- .../DriverTestConfiguration.cs | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/MongoDB.Driver.TestHelpers/Core/CoreTestConfiguration.cs b/tests/MongoDB.Driver.TestHelpers/Core/CoreTestConfiguration.cs index ede30c727af..8919c1d79c9 100644 --- a/tests/MongoDB.Driver.TestHelpers/Core/CoreTestConfiguration.cs +++ b/tests/MongoDB.Driver.TestHelpers/Core/CoreTestConfiguration.cs @@ -29,7 +29,6 @@ using MongoDB.Driver.Core.Operations; using MongoDB.Driver.Core.Servers; using MongoDB.Driver.Core.WireProtocol.Messages.Encoders; -using MongoDB.Driver.Encryption; using MongoDB.Driver.TestHelpers; using Xunit.Sdk; @@ -127,7 +126,16 @@ public static ClusterBuilder ConfigureCluster(ClusterBuilder builder) { builder = builder .ConfigureWithConnectionString(__connectionString.Value, __serverApi.Value) - .ConfigureCluster(c => c.With(serverSelectionTimeout: __defaultServerSelectionTimeout.Value)); + .ConfigureCluster(c => c.With(serverSelectionTimeout: __defaultServerSelectionTimeout.Value)) + .ConfigureServer(s => + { + if (Debugger.IsAttached) + { + s = s.With(heartbeatTimeout: TimeSpan.FromDays(1), serverMonitoringMode: ServerMonitoringMode.Poll); + } + + return s; + });; if (__connectionString.Value.Tls.HasValue && __connectionString.Value.Tls.Value && diff --git a/tests/MongoDB.Driver.TestHelpers/DriverTestConfiguration.cs b/tests/MongoDB.Driver.TestHelpers/DriverTestConfiguration.cs index 4a266dbb70a..2a710c6ee8b 100644 --- a/tests/MongoDB.Driver.TestHelpers/DriverTestConfiguration.cs +++ b/tests/MongoDB.Driver.TestHelpers/DriverTestConfiguration.cs @@ -24,7 +24,6 @@ using MongoDB.Driver.Core.Clusters; using MongoDB.Driver.Core.Configuration; using MongoDB.Driver.Core.Connections; -using MongoDB.Driver.Core.Logging; using MongoDB.Driver.Core.Servers; using MongoDB.Driver.Encryption; @@ -184,6 +183,13 @@ public static MongoClientSettings GetClientSettings() { serverSelectionTimeoutString = "30000"; } + + if (System.Diagnostics.Debugger.IsAttached) + { + clientSettings.HeartbeatTimeout = TimeSpan.FromDays(1); + clientSettings.ServerMonitoringMode = ServerMonitoringMode.Poll; + } + clientSettings.ServerSelectionTimeout = TimeSpan.FromMilliseconds(int.Parse(serverSelectionTimeoutString)); clientSettings.ClusterConfigurator = cb => CoreTestConfiguration.ConfigureLogging(cb); clientSettings.ServerApi = CoreTestConfiguration.ServerApi;