Migrated test_threading_local to be a patching test. Discovered that it's actually failing, but the way it was previously written the failures were masked.
This commit is contained in:
17
tests/stdlib/test_threading_local.py
Normal file
17
tests/stdlib/test_threading_local.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from eventlet.green import thread
|
||||||
|
from eventlet.green import threading
|
||||||
|
from eventlet.green import time
|
||||||
|
|
||||||
|
from test import test_threading_local
|
||||||
|
|
||||||
|
test_threading_local.threading = threading
|
||||||
|
|
||||||
|
def test_main():
|
||||||
|
import sys
|
||||||
|
sys.modules['thread'] = thread
|
||||||
|
sys.modules['threading'] = threading
|
||||||
|
sys.modules['time'] = time
|
||||||
|
test_threading_local.test_main()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
test_main()
|
@@ -1,55 +0,0 @@
|
|||||||
import unittest
|
|
||||||
from doctest import DocTestSuite
|
|
||||||
from tests import test_support
|
|
||||||
|
|
||||||
class ThreadingLocalTest(unittest.TestCase):
|
|
||||||
def test_derived(self):
|
|
||||||
# Issue 3088: if there is a threads switch inside the __init__
|
|
||||||
# of a threading.local derived class, the per-thread dictionary
|
|
||||||
# is created but not correctly set on the object.
|
|
||||||
# The first member set may be bogus.
|
|
||||||
from eventlet.green import threading
|
|
||||||
from eventlet.green import time
|
|
||||||
class Local(threading.local):
|
|
||||||
def __init__(self):
|
|
||||||
time.sleep(0.01)
|
|
||||||
local = Local()
|
|
||||||
|
|
||||||
def f(i):
|
|
||||||
local.x = i
|
|
||||||
# Simply check that the variable is correctly set
|
|
||||||
self.assertEqual(local.x, i)
|
|
||||||
|
|
||||||
threads= []
|
|
||||||
for i in range(10):
|
|
||||||
t = threading.Thread(target=f, args=(i,))
|
|
||||||
t.start()
|
|
||||||
threads.append(t)
|
|
||||||
|
|
||||||
for t in threads:
|
|
||||||
t.join()
|
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
|
||||||
suite = DocTestSuite('_threading_local')
|
|
||||||
|
|
||||||
try:
|
|
||||||
from eventlet.green.thread import _local
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
import _threading_local
|
|
||||||
local_orig = _threading_local.local
|
|
||||||
def setUp(test):
|
|
||||||
_threading_local.local = _local
|
|
||||||
def tearDown(test):
|
|
||||||
_threading_local.local = local_orig
|
|
||||||
suite.addTest(DocTestSuite('_threading_local',
|
|
||||||
setUp=setUp, tearDown=tearDown)
|
|
||||||
)
|
|
||||||
suite.addTest(unittest.makeSuite(ThreadingLocalTest))
|
|
||||||
|
|
||||||
test_support.run_suite(suite)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_main()
|
|
Reference in New Issue
Block a user