Commit 53ea1620 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Make some tests more frienly to MemoryError.

Free memory, unlock hanging threads.
parent 582265f4
...@@ -32,15 +32,24 @@ class Test_OpenGL_libs(unittest.TestCase): ...@@ -32,15 +32,24 @@ class Test_OpenGL_libs(unittest.TestCase):
def setUp(self): def setUp(self):
self.gl = self.glu = self.gle = None self.gl = self.glu = self.gle = None
if lib_gl: if lib_gl:
self.gl = CDLL(lib_gl, mode=RTLD_GLOBAL) try:
self.gl = CDLL(lib_gl, mode=RTLD_GLOBAL)
except OSError:
pass
if lib_glu: if lib_glu:
self.glu = CDLL(lib_glu, RTLD_GLOBAL) try:
self.glu = CDLL(lib_glu, RTLD_GLOBAL)
except OSError:
pass
if lib_gle: if lib_gle:
try: try:
self.gle = CDLL(lib_gle) self.gle = CDLL(lib_gle)
except OSError: except OSError:
pass pass
def tearDown(self):
self.gl = self.glu = self.gle = None
@unittest.skipUnless(lib_gl, 'lib_gl not available') @unittest.skipUnless(lib_gl, 'lib_gl not available')
def test_gl(self): def test_gl(self):
if self.gl: if self.gl:
......
...@@ -7,8 +7,6 @@ ctype_types = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, ...@@ -7,8 +7,6 @@ ctype_types = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
c_long, c_ulong, c_longlong, c_ulonglong, c_double, c_float] c_long, c_ulong, c_longlong, c_ulonglong, c_double, c_float]
python_types = [int, int, int, int, int, long, python_types = [int, int, int, int, int, long,
int, long, long, long, float, float] int, long, long, long, float, float]
LargeNamedType = type('T' * 2 ** 25, (Structure,), {})
large_string = 'T' * 2 ** 25
class PointersTestCase(unittest.TestCase): class PointersTestCase(unittest.TestCase):
...@@ -191,9 +189,11 @@ class PointersTestCase(unittest.TestCase): ...@@ -191,9 +189,11 @@ class PointersTestCase(unittest.TestCase):
self.assertEqual(bool(mth), True) self.assertEqual(bool(mth), True)
def test_pointer_type_name(self): def test_pointer_type_name(self):
LargeNamedType = type('T' * 2 ** 25, (Structure,), {})
self.assertTrue(POINTER(LargeNamedType)) self.assertTrue(POINTER(LargeNamedType))
def test_pointer_type_str_name(self): def test_pointer_type_str_name(self):
large_string = 'T' * 2 ** 25
self.assertTrue(POINTER(large_string)) self.assertTrue(POINTER(large_string))
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -39,8 +39,12 @@ class Bunch(object): ...@@ -39,8 +39,12 @@ class Bunch(object):
self.finished.append(tid) self.finished.append(tid)
while not self._can_exit: while not self._can_exit:
_wait() _wait()
for i in range(n): try:
start_new_thread(task, ()) for i in range(n):
start_new_thread(task, ())
except:
self._can_exit = True
raise
def wait_for_started(self): def wait_for_started(self):
while len(self.started) < self.n: while len(self.started) < self.n:
......
...@@ -357,10 +357,12 @@ class GCTests(unittest.TestCase): ...@@ -357,10 +357,12 @@ class GCTests(unittest.TestCase):
for i in range(N_THREADS): for i in range(N_THREADS):
t = threading.Thread(target=run_thread) t = threading.Thread(target=run_thread)
threads.append(t) threads.append(t)
for t in threads: try:
t.start() for t in threads:
time.sleep(1.0) t.start()
exit = True finally:
time.sleep(1.0)
exit = True
for t in threads: for t in threads:
t.join() t.join()
finally: finally:
......
...@@ -3149,11 +3149,15 @@ class SignalsTest(unittest.TestCase): ...@@ -3149,11 +3149,15 @@ class SignalsTest(unittest.TestCase):
# received (forcing a first EINTR in write()). # received (forcing a first EINTR in write()).
read_results = [] read_results = []
write_finished = False write_finished = False
error = [None]
def _read(): def _read():
while not write_finished: try:
while r in select.select([r], [], [], 1.0)[0]: while not write_finished:
s = os.read(r, 1024) while r in select.select([r], [], [], 1.0)[0]:
read_results.append(s) s = os.read(r, 1024)
read_results.append(s)
except BaseException as exc:
error[0] = exc
t = threading.Thread(target=_read) t = threading.Thread(target=_read)
t.daemon = True t.daemon = True
def alarm1(sig, frame): def alarm1(sig, frame):
...@@ -3174,6 +3178,8 @@ class SignalsTest(unittest.TestCase): ...@@ -3174,6 +3178,8 @@ class SignalsTest(unittest.TestCase):
wio.flush() wio.flush()
write_finished = True write_finished = True
t.join() t.join()
self.assertIsNone(error[0])
self.assertEqual(N, sum(len(x) for x in read_results)) self.assertEqual(N, sum(len(x) for x in read_results))
finally: finally:
write_finished = True write_finished = True
......
...@@ -949,8 +949,12 @@ class TestBasicOps(unittest.TestCase): ...@@ -949,8 +949,12 @@ class TestBasicOps(unittest.TestCase):
# Issue 13454: Crash when deleting backward iterator from tee() # Issue 13454: Crash when deleting backward iterator from tee()
def test_tee_del_backward(self): def test_tee_del_backward(self):
forward, backward = tee(repeat(None, 20000000)) forward, backward = tee(repeat(None, 20000000))
any(forward) # exhaust the iterator try:
del backward any(forward) # exhaust the iterator
del backward
except:
del forward, backward
raise
def test_StopIteration(self): def test_StopIteration(self):
self.assertRaises(StopIteration, izip().next) self.assertRaises(StopIteration, izip().next)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment