summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-12-29 19:16:42 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-12-29 19:16:42 -0500
commit308fc8a6b1a6481a143964d89ac167cfa1f76005 (patch)
tree0978440803c1d14144ba1c6e7074a4d02c6f339e
parent7ce0b40fe7dc88ce2533f78e2cdc467f2d450836 (diff)
downloadpython-coveragepy-git-308fc8a6b1a6481a143964d89ac167cfa1f76005.tar.gz
A test that isn't used yet, to test the refcount problem fixed this morning
-rw-r--r--tests/test_oddball.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/test_oddball.py b/tests/test_oddball.py
index e1099e62..b481131a 100644
--- a/tests/test_oddball.py
+++ b/tests/test_oddball.py
@@ -6,6 +6,7 @@
import sys
import coverage
+from coverage import env
from coverage.files import abs_file
from tests.coveragetest import CoverageTest
@@ -183,6 +184,42 @@ class MemoryLeakTest(CoverageTest):
self.fail("RAM grew by %d" % (ram_growth))
+class MemoryFumblingTest(CoverageTest):
+ """Test that we properly manage the None refcount."""
+
+ def test_dropping_none(self):
+ if not env.C_TRACER:
+ self.skipTest("Only the C tracer has refcounting issues")
+ # TODO: Mark this so it will only be run sometimes.
+ self.skipTest("This is too expensive for now (30s)")
+ # Start and stop coverage thousands of times to flush out bad
+ # reference counting, maybe.
+ self.make_file("the_code.py", """\
+ import random
+ def f():
+ if random.random() > .5:
+ x = 1
+ else:
+ x = 2
+ """)
+ self.make_file("main.py", """\
+ import coverage
+ import sys
+ from the_code import f
+ for i in range(10000):
+ cov = coverage.Coverage(branch=True)
+ cov.start()
+ f()
+ cov.stop()
+ cov.erase()
+ print("Final None refcount: %d" % (sys.getrefcount(None)))
+ """)
+ status, out = self.run_command_status("python main.py")
+ self.assertEqual(status, 0)
+ self.assertIn("Final None refcount", out)
+ self.assertNotIn("Fatal", out)
+
+
class PyexpatTest(CoverageTest):
"""Pyexpat screws up tracing. Make sure we've counter-defended properly."""