Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use '5 years ago' instead of absolute timestamp #453

Merged
merged 2 commits into from
Jan 3, 2018

Conversation

meejah
Copy link
Contributor

@meejah meejah commented Dec 20, 2017

Fix a test broken by the slow march of time

@codecov-io
Copy link

codecov-io commented Dec 20, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@5e62118). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##             master    #453   +/-   ##
========================================
  Coverage          ?   90.1%           
========================================
  Files             ?     144           
  Lines             ?   27301           
  Branches          ?    3929           
========================================
  Hits              ?   24599           
  Misses            ?    1961           
  Partials          ?     741

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e62118...5f00842. Read the comment docs.

@@ -303,7 +306,7 @@ def json_for_cap(options, cap):
"size": 1234,
"metadata": {
"tahoe": {
"linkcrtime": 0.0,
"linkcrtime": (time.time() - (5 * secs_per_year)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also work around the boundary conditions? In particular, I notice that secs_per_year is not always correct (since not all years have the same number of seconds). Will this cause the test to fail if run close enough to the year change-over? I guess any 5 year period will include either one or two leap years (intuitively; I haven't proven it). If it includes 1 leap year, then "5 years ago" is actually an additional 24 * 60 * 60 seconds ago. And if it includes 2 leap years, twice that addition.

So if this code runs on year X, Dec 31, 11PM then 5 * secs_per_year ago is around year X-4, Jan 1, 11PM (or even Jan 2 for ranges including two leap years). This is still pretty close to 5 years ago but I haven't checked to see what the code that actually computes the "N years ago" string does.

If it behaves correctly, maybe it's still worth a comment somewhere around here that it's okay. And if not,

now = datetime.now()
then = now.replace(year=now.year-5)
five_year_interval = (now - then).total_seconds()

gives the true number of seconds for that particular 5 year window.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also mock time.time() during the code that measures the interval, to make it deterministic?

BTW I filed https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2901 before seeing this PR (I assumed it was already an end-of-year problem, but I guess it was a too-much-time-has-passed problem).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that we need to mock time -- IMO, the "human readable output code" should output "5 years ago" regardless of a few seconds (or even days) difference in the interval length -- that said I haven't looked at what it actually does ...

@meejah
Copy link
Contributor Author

meejah commented Jan 3, 2018

Okay, I used @exarkun's more-exact method of computing the number of seconds in 5 years. I don't think we should mock time().

@meejah meejah merged commit c351a1d into tahoe-lafs:master Jan 3, 2018
@meejah meejah deleted the magic-folder-test-time branch January 3, 2018 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants