Commit c6f3c3f5 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8bfa791b
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
"""wcfs_test tests wcfs filesystem from outside as python client process""" """wcfs_test tests wcfs filesystem from outside as python client process"""
from __future__ import print_function from __future__ import print_function, absolute_import
from wendelin.lib.testing import getTestDB from wendelin.lib.testing import getTestDB
from wendelin.lib.zodb import dbclose from wendelin.lib.zodb import dbclose
...@@ -34,6 +34,7 @@ from persistent.timestamp import TimeStamp ...@@ -34,6 +34,7 @@ from persistent.timestamp import TimeStamp
from ZODB.utils import z64, u64, p64 from ZODB.utils import z64, u64, p64
import sys, os, os.path, subprocess, threading, inspect, traceback, re import sys, os, os.path, subprocess, threading, inspect, traceback, re
from time import gmtime
from errno import EINVAL from errno import EINVAL
from golang import go, chan, select, func, defer from golang import go, chan, select, func, defer
from golang import context, sync, time from golang import context, sync, time
...@@ -1749,16 +1750,36 @@ def tidtime(tid): ...@@ -1749,16 +1750,36 @@ def tidtime(tid):
# NOTE pytest.approx supports only ==, not e.g. <, so we use plain round. # NOTE pytest.approx supports only ==, not e.g. <, so we use plain round.
return round(t, 6) return round(t, 6)
# tidfromtime converts time into corresponding transacton ID.
def tidfromtime(t):
f = t - int(t) # fraction of seconds
t = int(t)
_ = gmtime(t)
s = _.tm_sec + f # total seconds
ts = TimeStamp(_.tm_year, _.tm_mon, _.tm_mday, _.tm_hour, _.tm_min, s)
return ts.raw()
# verify that tidtime is precise enough to show difference in between transactions. # verify that tidtime is precise enough to show difference in between transactions.
# verify that tidtime -> tidfromtime is identity withing rounding tolerance.
@func @func
def test_tidtime_notrough(): def test_tidtime():
t = tDB() t = tDB()
defer(t.close) defer(t.close)
atprev = t.commit() # tidtime not rough
atv = [t.commit()]
for i in range(10): for i in range(10):
at = t.commit() at = t.commit()
assert tidtime(at) > tidtime(atprev) assert tidtime(at) > tidtime(atv[-1])
atv.append(at)
# tidtime -> tidfromtime
for at in atv:
tat = tidtime(at)
at_ = tidfromtime(tat)
tat_ = tidtime(at_)
assert abs(tat_ - tat) <= 2E-6
# tAt is bytes whose repr returns human readable string considering it as `at` under tDB. # tAt is bytes whose repr returns human readable string considering it as `at` under tDB.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment