Skip to content

Commit 23aefeb

Browse files
authored
Fix CI flake in dwds/test/hot_restart_breakpoints_test.dart (#2685)
Wait until ChromeDriver is actually ready.
1 parent 52ad019 commit 23aefeb

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

dwds/test/fixtures/context.dart

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ class TestContext {
180180
'--port=$chromeDriverPort',
181181
'--url-base=$chromeDriverUrlBase',
182182
]);
183-
// On windows this takes a while to boot up, wait for the first line
184-
// of stdout as a signal that it is ready.
185183
final stdOutLines =
186184
chromeDriver.stdout
187185
.transform(utf8.decoder)
@@ -194,14 +192,31 @@ class TestContext {
194192
.transform(const LineSplitter())
195193
.asBroadcastStream();
196194

197-
stdOutLines.listen(
198-
(line) => _logger.finest('ChromeDriver stdout: $line'),
199-
);
195+
// Sometimes ChromeDriver can be slow to startup.
196+
// This was seen on a github actions run:
197+
// > 11:22:59.924700: ChromeDriver stdout: Starting ChromeDriver
198+
// > 139.0.7258.154 ([...]) on port 38107
199+
// > [...]
200+
// > 11:23:00.237350: ChromeDriver stdout: ChromeDriver was started
201+
// > successfully on port 38107.
202+
// Where in the 300+ ms it took before it was actually ready to accept
203+
// a connection we had tried - and failed - to connect.
204+
// We therefore wait until ChromeDriver reports that it has started
205+
// successfully.
206+
207+
final chromeDriverStartup = Completer();
208+
stdOutLines.listen((line) {
209+
if (!chromeDriverStartup.isCompleted &&
210+
line.contains('was started successfully')) {
211+
chromeDriverStartup.complete();
212+
}
213+
_logger.finest('ChromeDriver stdout: $line');
214+
});
200215
stdErrLines.listen(
201216
(line) => _logger.warning('ChromeDriver stderr: $line'),
202217
);
203218

204-
await stdOutLines.first;
219+
await chromeDriverStartup.future;
205220
} catch (e) {
206221
throw StateError(
207222
'Could not start ChromeDriver. Is it installed?\nError: $e',

dwds/test/hot_restart_breakpoints_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void main() {
4747
late Stream<Event> stream;
4848
// Fetch the log statements that are sent to console.
4949
final consoleLogs = <String>[];
50-
late StreamSubscription<ConsoleAPIEvent> consoleSubscription;
50+
StreamSubscription<ConsoleAPIEvent>? consoleSubscription;
5151

5252
setUp(() async {
5353
setCurrentLogWriter(debug: debug);
@@ -71,7 +71,7 @@ void main() {
7171
});
7272

7373
tearDown(() async {
74-
await consoleSubscription.cancel();
74+
await consoleSubscription?.cancel();
7575
consoleLogs.clear();
7676
await context.tearDown();
7777
});

0 commit comments

Comments
 (0)