Skip to content

Commit

Permalink
Adding GC to all interface impl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HosseinYousefi committed Sep 20, 2024
1 parent af1051e commit 5586249
Showing 1 changed file with 46 additions and 40 deletions.
86 changes: 46 additions & 40 deletions pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>.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<void>.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()));
});
}
}
Expand Down

0 comments on commit 5586249

Please sign in to comment.