From 678eadde4a2640a33cd288a565f74366433fb44f Mon Sep 17 00:00:00 2001 From: Matthew Russotto Date: Fri, 24 Jan 2020 12:47:49 -0500 Subject: SERVER-45761 Use same clock for test and working code in session_test [v4.0] --- src/mongo/db/session_test.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/mongo/db/session_test.cpp b/src/mongo/db/session_test.cpp index 5e8424db7c3..e16f0a74663 100644 --- a/src/mongo/db/session_test.cpp +++ b/src/mongo/db/session_test.cpp @@ -698,12 +698,9 @@ TEST_F(SessionTest, StashAndUnstashResources) { } TEST_F(SessionTest, ReportStashedResources) { - Date_t startTime = Date_t::now(); - - // Sleep a bit after recording the startTime but before starting the transaction to account for - // any clock discrepancy between the Date_t clock and the clock used to track the transaction - // stats start time. - mongo::sleepmillis(10); + // The transaction participant uses the precise clock source for timing, + // so ensure we use the same clock source for testing. + Date_t startTime = opCtx()->getServiceContext()->getPreciseClockSource()->now(); const auto sessionId = makeLogicalSessionIdForTest(); const TxnNumber txnNum = 20; @@ -803,12 +800,9 @@ TEST_F(SessionTest, ReportStashedResources) { } TEST_F(SessionTest, ReportUnstashedResources) { - Date_t startTime = Date_t::now(); - - // Sleep a bit after recording the startTime but before starting the transaction to account for - // any clock discrepancy between the Date_t clock and the clock used to track the transaction - // stats start time. - mongo::sleepmillis(10); + // The transaction participant uses the precise clock source for timing, + // so ensure we use the same clock source for testing. + Date_t startTime = opCtx()->getServiceContext()->getPreciseClockSource()->now(); const auto sessionId = makeLogicalSessionIdForTest(); const TxnNumber txnNum = 20; -- cgit v1.2.1