Hi!

I thought that the answer to the question in the title is "yes", and
indeed one can assume that the random generator is in a defined state.

However, working on two tickets that fix several memory leaks by using
weak references (#715 and #11521, both needing review, by the way), I
found that sometimes tests fail because of missing garbage collection:
When I insert
 sage: import gc
 sage: _ = gc.collect()
at the beginning of these tests, then they work.

That makes me wonder: Should the doctest framework always do a garbage
collection before starting a new test?

I am not sure what I'd prefer.

On the one hand, missing garbage collection can give rise to nasty
side effects of one test to other tests. For example:
 (1) One test creates some ring, demonstrating a wrong usage for
educational reasons; another test may use the same ring in a proper
way, but only finds the broken ring in cache. A crash may result,
depending on the order in which these tests are executed.
 (2) With the patches from #715 and 15521, polynomial rings can be
garbage collected (in unpatched Sage, they are immortal). That gives
rise to a failure of the test of
sage.libs.singular.ring.singular_ring_reference: The test inspects
references to rings kept in memory. To my understanding, an error
resulted from a garbage collection happening in the middle of the
test, so that the number of rings kept in memory at the beginning of
the test differed from the number of rings at the end of the test.

On the other hand, one could argue that garbage collection at the
beginning of each tests is a waste of time. Tests like
sage.libs.singular.ring.singular_ring_reference (inspecting
references) are not very frequent, and thus it would be easy to make
garbage collection explicitly only in these few cases.

What do you think?

Best regards,
Simon

-- 
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to