[pigeon] Create a message call free InstanceManager when running unit tests (#9395)
To support hot restart, PigeonInstanceManager.instance makes a call to clear the native InstanceManager when it is instantiated.
This was the source of unit test race condition flakes like https://github.com/flutter/flutter/issues/164132.
The current workaround is to try/catch the async PlatformException at the top of every test file or pass a test InstanceManager to every ProxyApi class:
```dart
final MyNativeClass object = MyNativeClass(
pigeon_instanceManager: PigeonInstanceManager(
onWeakReferenceRemoved: (_) {}
),
);
```
This PR changes it to [detect a test ran as Flutter unit test](https://api.flutter.dev/flutter/flutter_test/TestWidgetsFlutterBinding/ensureInitialized.html) and sets the default InstanceManager with one that doesn't make any message calls.
## Pre-Review Checklist
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
[pigeon] Prevents premature finalization from unused Dart instance for ProxyApis (#9231)
1. The Dart InstanceManager.addHostCreatedInstance is only ever used to respond to native calls that create a new instance right before the instance is returned in a host method call or passed in a flutter method call. So, addHostCreatedInstance now only adds a strong referenced instance and not the weak referenced instance. This will ensure the weak referenced instance is not created until it is being passed to a user immediately.
2. The Dart InstanceManager.remove now asserts that the strong referenced instance isn't removed before the weak referenced instance. This should prevent future scenarios where the user is holding a weak referenced instance while the native side no longer has any reference.
Fixes https://github.com/flutter/flutter/issues/168531
## Pre-Review Checklist
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
[pigeon] Update task queue handling (#8627)
Updates the task queue implementation across all supporting generators to use one task queue for an entire host API, rather than one per method, so that multiple methods using task queues will have ordering guarantees amongst them. Also changes the Obj-C implementation to no-op on macOS instead of failing to compile, so that shared iOS/macOS code can use task queues on iOS without breaking macOS. (We could deliberately add a compile error with a clear error message in a macOS ifdef if we get reports of user confusion in the future, but my expectation is that no-op is the best option for most people.)
Related changes:
- Adds integration testing that task queues work, instead of just that the generator step succeeds.
- For platforms that don't support task queues, they are still included in the integration test to ensure that
- I removed the now-vestigial background_platform_channels.dart.
- Adds Swift support, since it was easier to add than to skip it in the tests.
Fixes https://github.com/flutter/flutter/issues/162624
Fixes https://github.com/flutter/flutter/issues/111512
[pigeon] reorg generator files (#8532)
Just moves a few files into folders to clean things up a bit. Future organizing is likely, but I wanted to move the files with no changes first
[pigeon] reorg generator files (#8532)
Just moves a few files into folders to clean things up a bit. Future organizing is likely, but I wanted to move the files with no changes first
[pigeon] Create a message call free InstanceManager when running unit tests (#9395)
To support hot restart, PigeonInstanceManager.instance makes a call to clear the native InstanceManager when it is instantiated.
This was the source of unit test race condition flakes like https://github.com/flutter/flutter/issues/164132.
The current workaround is to try/catch the async PlatformException at the top of every test file or pass a test InstanceManager to every ProxyApi class:
```dart
final MyNativeClass object = MyNativeClass(
pigeon_instanceManager: PigeonInstanceManager(
onWeakReferenceRemoved: (_) {}
),
);
```
This PR changes it to [detect a test ran as Flutter unit test](https://api.flutter.dev/flutter/flutter_test/TestWidgetsFlutterBinding/ensureInitialized.html) and sets the default InstanceManager with one that doesn't make any message calls.
## Pre-Review Checklist
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
[pigeon] reorg generator files (#8532)
Just moves a few files into folders to clean things up a bit. Future organizing is likely, but I wanted to move the files with no changes first