Skip to content

Commit 104af11

Browse files
authored
Merge pull request #15692 from Automattic/vkarpov15/gh-14949
fix(connection): snapshot Date so stale heartbeat check protects against useFakeTimers
2 parents dd39133 + 472d2c8 commit 104af11

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/connection.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const decorateBulkWriteResult = require('./helpers/model/decorateBulkWriteResult
2828
const arrayAtomicsSymbol = require('./helpers/symbols').arrayAtomicsSymbol;
2929
const sessionNewDocuments = require('./helpers/symbols').sessionNewDocuments;
3030

31+
// Snapshot the native Date constructor to ensure both Date.now() and new Date() (and other Date methods)
32+
// bypass timer mocks such as those set up by useFakeTimers().
33+
const Date = globalThis.Date;
34+
3135
/**
3236
* A list of authentication mechanisms that don't require a password for authentication.
3337
* This is used by the authMechanismDoesNotRequirePassword method.

0 commit comments

Comments
 (0)