From 5586249976e837651b5b3e5844d5f4916f6b291c Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Fri, 20 Sep 2024 02:03:58 +0200 Subject: [PATCH] Adding GC to all interface impl tests --- .../runtime_test_registrant.dart | 86 ++++++++++--------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart b/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart index 7c65280ad..6e6d36b5d 100644 --- a/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart +++ b/pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart @@ -710,47 +710,53 @@ void registerTests(String groupName, TestRunnerCallback test) { test( 'on ${sameThread ? 'the same thread' : 'another thread'}' ' throwing $exception', () async { - final runnable = MyRunnable.implement( - $MyRunnable( - run: () { - // ignore: only_throw_errors - throw exception; - }, - ), - ); - final runner = MyRunnableRunner(runnable); - if (sameThread) { - runner.runOnSameThread(); - } else { - runner.runOnAnotherThread(); - } - while (runner.error.isNull) { - await Future.delayed(const Duration(milliseconds: 100)); + await using((arena) async { + final runnable = MyRunnable.implement( + $MyRunnable( + run: () { + // ignore: only_throw_errors + throw exception; + }, + ), + )..releasedBy(arena); + final runner = MyRunnableRunner(runnable)..releasedBy(arena); + if (sameThread) { + runner.runOnSameThread(); + } else { + runner.runOnAnotherThread(); + } + while (runner.error.isNull) { + await Future.delayed(const Duration(milliseconds: 100)); + } + expect( + Jni.env.IsInstanceOf( + runner.error.reference.pointer, + JClass.forName( + 'java/lang/reflect/UndeclaredThrowableException') + .reference + .pointer, + ), + isTrue, + ); + final throwableClass = runner.error.jClass; + final cause = throwableClass + .instanceMethodId('getCause', '()Ljava/lang/Throwable;') + .call(runner.error, JObject.type, []); + expect( + Jni.env.IsInstanceOf( + cause.reference.pointer, + JClass.forName( + 'com/github/dart_lang/jni/PortProxyBuilder\$DartException') + .reference + .pointer, + ), + isTrue, + ); + expect(cause.toString(), contains(exception.toString())); + }); + if (!Platform.isAndroid) { + _runJavaGC(); } - expect( - Jni.env.IsInstanceOf( - runner.error.reference.pointer, - JClass.forName('java/lang/reflect/UndeclaredThrowableException') - .reference - .pointer, - ), - isTrue, - ); - final throwableClass = runner.error.jClass; - final cause = throwableClass - .instanceMethodId('getCause', '()Ljava/lang/Throwable;') - .call(runner.error, JObject.type, []); - expect( - Jni.env.IsInstanceOf( - cause.reference.pointer, - JClass.forName( - 'com/github/dart_lang/jni/PortProxyBuilder\$DartException') - .reference - .pointer, - ), - isTrue, - ); - expect(cause.toString(), contains(exception.toString())); }); } }