summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_logging.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-24 07:14:26 (GMT)
committerGitHub <noreply@github.com>2024-06-24 07:14:26 (GMT)
commit544a47212b92f52ceffbd50275c6b0c57a446a98 (patch)
tree7ad39158391255a0639226e83790b8877fd018b4 /Lib/test/test_logging.py
parentb7240ed3f09ffb4bb8bffac3a1ff88b1e99afa26 (diff)
downloadcpython-544a47212b92f52ceffbd50275c6b0c57a446a98.zip
cpython-544a47212b92f52ceffbd50275c6b0c57a446a98.tar.gz
cpython-544a47212b92f52ceffbd50275c6b0c57a446a98.tar.bz2
[3.13] gh-120683: Fix an error in logging.LogRecord timestamp (GH-120709) (GH-120933)
The integer part of the timestamp can be rounded up, while the millisecond calculation truncates, causing the log timestamp to be wrong by up to 999 ms (affected roughly 1 in 8 million timestamps). (cherry picked from commit 1500a23f33f5a6d052ff1ef6383d9839928b8ff1) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r--Lib/test/test_logging.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 504862a..c78e76d 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -4648,13 +4648,18 @@ class FormatterTest(unittest.TestCase, AssertErrorMessage):
(1_677_902_297_100_000_000, 100.0), # exactly 100ms
(1_677_903_920_999_998_503, 999.0), # check truncating doesn't round
(1_677_903_920_000_998_503, 0.0), # check truncating doesn't round
+ (1_677_903_920_999_999_900, 0.0), # check rounding up
)
for ns, want in tests:
with patch('time.time_ns') as patched_ns:
patched_ns.return_value = ns
record = logging.makeLogRecord({'msg': 'test'})
- self.assertEqual(record.msecs, want)
- self.assertEqual(record.created, ns / 1e9)
+ with self.subTest(ns):
+ self.assertEqual(record.msecs, want)
+ self.assertEqual(record.created, ns / 1e9)
+ self.assertAlmostEqual(record.created - int(record.created),
+ record.msecs / 1e3,
+ delta=1e-3)
def test_relativeCreated_has_higher_precision(self):
# See issue gh-102402.