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
time_monotonically_increases always produces values in the past, and can produce duplicates #5
Comments
I would prefer making time_monotonically_increases start at a base time (the current time). I think any tests relying on incremental increases should be changed to testing relative times (greater-than, less-than). Plus it would avoid getting puzzling errors in the future if someone uses the wrong fudged time. |
I do agree that's safest, but it might result in a lot of test cleanup. What if we keep the existing version but have it use OTOH, if you feel that the test cleanup is quickly manageable, we can go ahead and change the behaviour and release a major version bump. |
(Oh, also the documentation for this function is atrocious. It's not clear what the signature is or how to use it. That should be improved too.) |
Maybe we make the change we want and then trial run the tests to see what kind of issues we'll have. Hopefully it's relatively simple to fix a handful of test cases. We'd also want this default behavior so that relative create times are in-step. E.g. we want stuff created in the layer to be created/modified before any items created in the tests. |
Yeah, good points. OK, so I'll put out a 2.0 with this as default, and you can alternate your version pin to address issues as necessary. Sound good? |
Yep, let's do it |
See PR #6. I think another set of eyeballs on it would be good. |
There are two separate but related issues here.
The first is that if two or more functions are wrapped with
time_monotonically_increases
within the scope of a test (supporttest_foo()
callssetup1
andsetup2
, both of which are wrapped), duplicate times will be produced (both starting at 0). This is not monotonic (although it is within the possibility of the realtime.time
function).Second, the values are always in the past (beginning at 0). If anyone had captured a time before the wrapping took place, the new values will sort earlier, which can be a problem.
Both of these are potential issues when using this function together with ZODB's MappingStorage and DemoStorage. It wants to assign transaction IDs for every commit based on the current timestamp. Lookup of objects is partially based on these timestamps. If timestamps repeat or are in the past of where they should be, baffling errors can result:
Here,
'\x00\x00\x00\x00\x00\x00\x00\x00'
is the root OID, which is guaranteed to exist (and this exception is raised if it isn't found). Examining the storage, we see a mix of timestamp values; the most recent timestamp, recorded by the outside storage is in the past (76.0 seconds):Contrast with this value, which is clearly a real time stamp:
Both of these problems can be avoided if t_m_i produces times starting with the real time, and also keeps a global value to increment. Something like:
This may need to be optional or in a different function, because I'm sure there are tests relying on the sequence being repeatable and starting at a known value.
Thoughts @jzuech3 @papachoco ?
The text was updated successfully, but these errors were encountered: