From 3c705417636ee23f93144104273b6f2ba133b917 Mon Sep 17 00:00:00 2001 From: Mouad Debbar Date: Fri, 14 Apr 2023 16:44:59 -0400 Subject: [PATCH] [web] Don't run goldctl init more than once (flutter/engine#41207) From the logs reported in https://github.com/flutter/flutter/issues/124864 I noticed we are making multiple calls to `goldctl init` which could be causing some race conditions with the `goldctl imgtest add` calls. This PR makes sure we only call `goldctl init` once. --- .../lib/skia_gold_client.dart | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/engine/src/flutter/testing/skia_gold_client/lib/skia_gold_client.dart b/engine/src/flutter/testing/skia_gold_client/lib/skia_gold_client.dart index b7d23abdb3..b258de044b 100644 --- a/engine/src/flutter/testing/skia_gold_client/lib/skia_gold_client.dart +++ b/engine/src/flutter/testing/skia_gold_client/lib/skia_gold_client.dart @@ -55,9 +55,12 @@ class SkiaGoldClient { String get _keysPath => path.join(workDirectory.path, 'keys.json'); String get _failuresPath => path.join(workDirectory.path, 'failures.json'); - /// Indicates whether the `goldctl` tool has been initialized for the current - /// test context. - bool _isInitialized = false; + Future? _initResult; + Future _initOnce(Future Function() callback) { + // If a call has already been made, return the result of that call. + _initResult ??= callback(); + return _initResult!; + } /// Indicates whether the client has already been authorized to communicate /// with the Skia Gold backend. @@ -121,10 +124,6 @@ class SkiaGoldClient { /// The `imgtest` command collects and uploads test results to the Skia Gold /// backend, the `init` argument initializes the current test. Future _imgtestInit() async { - if (_isInitialized) { - return; - } - final File keys = File(_keysPath); final File failures = File(_failuresPath); @@ -165,7 +164,6 @@ class SkiaGoldClient { ..writeln('stderr: ${result.stderr}'); throw Exception(buf.toString()); } - _isInitialized = true; } /// Executes the `imgtest add` command in the `goldctl` tool. @@ -226,7 +224,7 @@ class SkiaGoldClient { int pixelDeltaThreshold, double maxDifferentPixelsRate, ) async { - await _imgtestInit(); + await _initOnce(_imgtestInit); final List imgtestCommand = [ _goldctl, @@ -253,10 +251,6 @@ class SkiaGoldClient { /// The `imgtest` command collects and uploads test results to the Skia Gold /// backend, the `init` argument initializes the current tryjob. Future _tryjobInit() async { - if (_isInitialized) { - return; - } - final File keys = File(_keysPath); final File failures = File(_failuresPath); @@ -300,7 +294,6 @@ class SkiaGoldClient { ..writeln('stderr: ${result.stderr}'); throw Exception(buf.toString()); } - _isInitialized = true; } /// Executes the `imgtest add` command in the `goldctl` tool for tryjobs. @@ -319,7 +312,7 @@ class SkiaGoldClient { int pixelDeltaThreshold, double differentPixelsRate, ) async { - await _tryjobInit(); + await _initOnce(_tryjobInit); final List tryjobCommand = [ _goldctl,