Skip to content

Fixes #1095. Wait for entryPoint is invoked before doing the test #2102

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
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions LibTest/isolate/Isolate/ping_A03_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import "dart:async";
import "../../../Utils/expect.dart";
import "IsolateUtil.dart";

entryPoint(message){
entryPoint(message) {
message.send("Started");
Random random = new Random();
int s = 0;
while (true){
Expand All @@ -44,22 +45,23 @@ entryPoint(message){
}

test() async {
ReceivePort port = new ReceivePort();
ReceivePort onExit = new ReceivePort();
Isolate isolate = await Isolate.spawn(
entryPoint,
null, // message
port.sendPort,
onExit:onExit.sendPort,
errorsAreFatal:true
);
// check
await port.first;
ReceivePort pingPort = new ReceivePort();
isolate.ping(pingPort.sendPort, priority:Isolate.beforeNextEvent);
Future pingResponse = pingPort.first.timeout(TWO_SECONDS, onTimeout: () {
pingPort.close();
return "timeout";
});
Expect.equals("timeout", await pingResponse);
// clean up

isolate.kill(priority:Isolate.immediate);
await onExit.first;
asyncEnd();
Expand Down
45 changes: 23 additions & 22 deletions LibTest/isolate/Isolate/ping_A03_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,42 +35,36 @@ import "dart:async";
import "../../../Utils/expect.dart";
import "IsolateUtil.dart";

entryPoint(message){
entryPoint(SendPort message) {
message.send("Started");
Random random = new Random();
int s = 0;
while (true){
while (true) {
s = -s + random.nextInt(100);
}
}

Future test(List<Object> values) async {
ReceivePort port = new ReceivePort();
ReceivePort onExit = new ReceivePort();
Isolate isolate = await Isolate.spawn(
entryPoint,
null, // message
onExit:onExit.sendPort,
errorsAreFatal:true
);
// check
Isolate isolate = await Isolate.spawn(entryPoint, port.sendPort,
onExit: onExit.sendPort, errorsAreFatal: true);
await port.first;
List<Future> pingResponses = [];
for (Object value in values) {
ReceivePort pingPort = new ReceivePort();
isolate.ping(
pingPort.sendPort,
response:value,
priority:Isolate.beforeNextEvent
);
isolate.ping(pingPort.sendPort,
response: value, priority: Isolate.beforeNextEvent);
Future pingResponse = pingPort.first.timeout(TWO_SECONDS, onTimeout: () {
pingPort.close();
return "timeout";
});
pingResponses.add(pingResponse);
}
for (Object response in await Future.wait(pingResponses)){
Expect.equals("timeout",response);
for (Object response in await Future.wait(pingResponses)) {
Expect.equals("timeout", response);
}
// clean up
isolate.kill(priority:Isolate.immediate);
isolate.kill(priority: Isolate.immediate);
await onExit.first;
asyncEnd();
}
Expand All @@ -79,9 +73,16 @@ main() {
asyncStart();
test([
null,
0, 1, -1,
true, false,
"", "string",
1.1, double.nan, double.infinity, 0.0
0,
1,
-1,
true,
false,
"",
"string",
1.1,
double.nan,
double.infinity,
0.0
]);
}