@@ -314,16 +314,6 @@ class SkiaGoldClient {
314314 _tryjobInitialized = true ;
315315 }
316316
317- static void _addIndented (StringBuffer buffer, String text) {
318- if (text.isEmpty) {
319- buffer.writeln (' <empty>' );
320- } else {
321- for (final String line in text.split ('\n ' )) {
322- buffer.writeln (' $line ' );
323- }
324- }
325- }
326-
327317 /// Executes the `imgtest add` command in the goldctl tool for tryjobs.
328318 ///
329319 /// The `imgtest` command collects and uploads test results to the Skia Gold
@@ -334,64 +324,41 @@ class SkiaGoldClient {
334324 /// The [testName] and [goldenFile] parameters reference the current
335325 /// comparison being evaluated by the [FlutterPreSubmitFileComparator] .
336326 Future <void > tryjobAdd (String testName, File goldenFile) async {
337- Duration delay = const Duration (seconds: 5 );
338- while (true ) {
339- final io.ProcessResult result = await process.run (< String > [
340- _goldctl,
341- 'imgtest' , 'add' ,
342- '--work-dir' , workDirectory.childDirectory ('temp' ).path,
343- '--test-name' , cleanTestName (testName),
344- '--png-file' , goldenFile.path,
345- ..._getPixelMatchingArguments (),
346- ]);
347-
348- final String resultStdout = result.stdout as String ;
349- final String resultStderr = result.stderr as String ;
350- if (result.exitCode == 0 ||
351- resultStdout.contains ('Untriaged' ) ||
352- resultStdout.contains ('negative image' )) {
353- return ; // success
354- }
327+ final List <String > imgtestCommand = < String > [
328+ _goldctl,
329+ 'imgtest' , 'add' ,
330+ '--work-dir' , workDirectory
331+ .childDirectory ('temp' )
332+ .path,
333+ '--test-name' , cleanTestName (testName),
334+ '--png-file' , goldenFile.path,
335+ ..._getPixelMatchingArguments (),
336+ ];
355337
356- if (resultStdout.contains ('502' )) {
357- // probably a transient error, try again
358- // Ideally we'd use something like package:test's printOnError, but best reliability
359- // in getting logs on CI for now we're just using print.
360- // See also: https://github.com/flutter/flutter/issues/91285
361- print ('Transient failure from Skia Gold, retrying in ${delay .inSeconds } seconds.' ); // ignore: avoid_print
362- print ('' ); // ignore: avoid_print
363- print ('stdout from gold:' ); // ignore: avoid_print
364- final StringBuffer buffer = StringBuffer ();
365- _addIndented (buffer, resultStdout);
366- print (buffer); // ignore: avoid_print
367- await Future <void >.delayed (delay);
368- delay *= 2 ;
369- continue ; // retry
370- }
338+ final io.ProcessResult result = await process.run (imgtestCommand);
371339
372- final StringBuffer buffer = StringBuffer ()
373- ..write ('Golden test for "$testName " failed with exit code ${result .exitCode } ' )
374- ..writeln ('for a reason unrelated to pixel comparison.' );
375- if (resultStdout.isNotEmpty) {
376- buffer
377- ..writeln ()
378- ..writeln ('stdout from gold:' );
379- _addIndented (buffer, resultStdout);
380- }
381- if (resultStderr.isNotEmpty) {
382- buffer
383- ..writeln ()
384- ..writeln ('stderr from gold:' );
385- _addIndented (buffer, resultStderr);
386- }
387- final File resultFile = workDirectory.childFile ('result-state.json' );
340+ final String /*!*/ resultStdout = result.stdout.toString ();
341+ if (result.exitCode != 0 &&
342+ ! (resultStdout.contains ('Untriaged' ) || resultStdout.contains ('negative image' ))) {
343+ String ? resultContents;
344+ final File resultFile = workDirectory.childFile (fs.path.join (
345+ 'result-state.json' ,
346+ ));
388347 if (await resultFile.exists ()) {
389- buffer
390- ..writeln ()
391- ..writeln ('result-state.json contents:' );
392- _addIndented (buffer, resultFile.readAsStringSync ());
348+ resultContents = await resultFile.readAsString ();
393349 }
394- throw SkiaException (buffer.toString ()); // failure
350+ final StringBuffer buf = StringBuffer ()
351+ ..writeln ('Unexpected Gold tryjobAdd failure.' )
352+ ..writeln ('Tryjob execution for golden file test $testName failed for' )
353+ ..writeln ('a reason unrelated to pixel comparison.' )
354+ ..writeln ()
355+ ..writeln ('Debug information for Gold --------------------------------' )
356+ ..writeln ('stdout: ${result .stdout }' )
357+ ..writeln ('stderr: ${result .stderr }' )
358+ ..writeln ()
359+ ..writeln ()
360+ ..writeln ('result-state.json: ${resultContents ?? 'No result file found.' }' );
361+ throw SkiaException (buf.toString ());
395362 }
396363 }
397364
0 commit comments