From 007439e51981c536e65171444b536b03ef23fc25 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Thu, 2 Dec 2021 12:46:20 -0800 Subject: [PATCH] Avoid sender making more progress than the receiver in Isolate/pause_A01_t01/2. In these tests, one isolate continuously sends messages to another without back pressure. If the system is loaded, the sender may send messages at a faster rate then the receiver can process them and the test can time out before receiver processes enough messages to end the test. Instead of processing a large number of messages to ensure some of them would happen after the pause request, use synchronous sleeps. --- LibTest/isolate/Isolate/pause_A01_t01.dart | 7 ++++++- LibTest/isolate/Isolate/pause_A01_t02.dart | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/LibTest/isolate/Isolate/pause_A01_t01.dart b/LibTest/isolate/Isolate/pause_A01_t01.dart index 9ee7666c33..262c581f96 100644 --- a/LibTest/isolate/Isolate/pause_A01_t01.dart +++ b/LibTest/isolate/Isolate/pause_A01_t01.dart @@ -15,6 +15,7 @@ /// /// @author a.semenov@unipro.ru +import "dart:io"; import "dart:isolate"; import "dart:math"; import "../../../Utils/expect.dart"; @@ -27,6 +28,10 @@ entryPoint(List sendPorts) { while (true) { s = -s + random.nextInt(100); 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)); } } @@ -45,7 +50,7 @@ test() async { // check that messages are received from paused isolate int count = 0; await for (var _ in receivePort2) { - if (count++ == 1000000) { + if (count++ == 100) { break; } } diff --git a/LibTest/isolate/Isolate/pause_A01_t02.dart b/LibTest/isolate/Isolate/pause_A01_t02.dart index 9d449d7074..65f60846e3 100644 --- a/LibTest/isolate/Isolate/pause_A01_t02.dart +++ b/LibTest/isolate/Isolate/pause_A01_t02.dart @@ -16,6 +16,7 @@ /// /// @author a.semenov@unipro.ru +import "dart:io"; import "dart:isolate"; import "dart:math"; import "../../../Utils/expect.dart"; @@ -28,6 +29,10 @@ entryPoint(List sendPorts) { while (true) { s = -s + random.nextInt(100); 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)); } } @@ -46,7 +51,7 @@ test() async { // check that messages are received from paused isolate int count = 0; await for (var _ in receivePort2) { - if (count++ == 1000000) { + if (count++ == 100) { break; } }