Skip to content

Commit 3756b19

Browse files
authored
Fixes #2158. Fix flaky co19_2/LibTest/isolate/Isolate/pause_A01_t01, _02 tests (#2159)
1 parent db81808 commit 3756b19

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

LibTest/isolate/Isolate/pause_A01_t01.dart

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,47 @@
1717
///
1818
/// @author [email protected]
1919
20+
import "dart:io";
2021
import "dart:isolate";
2122
import "dart:math";
2223
import "../../../Utils/expect.dart";
2324

2425
// indefinitely running isolate
25-
entryPoint(SendPort sendPort){
26+
entryPoint(List<SendPort> sendPorts) {
27+
sendPorts[0].send(42);
2628
Random random = new Random();
2729
int s = 0;
28-
while (true){
30+
while (true) {
2931
s = -s + random.nextInt(100);
30-
sendPort.send(s);
32+
sendPorts[1].send(s);
33+
34+
// Synchronous sleep does not yield to the message loop, so the pause
35+
// doesn't take effect.
36+
sleep(const Duration(milliseconds: 1));
3137
}
3238
}
3339

3440
test() async {
35-
ReceivePort receivePort = new ReceivePort();
41+
ReceivePort receivePort1 = new ReceivePort();
42+
ReceivePort receivePort2 = new ReceivePort();
3643
ReceivePort onExit = new ReceivePort();
37-
Isolate isolate = await Isolate.spawn(
38-
entryPoint,
39-
receivePort.sendPort, // message
40-
onExit:onExit.sendPort,
41-
errorsAreFatal:true
42-
);
44+
Isolate isolate =
45+
await Isolate.spawn(entryPoint,
46+
[receivePort1.sendPort, receivePort2.sendPort],
47+
onExit: onExit.sendPort,
48+
errorsAreFatal: true);
49+
// make sure that isolate started its work
50+
await receivePort1.first;
4351
isolate.pause();
4452
// check that messages are received from paused isolate
4553
int count = 0;
46-
await for (var _ in receivePort){
47-
if (count++==1000000){
54+
await for (var _ in receivePort2) {
55+
if (count++ == 100) {
4856
break;
4957
}
5058
}
5159
// clean up
52-
isolate.kill(priority:Isolate.immediate);
60+
isolate.kill(priority: Isolate.immediate);
5361
await onExit.first;
5462
asyncEnd();
5563
}

LibTest/isolate/Isolate/pause_A01_t02.dart

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,47 @@
1818
///
1919
/// @author [email protected]
2020
21+
import "dart:io";
2122
import "dart:isolate";
2223
import "dart:math";
2324
import "../../../Utils/expect.dart";
2425

2526
// indefinitely running isolate
26-
entryPoint(SendPort sendPort){
27+
entryPoint(List<SendPort> sendPorts) {
28+
sendPorts[0].send(42);
2729
Random random = new Random();
2830
int s = 0;
29-
while (true){
31+
while (true) {
3032
s = -s + random.nextInt(100);
31-
sendPort.send(s);
33+
sendPorts[1].send(s);
34+
35+
// Synchronous sleep does not yield to the message loop, so the pause
36+
// doesn't take effect.
37+
sleep(const Duration(milliseconds: 1));
3238
}
3339
}
3440

3541
test() async {
36-
ReceivePort receivePort = new ReceivePort();
42+
ReceivePort receivePort1 = new ReceivePort();
43+
ReceivePort receivePort2 = new ReceivePort();
3744
ReceivePort onExit = new ReceivePort();
38-
Isolate isolate = await Isolate.spawn(
39-
entryPoint,
40-
receivePort.sendPort, // message
41-
onExit:onExit.sendPort,
42-
errorsAreFatal:true
43-
);
45+
Isolate isolate =
46+
await Isolate.spawn(entryPoint,
47+
[receivePort1.sendPort, receivePort2.sendPort],
48+
onExit: onExit.sendPort,
49+
errorsAreFatal: true);
50+
// make sure that isolate started its work
51+
await receivePort1.first;
4452
isolate.pause(new Capability());
4553
// check that messages are received from paused isolate
4654
int count = 0;
47-
await for (var _ in receivePort){
48-
if (count++==1000000){
55+
await for (var _ in receivePort2) {
56+
if (count++ == 100) {
4957
break;
5058
}
5159
}
5260
// clean up
53-
isolate.kill(priority:Isolate.immediate);
61+
isolate.kill(priority: Isolate.immediate);
5462
await onExit.first;
5563
asyncEnd();
5664
}

0 commit comments

Comments
 (0)