-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[pigeon] Create a message call free InstanceManager when running unit tests #9395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 13 commits into
flutter:main
from
bparrishMines:test_instancemanager
Jun 18, 2025
+58
−4
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9db1596
set test default instance manager
bparrishMines 37d94be
fix changelog
bparrishMines 7d3840c
better formatting
bparrishMines a496abf
improve test
bparrishMines 195ede0
Merge branch 'main' of github.com:flutter/packages into test_instance…
bparrishMines 7765204
unused params
bparrishMines 6e60cc2
message instead of method
bparrishMines f4d7d6f
unused import
bparrishMines 5ae0295
Merge branch 'main' of github.com:flutter/packages into test_instance…
bparrishMines de63935
use 2 full cycles
bparrishMines a10c8bc
add full cycle to the other test
bparrishMines 20014bc
check for true instead
bparrishMines 57e5650
Merge branch 'main' of github.com:flutter/packages into test_instance…
bparrishMines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,7 +167,7 @@ void main() { | |
instanceManager.addDartCreatedInstance(object); | ||
|
||
object = null; | ||
await forceGC(); | ||
await forceGC(fullGcCycles: 2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test was failing on windows, so I added another cycle. |
||
|
||
expect(weakReferencedRemovedCalled, isTrue); | ||
}); | ||
|
@@ -188,10 +188,49 @@ void main() { | |
instanceManager.addHostCreatedInstance(object, 0); | ||
|
||
object = null; | ||
await forceGC(); | ||
await forceGC(fullGcCycles: 2); | ||
|
||
expect(weakReferencedRemovedCalled, isFalse); | ||
}); | ||
|
||
testWidgets( | ||
'instantiating default InstanceManager does not make a message call', | ||
(WidgetTester tester) async { | ||
bool messageCallMade = false; | ||
TestDefaultBinaryMessengerBinding | ||
.instance.defaultBinaryMessenger.allMessagesHandler = (_, __, ___) { | ||
messageCallMade = true; | ||
return null; | ||
}; | ||
|
||
// Initialize default InstanceManager | ||
// ignore: unnecessary_statements | ||
PigeonInstanceManager.instance; | ||
|
||
expect(messageCallMade, isFalse); | ||
}, | ||
); | ||
|
||
testWidgets( | ||
'default InstanceManager does not make message call when weak reference is removed', | ||
(WidgetTester tester) async { | ||
bool messageCallMade = false; | ||
TestDefaultBinaryMessengerBinding | ||
.instance.defaultBinaryMessenger.allMessagesHandler = (_, __, ___) { | ||
messageCallMade = true; | ||
return null; | ||
}; | ||
|
||
final PigeonInstanceManager instanceManager = | ||
PigeonInstanceManager.instance; | ||
|
||
final int identifier = | ||
instanceManager.addDartCreatedInstance(CopyableObject()); | ||
instanceManager.onWeakReferenceRemoved(identifier); | ||
|
||
expect(messageCallMade, isFalse); | ||
}, | ||
); | ||
}); | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, is
FLUTTER_TEST
only set in unit tests? Or will this breakflutter test
integration test behavior?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot that integration tests also use
flutter test
. But I just tried it and it looks like this doesn't affect integration tests. It seems the environment variable is only for unit tests.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably the case because integration tests still need to use the real BinaryMessenger. When
FLUTTER_TEST
is set, it uses a test BinaryMessenger from TestWidgetsFlutterBinding.Edit:
Actually I found a bit of info on it: https://api.flutter.dev/flutter/flutter_test/LiveTestWidgetsFlutterBinding-class.html. It looks like integration tests from
flutter test
is treated the same way as running tests withflutter run
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good; LGTM then.
I wish we didn't have to embed special test logic in the production code, but it seems like the best option we have at the moment.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm would it be better to copy https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/foundation/_platform_io.dart#L30 then. And wrap the
Platform.environment
check in anassert
so that it gets ignored in release mode.