Skip to content

Commit

Permalink
merge 3.3-slp (Stackless python#117, fix test cases)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anselm Kruis committed Mar 17, 2017
2 parents e0f01d1 + 3555a21 commit dc3cfaf
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
11 changes: 10 additions & 1 deletion Stackless/unittests/test_miscell.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
withThreads = False

from support import test_main # @UnusedImport
from support import StacklessTestCase, AsTaskletTestCase, require_one_thread
from support import StacklessTestCase, AsTaskletTestCase, require_one_thread, testcase_leaks_references


def is_soft():
Expand Down Expand Up @@ -613,18 +613,22 @@ def other_thread_main():
tlet.kill()

@unittest.skipUnless(withThreads, "requires thread support")
@testcase_leaks_references("chatches TaskletExit and does not die in its own thread", soft_switching=False)
def test_kill_without_thread_state_nl0(self):
return self._test_kill_without_thread_state(0, False)

@unittest.skipUnless(withThreads, "requires thread support")
@testcase_leaks_references("chatches TaskletExit and does not die in its own thread")
def test_kill_without_thread_state_nl1(self):
return self._test_kill_without_thread_state(1, False)

@unittest.skipUnless(withThreads, "requires thread support")
@testcase_leaks_references("chatches TaskletExit and does not die in its own thread", soft_switching=False)
def test_kill_without_thread_state_blocked_nl0(self):
return self._test_kill_without_thread_state(0, True)

@unittest.skipUnless(withThreads, "requires thread support")
@testcase_leaks_references("chatches TaskletExit and does not die in its own thread")
def test_kill_without_thread_state_blocked_nl1(self):
return self._test_kill_without_thread_state(1, True)

Expand Down Expand Up @@ -1098,6 +1102,7 @@ def test():
self.assertEqual(self.recursion_depth_in_test, 1)

@unittest.skipUnless(withThreads, "requires thread support")
@testcase_leaks_references("Tasklet chatches TaskletExit and refuses to die in its thread")
def test_unbind_fail_cstate_no_thread(self):
# https://bitbucket.org/stackless-dev/stackless/issues/92
loop = True
Expand Down Expand Up @@ -1257,6 +1262,10 @@ def test_nesting_level(self):
self.assertIsInstance(l1, int)

def test_chain(self):
# create at least one additional C-stack
t = stackless.tasklet(apply_not_stackless)(stackless.main.switch,)
t.run()
self.addCleanup(t.run)
start = stackless.main.cstate
c = start.next
self.assertIsNot(c, start)
Expand Down
10 changes: 6 additions & 4 deletions Stackless/unittests/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,13 @@ def b():
def c():
return b()

try:
c()
except ZeroDivisionError:
tb = sys.exc_info()[2]
def d():
try:
c()
except ZeroDivisionError:
return sys.exc_info()[2]

tb = d() # this way tb dosn't reference the current frame
innerframes_orig = inspect.getinnerframes(tb)
p = self.dumps(tb)
tb2 = self.loads(p)
Expand Down
4 changes: 3 additions & 1 deletion Stackless/unittests/test_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from stackless import _test_nostacklesscall as apply_not_stackless

from support import test_main # @UnusedImport
from support import StacklessTestCase, AsTaskletTestCase
from support import StacklessTestCase, AsTaskletTestCase, testcase_leaks_references
try:
import threading
try:
Expand All @@ -18,6 +18,7 @@
withThreads = True
except:
withThreads = False

class threading(object):
Thread = object

Expand Down Expand Up @@ -400,6 +401,7 @@ def test_rebind_from_dead(self):
t.bind_thread()
self.assertEqual(t.thread_id, stackless.getcurrent().thread_id)

@testcase_leaks_references("test catches TaskletExit and refuses to die in its own thread")
def test_rebind_from_dead_fail_cstate(self):
# A test for https://bitbucket.org/stackless-dev/stackless/issues/92
loop = True
Expand Down
16 changes: 11 additions & 5 deletions Stackless/unittests/test_tpflags_have_stackless_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,18 @@ def func(obj=None):
obj.nesting_level = stackless.current.nesting_level
return None

cls(func).__class__ # the first access of __class__ releases 1 ref to None
with stackless.atomic():
# None-refcount it needs protection, it the test suite is multithreaded
# None-refcount needs protection, it the test suite is multithreaded
gc.collect()
rc_none = sys.getrefcount(None)
rc_cls = sys.getrefcount(cls)
rc_none = rc_none2 = sys.getrefcount(None)
rc_cls = rc_cls2 = sys.getrefcount(cls)
c = cls(func)
self.assertEqual(sys.getrefcount(None), rc_none)
self.assertEqual(sys.getrefcount(c) - sys.getrefcount(object()), 1)
rc_none2 = sys.getrefcount(None)
rc_cls2 = sys.getrefcount(cls)
self.assertEqual(rc_none, rc_none2)
self.assertEqual(rc_cls + 1, rc_cls2) # one ref for c
self.assertEqual(sys.getrefcount(c) - sys.getrefcount(object()), 1)
self.assertIs(c.__class__, cls)
current_nesting_level = stackless.current.nesting_level
if hasattr(c, "nesting_level"):
Expand Down Expand Up @@ -328,6 +332,7 @@ def helper():
return emsg
self.fail("does not raise the expected exception")

helper() # warm up.
gc.collect()
with stackless.atomic():
rc_none = sys.getrefcount(None)
Expand Down Expand Up @@ -367,6 +372,7 @@ def helper():
self.fail("does not raise the expected exception")

emsg = ''
helper() # warm up
gc.collect()
with stackless.atomic():
rc_none = sys.getrefcount(None)
Expand Down
3 changes: 2 additions & 1 deletion Stackless/unittests/test_watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ def runner_func():

def _test_watchdog_on_tasklet(self, soft):
def runner_func():
stackless.run(2, soft=soft, totaltimeout=True, ignore_nesting=True)
# run the watchdog long enough to start t1 and t2
stackless.run(150, soft=soft, totaltimeout=True, ignore_nesting=True)
if stackless.getruncount():
self.done += 1 # we were interrupted
t1.kill()
Expand Down

0 comments on commit dc3cfaf

Please sign in to comment.