Skip to content

Commit

Permalink
Clean up for next tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HosseinYousefi committed Dec 12, 2024
1 parent eb863b0 commit 52f8d40
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions pkgs/jnigen/test/simple_package_test/runtime_test_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ void _runJavaGC() {
} while (result.exitCode != 0);
}

Future<void> _waitUntil(bool Function() predicate) async {
for (var i = 0; i < 8; ++i) {
await Future<void>.delayed(Duration(milliseconds: (1 << i) * 100));
if (predicate()) {
return;
}
}
}

void registerTests(String groupName, TestRunnerCallback test) {
group(groupName, () {
test('static final fields - int', () {
Expand Down Expand Up @@ -636,14 +645,7 @@ void registerTests(String groupName, TestRunnerCallback test) {
// Running garbage collection does not work on Android. Skipping this
// test for android.
_runJavaGC();
for (var i = 0; i < 8; ++i) {
await Future<void>.delayed(Duration(milliseconds: (1 << i) * 100));
if (MyInterface.$impls.isEmpty) {
break;
}
}
// Since the interface is now deleted, the cleaner must signal to Dart
// to clean up.
await _waitUntil(() => MyInterface.$impls.isEmpty);
expect(MyInterface.$impls, isEmpty);
}
});
Expand Down Expand Up @@ -688,12 +690,7 @@ void registerTests(String groupName, TestRunnerCallback test) {
// Running garbage collection does not work on Android. Skipping this
// test for android.
_runJavaGC();
for (var i = 0; i < 8; ++i) {
await Future<void>.delayed(Duration(milliseconds: (1 << i) * 100));
if (MyInterface.$impls.isEmpty) {
break;
}
}
await _waitUntil(() => MyInterface.$impls.isEmpty);
// Since the interface is now deleted, the cleaner must signal to Dart
// to clean up.
expect(MyInterface.$impls, isEmpty);
Expand Down Expand Up @@ -741,27 +738,30 @@ void registerTests(String groupName, TestRunnerCallback test) {
// Running garbage collection does not work on Android. Skipping
// this test for android.
_runJavaGC();
for (var i = 0; i < 8; ++i) {
await Future<void>.delayed(
Duration(milliseconds: (1 << i) * 100));
if (MyInterface.$impls.isEmpty) {
break;
}
}
await _waitUntil(() => MyInterface.$impls.isEmpty);
// Since the interface is now deleted, the cleaner must signal to
// Dart to clean up.
expect(MyRunnable.$impls, isEmpty);
}
});
}
test('Object methods work', () {
test('Object methods work', () async {
final runnable = MyRunnable.implement($MyRunnable(
run: () {},
));
expect(runnable == runnable, true);
expect(runnable != runnable, false);
expect(runnable.hashCode, runnable.hashCode);
expect(runnable.toString(), runnable.toString());
expect(MyRunnable.$impls, hasLength(1));
runnable.release();
if (!Platform.isAndroid) {
// Running garbage collection does not work on Android. Skipping
// this test for android.
_runJavaGC();
await _waitUntil(() => MyInterface.$impls.isEmpty);
expect(MyRunnable.$impls, isEmpty);
}
runnable.release();
});
}
Expand Down

0 comments on commit 52f8d40

Please sign in to comment.