Opened 19 years ago
Closed 19 years ago
#1849 closed defect (fixed)
[PATCH] Attachments test fails due to identical timestamps
Reported by: | Owned by: | Christian Boos | |
---|---|---|---|
Priority: | high | Milestone: | 0.9 |
Component: | general | Version: | 0.8.4 |
Severity: | minor | Keywords: | |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description (last modified by )
The Trac 'attachments' test adds two attachments to the database, and checks that they are added in the correct order (one after another). It checks this order by sorting the attachments by time. On fast machines, these two attachments are added to the database so quickly that they show up with exactly the same timestamp. As a result, the sort order is undefined and the test frequently fails.
To fix this test failure, I have added a two microsecond "sleep_for_timestamps" function. This ensures that the two attachments are added with different timestamps.
- trac/tests/util.py: (AttachmentTestCase.test_insert): Sleep for two microseconds in between adding new attachments so as to ensure different timestamps and a consistent ordering.
- trac/util.py: (sleep_for_timestamps): Add sleep_for_timestamps function.
-
trac/tests/attachment.py
2 2 from trac.config import Configuration 3 3 from trac.log import logger_factory 4 4 from trac.test import EnvironmentStub, Mock 5 from trac.util import sleep_for_timestamps 5 6 6 7 import os 7 8 import os.path … … 58 59 def test_insert(self): 59 60 attachment = Attachment(self.env, 'ticket', 42) 60 61 attachment.insert('foo.txt', tempfile.TemporaryFile(), 0) 62 sleep_for_timestamps() 61 63 attachment = Attachment(self.env, 'ticket', 42) 62 64 attachment.insert('bar.jpg', tempfile.TemporaryFile(), 0) 63 65 -
trac/util.py
26 26 import time 27 27 import tempfile 28 28 import re 29 import time 29 30 30 31 TRUE = ['yes', '1', 1, 'true', 'on', 'aye'] 31 32 FALSE = ['no', '0', 0, 'false', 'off', 'nay'] … … 381 382 return '</span>' 382 383 return '<span class="code-%s">' % mtype 383 384 385 def sleep_for_timestamps(): 386 granularity = 0.002 387 time.sleep(granularity)
Attachments (1)
Change History (5)
by , 19 years ago
comment:1 by , 19 years ago
Looks like the patch got mangled in the text of the report, so I attached it as "patch.txt".
Cheers,
David James
comment:2 by , 19 years ago
We should probably increase the sleep there from 0.002 to 0.02. I've found that 2 milliseconds isn't enough — we need at least 1/60th of a second to ensure safe timestamps.
comment:3 by , 19 years ago
Description: | modified (diff) |
---|---|
Milestone: | → 0.9 |
Owner: | changed from | to
Priority: | normal → high |
Severity: | normal → minor |
Status: | new → assigned |
I just upgraded to pysqlite2 2.0.4 … and got hit by this one :)
comment:4 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Applied in r2310. Thanks!
(and sorry for not having done that earlier, you told me about it in July, IIRC :) )
Patch to solve this issue