This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Migrate more tests from litetest to package:test
#55119
Merged
auto-submit
merged 11 commits into
flutter-team-archive:main
from
matanlurey:pkg-test-observatory
Sep 12, 2024
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
09351af
Migrate dart/observatory to package:test.
matanlurey 857c13b
Migrate more tests.
matanlurey 1c2e46a
Moar tests.
matanlurey 0dc3d8e
++
matanlurey f2727b7
++
matanlurey 3507544
++
matanlurey 0f593a4
Migrate platform_isolate_test.
matanlurey 83994ac
Migrate fragment_shader_test.dart
matanlurey 8e4895a
++
matanlurey 73a4528
++
matanlurey 82b92d0
Add nits.
matanlurey 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ import 'dart:async'; | |
| import 'dart:isolate'; | ||
| import 'dart:ui'; | ||
|
|
||
| import 'package:litetest/litetest.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| int counter = 0; | ||
|
|
||
|
|
@@ -62,34 +62,47 @@ void main() { | |
| expect(await future3, 3); | ||
| }); | ||
|
|
||
| test('PlatformIsolate runOnPlatformThread, send and receive messages', | ||
| () async { | ||
| // Send numbers 1 to 10 to the platform isolate. The platform isolate | ||
| // multiplies them by 100 and sends them back. | ||
| int sum = 0; | ||
| final RawReceivePort recvPort = RawReceivePort((Object message) { | ||
| if (message is SendPort) { | ||
| for (int i = 1; i <= 10; ++i) { | ||
| message.send(i); | ||
| } | ||
| } else { | ||
| sum += message as int; | ||
| test('PlatformIsolate runOnPlatformThread, send/receive messages', () async { | ||
| late SendPort toPlatformThread; | ||
| var sumOfReceivedMessages = 0; | ||
| var countofReceivedMessages = 0; | ||
| final recvPort = RawReceivePort((Object message) { | ||
| switch (message) { | ||
| case final SendPort sendPort: | ||
| toPlatformThread = sendPort; | ||
| for (int i = 1; i <= 10; i++) { | ||
| sendPort.send(i); | ||
| } | ||
| case final int value: | ||
| sumOfReceivedMessages += value; | ||
| countofReceivedMessages++; | ||
| if (countofReceivedMessages == 10) { | ||
| toPlatformThread.send(true); | ||
| } | ||
| default: | ||
| fail('Unexpected message: $message'); | ||
| } | ||
| }); | ||
| final SendPort sendPort = recvPort.sendPort; | ||
|
|
||
| final sendPort = recvPort.sendPort; | ||
| await runOnPlatformThread(() async { | ||
| final Completer<void> completer = Completer<void>(); | ||
| final RawReceivePort recvPort = RawReceivePort((Object message) { | ||
| sendPort.send((message as int) * 100); | ||
| if (message == 10) { | ||
| completer.complete(); | ||
| final completer = Completer<void>(); | ||
| final recvPort = RawReceivePort((Object message) { | ||
| switch (message) { | ||
| case final int value: | ||
| sendPort.send(value * 100); | ||
| case true: | ||
| completer.complete(); | ||
| default: | ||
| fail('Unexpected message: $message'); | ||
| } | ||
| }); | ||
| sendPort.send(recvPort.sendPort); | ||
| await completer.future; | ||
| recvPort.close(); | ||
| }); | ||
| expect(sum, 5500); // sum(1 to 10) * 100 | ||
|
Contributor
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. Please bring back this comment.
Contributor
Author
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. Done! |
||
|
|
||
| expect(sumOfReceivedMessages, 5500); | ||
| recvPort.close(); | ||
| }); | ||
|
|
||
|
|
@@ -122,9 +135,11 @@ void main() { | |
|
|
||
| test('PlatformIsolate runOnPlatformThread, disabled on helper isolates', | ||
| () async { | ||
| await Isolate.run(() { | ||
| expect(() => runOnPlatformThread(() => print('Unreachable')), throws); | ||
| }); | ||
| await expectLater(() async { | ||
| await Isolate.run(() { | ||
| return runOnPlatformThread(() => print('Unreachable')); | ||
| }); | ||
| }, throws); | ||
| }); | ||
|
|
||
| test('PlatformIsolate runOnPlatformThread, on platform isolate', () async { | ||
|
|
@@ -134,7 +149,7 @@ void main() { | |
| }); | ||
|
|
||
| test('PlatformIsolate runOnPlatformThread, exit disabled', () async { | ||
| await runOnPlatformThread(() => expect(() => Isolate.exit(), throws)); | ||
| await expectLater(runOnPlatformThread(() => Isolate.exit()), throws); | ||
| }); | ||
|
|
||
| test('PlatformIsolate runOnPlatformThread, unsendable object', () async { | ||
|
|
||
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
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.
Why are we losing these asserts? I see the print statement below, are we just going to fail further down in execution?
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.
Package test can't run assertions outside of a test block and these functions generate tests. I think the test will still fail approximately at the same time though?
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.
Changed to a
fail