Skip to content

Commit

Permalink
Fixes #1095. Wait for entryPoint is invoked before doing the test (#2102
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sgrekhov authored Jun 28, 2023
1 parent ae846ed commit 11de275
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
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
]);
}

0 comments on commit 11de275

Please sign in to comment.