Skip to content

Commit

Permalink
Fixes #2158. Fix flaky co19_2/LibTest/isolate/Isolate/pause_A01_t01, …
Browse files Browse the repository at this point in the history
…_02 tests (#2159)
  • Loading branch information
sgrekhov authored Aug 2, 2023
1 parent db81808 commit 3756b19
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
34 changes: 21 additions & 13 deletions LibTest/isolate/Isolate/pause_A01_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,47 @@
///
/// @author a.semenov@unipro.ru
import "dart:io";
import "dart:isolate";
import "dart:math";
import "../../../Utils/expect.dart";

// indefinitely running isolate
entryPoint(SendPort sendPort){
entryPoint(List<SendPort> sendPorts) {
sendPorts[0].send(42);
Random random = new Random();
int s = 0;
while (true){
while (true) {
s = -s + random.nextInt(100);
sendPort.send(s);
sendPorts[1].send(s);

// Synchronous sleep does not yield to the message loop, so the pause
// doesn't take effect.
sleep(const Duration(milliseconds: 1));
}
}

test() async {
ReceivePort receivePort = new ReceivePort();
ReceivePort receivePort1 = new ReceivePort();
ReceivePort receivePort2 = new ReceivePort();
ReceivePort onExit = new ReceivePort();
Isolate isolate = await Isolate.spawn(
entryPoint,
receivePort.sendPort, // message
onExit:onExit.sendPort,
errorsAreFatal:true
);
Isolate isolate =
await Isolate.spawn(entryPoint,
[receivePort1.sendPort, receivePort2.sendPort],
onExit: onExit.sendPort,
errorsAreFatal: true);
// make sure that isolate started its work
await receivePort1.first;
isolate.pause();
// check that messages are received from paused isolate
int count = 0;
await for (var _ in receivePort){
if (count++==1000000){
await for (var _ in receivePort2) {
if (count++ == 100) {
break;
}
}
// clean up
isolate.kill(priority:Isolate.immediate);
isolate.kill(priority: Isolate.immediate);
await onExit.first;
asyncEnd();
}
Expand Down
34 changes: 21 additions & 13 deletions LibTest/isolate/Isolate/pause_A01_t02.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,47 @@
///
/// @author a.semenov@unipro.ru
import "dart:io";
import "dart:isolate";
import "dart:math";
import "../../../Utils/expect.dart";

// indefinitely running isolate
entryPoint(SendPort sendPort){
entryPoint(List<SendPort> sendPorts) {
sendPorts[0].send(42);
Random random = new Random();
int s = 0;
while (true){
while (true) {
s = -s + random.nextInt(100);
sendPort.send(s);
sendPorts[1].send(s);

// Synchronous sleep does not yield to the message loop, so the pause
// doesn't take effect.
sleep(const Duration(milliseconds: 1));
}
}

test() async {
ReceivePort receivePort = new ReceivePort();
ReceivePort receivePort1 = new ReceivePort();
ReceivePort receivePort2 = new ReceivePort();
ReceivePort onExit = new ReceivePort();
Isolate isolate = await Isolate.spawn(
entryPoint,
receivePort.sendPort, // message
onExit:onExit.sendPort,
errorsAreFatal:true
);
Isolate isolate =
await Isolate.spawn(entryPoint,
[receivePort1.sendPort, receivePort2.sendPort],
onExit: onExit.sendPort,
errorsAreFatal: true);
// make sure that isolate started its work
await receivePort1.first;
isolate.pause(new Capability());
// check that messages are received from paused isolate
int count = 0;
await for (var _ in receivePort){
if (count++==1000000){
await for (var _ in receivePort2) {
if (count++ == 100) {
break;
}
}
// clean up
isolate.kill(priority:Isolate.immediate);
isolate.kill(priority: Isolate.immediate);
await onExit.first;
asyncEnd();
}
Expand Down

0 comments on commit 3756b19

Please sign in to comment.