From f58db6ce223474b71ccc6fc6604da64b7879367d Mon Sep 17 00:00:00 2001 From: Curt Hagenlocher Date: Mon, 24 Nov 2025 12:46:24 -0800 Subject: [PATCH] Fix flaky test Fix flaky test by using the more-accurate `Stopwatch` instead of `DateTime.UtcNow`. --- .../Auth/MandatoryTokenExchangeDelegatingHandlerTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/csharp/test/Drivers/Databricks/Unit/Auth/MandatoryTokenExchangeDelegatingHandlerTests.cs b/csharp/test/Drivers/Databricks/Unit/Auth/MandatoryTokenExchangeDelegatingHandlerTests.cs index 5da898ded6..9bed0463c2 100644 --- a/csharp/test/Drivers/Databricks/Unit/Auth/MandatoryTokenExchangeDelegatingHandlerTests.cs +++ b/csharp/test/Drivers/Databricks/Unit/Auth/MandatoryTokenExchangeDelegatingHandlerTests.cs @@ -16,6 +16,7 @@ */ using System; +using System.Diagnostics; using System.Linq; using System.Net; using System.Net.Http; @@ -167,9 +168,10 @@ public async Task SendAsync_WithExternalToken_BlocksUntilTokenExchangeCompletes( var httpClient = new HttpClient(handler); // First request should block until token exchange completes, then use exchanged token - var startTime = DateTime.UtcNow; + var stopwatch = Stopwatch.StartNew(); var response = await httpClient.SendAsync(request); - var requestDuration = DateTime.UtcNow - startTime; + stopwatch.Stop(); + var requestDuration = stopwatch.Elapsed; Assert.Equal(expectedResponse, response); Assert.True(requestDuration >= tokenExchangeDelay,