@@ -132,7 +132,6 @@ class TestContext {
132132 TestContext (this .project, this .sdkConfigurationProvider);
133133
134134 Future <void > setUp ({
135- int setupNum = - 1 ,
136135 TestSettings testSettings = const TestSettings (),
137136 TestAppMetadata appMetadata = const TestAppMetadata .externalApp (),
138137 TestDebugSettings debugSettings =
@@ -156,7 +155,7 @@ class TestContext {
156155 DartUri .currentDirectory = project.absolutePackageDirectory;
157156
158157 void log (String s) {
159- _logger.info ('${DateTime .now ()}: ($ setupNum ): $s ' );
158+ _logger.info ('${DateTime .now ()}: $s ' );
160159 }
161160
162161 log ('Serving: ${project .directoryToServe }/${project .filePathToServe }' );
@@ -177,19 +176,12 @@ class TestContext {
177176 _outputDir = systemTempDir.createTempSync ('foo bar' );
178177
179178 final chromeDriverPort = await findUnusedPort ();
180- log ('Picked chromeDriverPort = $chromeDriverPort ' );
181179 final chromeDriverUrlBase = 'wd/hub' ;
182180 try {
183- final localDriver =
184- _chromeDriver = await Process .start ('chromedriver$_exeExt ' , [
185- '--port=$chromeDriverPort ' ,
186- '--url-base=$chromeDriverUrlBase ' ,
187- ]);
188- log (
189- 'Started chrome driver - identity hash code = ${identityHashCode (localDriver )}' ,
190- );
191- // On windows this takes a while to boot up, wait for the first line
192- // of stdout as a signal that it is ready.
181+ _chromeDriver = await Process .start ('chromedriver$_exeExt ' , [
182+ '--port=$chromeDriverPort ' ,
183+ '--url-base=$chromeDriverUrlBase ' ,
184+ ]);
193185 final stdOutLines =
194186 chromeDriver.stdout
195187 .transform (utf8.decoder)
@@ -202,11 +194,31 @@ class TestContext {
202194 .transform (const LineSplitter ())
203195 .asBroadcastStream ();
204196
205- stdOutLines.listen ((line) => log ('ChromeDriver stdout: $line ' ));
197+ // Sometimes ChromeDriver can be slow to startup.
198+ // This was seen on a github actions run:
199+ // > 11:22:59.924700: ChromeDriver stdout: Starting ChromeDriver
200+ // > 139.0.7258.154 ([...]) on port 38107
201+ // > [...]
202+ // > 11:23:00.237350: ChromeDriver stdout: ChromeDriver was started
203+ // > successfully on port 38107.
204+ // Where in the 300+ ms it took before it was actually ready to accept
205+ // a connection we had tried - and failed - to connect.
206+ // We therefore wait until ChromeDriver reports that it has started
207+ // successfully.
208+
209+ final chromeDriverStartup = Completer ();
210+ stdOutLines.listen ((line) {
211+ if (! chromeDriverStartup.isCompleted &&
212+ line.contains ('was started successfully' )) {
213+ chromeDriverStartup.complete ();
214+ }
215+ log ('ChromeDriver stdout: $line ' );
216+ });
206217 stdErrLines.listen ((line) => log ('ChromeDriver stderr: $line ' ));
207218
208- final firstLine = await stdOutLines.first;
209- log ('Notice first line = $firstLine ' );
219+ await stdOutLines.first;
220+ await chromeDriverStartup.future;
221+ log ('ChromeDriver has now started' );
210222 } catch (e) {
211223 throw StateError (
212224 'Could not start ChromeDriver. Is it installed?\n Error: $e ' ,
@@ -226,7 +238,6 @@ class TestContext {
226238 var filePathToServe = project.filePathToServe;
227239
228240 _port = await findUnusedPort ();
229- log ('Port #2: $_port ' );
230241 switch (testSettings.compilationMode) {
231242 case CompilationMode .buildDaemon:
232243 {
@@ -343,7 +354,6 @@ class TestContext {
343354 );
344355
345356 final assetServerPort = await findUnusedPort ();
346- log ('Port #3: $assetServerPort ' );
347357 _hostname = appMetadata.hostname;
348358 await webRunner.run (
349359 frontendServerFileSystem,
@@ -398,7 +408,6 @@ class TestContext {
398408 }
399409
400410 final debugPort = await findUnusedPort ();
401- log ('Port #4: $debugPort ' );
402411 if (testSettings.launchChrome) {
403412 // If the environment variable DWDS_DEBUG_CHROME is set to the string
404413 // true then Chrome will be launched with a UI rather than headless.
0 commit comments