Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1ff5495

Browse files
authored
[web] Don't run goldctl init more than once (#41207)
From the logs reported in flutter/flutter#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.
1 parent 775343a commit 1ff5495

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

testing/skia_gold_client/lib/skia_gold_client.dart

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ class SkiaGoldClient {
5555
String get _keysPath => path.join(workDirectory.path, 'keys.json');
5656
String get _failuresPath => path.join(workDirectory.path, 'failures.json');
5757

58-
/// Indicates whether the `goldctl` tool has been initialized for the current
59-
/// test context.
60-
bool _isInitialized = false;
58+
Future<void>? _initResult;
59+
Future<void> _initOnce(Future<void> Function() callback) {
60+
// If a call has already been made, return the result of that call.
61+
_initResult ??= callback();
62+
return _initResult!;
63+
}
6164

6265
/// Indicates whether the client has already been authorized to communicate
6366
/// with the Skia Gold backend.
@@ -121,10 +124,6 @@ class SkiaGoldClient {
121124
/// The `imgtest` command collects and uploads test results to the Skia Gold
122125
/// backend, the `init` argument initializes the current test.
123126
Future<void> _imgtestInit() async {
124-
if (_isInitialized) {
125-
return;
126-
}
127-
128127
final File keys = File(_keysPath);
129128
final File failures = File(_failuresPath);
130129

@@ -165,7 +164,6 @@ class SkiaGoldClient {
165164
..writeln('stderr: ${result.stderr}');
166165
throw Exception(buf.toString());
167166
}
168-
_isInitialized = true;
169167
}
170168

171169
/// Executes the `imgtest add` command in the `goldctl` tool.
@@ -226,7 +224,7 @@ class SkiaGoldClient {
226224
int pixelDeltaThreshold,
227225
double maxDifferentPixelsRate,
228226
) async {
229-
await _imgtestInit();
227+
await _initOnce(_imgtestInit);
230228

231229
final List<String> imgtestCommand = <String>[
232230
_goldctl,
@@ -253,10 +251,6 @@ class SkiaGoldClient {
253251
/// The `imgtest` command collects and uploads test results to the Skia Gold
254252
/// backend, the `init` argument initializes the current tryjob.
255253
Future<void> _tryjobInit() async {
256-
if (_isInitialized) {
257-
return;
258-
}
259-
260254
final File keys = File(_keysPath);
261255
final File failures = File(_failuresPath);
262256

@@ -300,7 +294,6 @@ class SkiaGoldClient {
300294
..writeln('stderr: ${result.stderr}');
301295
throw Exception(buf.toString());
302296
}
303-
_isInitialized = true;
304297
}
305298

306299
/// Executes the `imgtest add` command in the `goldctl` tool for tryjobs.
@@ -319,7 +312,7 @@ class SkiaGoldClient {
319312
int pixelDeltaThreshold,
320313
double differentPixelsRate,
321314
) async {
322-
await _tryjobInit();
315+
await _initOnce(_tryjobInit);
323316

324317
final List<String> tryjobCommand = <String>[
325318
_goldctl,

0 commit comments

Comments
 (0)