Skip to content

Commit 443a4db

Browse files
committed
fix test__count (no support for weakref callbacks yet)
1 parent 88e4c06 commit 443a4db

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_thread.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -118,32 +118,29 @@ def test_stack_size(self):
118118
thread.stack_size(0)
119119
self.assertEqual(thread.stack_size(), 0, "stack_size not reset to default")
120120

121-
# def test__count(self):
122-
# # Test the _count() function.
123-
# orig = thread._count()
124-
# mut = thread.allocate_lock()
125-
# mut.acquire()
126-
# started = []
127-
#
128-
# def task():
129-
# started.append(None)
130-
# mut.acquire()
131-
# mut.release()
132-
# thread.start_new_thread(task, ())
133-
# while not started:
134-
# time.sleep(POLL_SLEEP)
135-
# self.assertEqual(thread._count(), orig + 1)
136-
# # Allow the task to finish.
137-
# mut.release()
138-
# # The only reliable way to be sure that the thread ended from the
139-
# # interpreter's point of view is to wait for the function object to be
140-
# # destroyed.
141-
# done = []
142-
# wr = weakref.ref(task, lambda _: done.append(None))
143-
# del task
144-
# while not done:
145-
# time.sleep(POLL_SLEEP)
146-
# self.assertEqual(thread._count(), orig)
121+
def test__count(self):
122+
# Test the _count() function.
123+
orig = thread._count()
124+
mut = thread.allocate_lock()
125+
mut.acquire()
126+
started = []
127+
done = []
128+
129+
def task():
130+
started.append(None)
131+
mut.acquire()
132+
mut.release()
133+
done.append(None)
134+
135+
thread.start_new_thread(task, ())
136+
while not started:
137+
time.sleep(POLL_SLEEP)
138+
self.assertEqual(thread._count(), orig + 1)
139+
# Allow the task to finish.
140+
mut.release()
141+
while not done:
142+
time.sleep(POLL_SLEEP)
143+
self.assertEqual(thread._count(), orig)
147144

148145
# def test_save_exception_state_on_error(self):
149146
# # See issue #14474

0 commit comments

Comments
 (0)