Repository navigation
Commit a378299
authored
[pigeon] Fix race in event channel handler removal integration test (#13528)
**This PR fixes the tree.** `Linux_android custom_package_tests master` is failing on `main` (all 3 attempts of [#4084](https://ci.chromium.org/p/flutter/builders/prod/Linux_android%20custom_package_tests%20master/4084)) in the Pigeon integration test `event channels handle multiple instances`:
```
The following MissingPluginException was thrown while de-activating platform stream on channel
dev.flutter.pigeon.pigeon_integration_tests.EventChannelMethods.streamConsistentNumbers.1:
MissingPluginException(No implementation found for method cancel on channel
dev.flutter.pigeon.pigeon_integration_tests.EventChannelMethods.streamConsistentNumbers.1)
```
### Cause
The test plugin unregisters the stream handler for instance `"1"` (to exercise event channel unregistration, added in #13438) immediately after calling `endOfStream()`. On the Dart side, the end of the stream closes the `EventChannel`'s broadcast stream, which then sends a `cancel` method call back on the same channel. If the handler has already been removed by the time that `cancel` call arrives, it fails with a `MissingPluginException`, which fails the test. Whether it fails depends on timing, so it shows up as a flake.
### Fix
Unregister the handler from the stream handler's `onCancel` instead, i.e. only after the `cancel` call has been received, in both the Kotlin (Android) and Swift (iOS/macOS) test plugins. The generated Pigeon stream handler wrappers already forward the platform `onCancel` to the user handler, so no generator or generated-code changes are needed. The test still exercises unregistration; it just no longer races with the channel teardown.
This only changes test plugin code under `platform_tests/`, so there is no change to the published package.
### Testing
On an Android emulator (Pixel 9a), running only `event channels handle multiple instances`:
| | Runs | Failures (`MissingPluginException` on `cancel`) |
|---|---|---|
| Without this fix (`main`) | 5 | 2 |
| With this fix | 10 | 0 |
The full `android_kotlin_integration_tests` suite (680 tests) also passes with this fix, as do `dart_unittests` and `flutter_unittests`. The Swift change mirrors the Kotlin one and is covered by the iOS/macOS integration tests in CI.
### Related
flutter/flutter#179154 tracks a different flake in the same test on macOS Swift (`Bad state: Cannot add new events after calling close`, i.e. an event sent after `endOfStream`). This PR does not address that one, and the macOS Swift skip is left in place.
## 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.1 parent 3f34a6f commit a378299
2 files changed
Lines changed: 20 additions & 6 deletions
File tree
- packages/pigeon/platform_tests/test_plugin
- android/src/main/kotlin/com/example/test_plugin
- darwin/test_plugin/Sources/test_plugin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
2332 | 2332 | | |
2333 | 2333 | | |
2334 | 2334 | | |
2335 | | - | |
| 2335 | + | |
2336 | 2336 | | |
2337 | 2337 | | |
2338 | 2338 | | |
| |||
2341 | 2341 | | |
2342 | 2342 | | |
2343 | 2343 | | |
2344 | | - | |
2345 | 2344 | | |
2346 | 2345 | | |
2347 | 2346 | | |
| |||
2353 | 2352 | | |
2354 | 2353 | | |
2355 | 2354 | | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
2356 | 2363 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
2266 | 2266 | | |
2267 | 2267 | | |
2268 | 2268 | | |
2269 | | - | |
| 2269 | + | |
2270 | 2270 | | |
2271 | 2271 | | |
2272 | 2272 | | |
| |||
2285 | 2285 | | |
2286 | 2286 | | |
2287 | 2287 | | |
2288 | | - | |
2289 | 2288 | | |
2290 | 2289 | | |
2291 | 2290 | | |
2292 | 2291 | | |
2293 | 2292 | | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
2294 | 2301 | | |
0 commit comments