Skip to content

Commit a562e65

Browse files
committed
Make capsule destructor test more robust
1 parent 4b02214 commit a562e65

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@
5656
IS_MANAGED_LAUNCHER = not GRAALPYTHON or __graalpython__.is_managed_launcher()
5757

5858

59-
def run_gc():
60-
for i in range(3):
61-
gc.collect()
62-
time.sleep(0.01)
63-
64-
6559
def assert_raises(err, fn, *args, **kwargs):
6660
raised = False
6761
try:

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_capsule.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3737
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3838
# SOFTWARE.
39+
import gc
40+
import time
3941

40-
from . import CPyExtTestCase, CPyExtFunction, unhandled_error_compare, CPyExtType, run_gc
42+
from . import CPyExtTestCase, CPyExtFunction, unhandled_error_compare, CPyExtType
4143

4244
__dir__ = __file__.rpartition("/")[0]
4345

@@ -131,9 +133,12 @@ def test_capsule_destructor(self):
131133
)
132134
d = {}
133135
capsule = Tester.create_capsule(d)
134-
run_gc()
135136
assert capsule
136137
assert not d
137138
del capsule
138-
run_gc()
139-
assert "destructor_was_here" in d
139+
start = time.time()
140+
while "destructor_was_here" not in d:
141+
if time.time() - start > 60:
142+
raise AssertionError("Capsule destructor didn't execute within timeout")
143+
gc.collect()
144+
time.sleep(0.01)

0 commit comments

Comments
 (0)