Edgewall Software

Opened 16 years ago

Closed 16 years ago

#1849 closed defect (fixed)

[PATCH] Attachments test fails due to identical timestamps

Reported by: james@… 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 Christian Boos)

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

    22from trac.config import Configuration
    33from trac.log import logger_factory
    44from trac.test import EnvironmentStub, Mock
     5from trac.util import sleep_for_timestamps
    67import os
    78import os.path
    5859    def test_insert(self):
    5960        attachment = Attachment(self.env, 'ticket', 42)
    6061        attachment.insert('foo.txt', tempfile.TemporaryFile(), 0)
     62        sleep_for_timestamps()
    6163        attachment = Attachment(self.env, 'ticket', 42)
    6264        attachment.insert('bar.jpg', tempfile.TemporaryFile(), 0)
  • trac/util.py

    2626import time
    2727import tempfile
    2828import re
     29import time
    3031TRUE =  ['yes', '1', 1, 'true',  'on',  'aye']
    3132FALSE = ['no',  '0', 0, 'false', 'off', 'nay']
    381382                    return '</span>'
    382383                return '<span class="code-%s">' % mtype
     385def sleep_for_timestamps():
     386  granularity = 0.002
     387  time.sleep(granularity)

Attachments (1)

patch.txt (1.2 KB ) - added by anonymous 16 years ago.
Patch to solve this issue

Download all attachments as: .zip

Change History (5)

by anonymous, 16 years ago

Attachment: patch.txt added

Patch to solve this issue

comment:1 by james@…, 16 years ago

Looks like the patch got mangled in the text of the report, so I attached it as "patch.txt".


David James

comment:2 by james@…, 16 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 Christian Boos, 16 years ago

Description: modified (diff)
Milestone: 0.9
Owner: changed from Jonas Borgström to Christian Boos
Priority: normalhigh
Severity: normalminor
Status: newassigned

I just upgraded to pysqlite2 2.0.4 … and got hit by this one :)

comment:4 by Christian Boos, 16 years ago

Resolution: fixed
Status: assignedclosed

Applied in r2310. Thanks!

(and sorry for not having done that earlier, you told me about it in July, IIRC :) )

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.