Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions testing/skia_gold_client/lib/skia_gold_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ 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;

/// Indicates whether the client has already been authorized to communicate
/// with the Skia Gold backend.
bool get _isAuthorized {
Expand Down Expand Up @@ -121,10 +117,6 @@ class SkiaGoldClient {
/// The `imgtest` command collects and uploads test results to the Skia Gold
/// backend, the `init` argument initializes the current test.
Future<void> _imgtestInit() async {
if (_isInitialized) {
return;
}

final File keys = File(_keysPath);
final File failures = File(_failuresPath);

Expand Down Expand Up @@ -165,7 +157,6 @@ class SkiaGoldClient {
..writeln('stderr: ${result.stderr}');
throw Exception(buf.toString());
}
_isInitialized = true;
}

/// Executes the `imgtest add` command in the `goldctl` tool.
Expand Down Expand Up @@ -226,7 +217,7 @@ class SkiaGoldClient {
int pixelDeltaThreshold,
double maxDifferentPixelsRate,
) async {
await _imgtestInit();
await _callOnce(_imgtestInit);

final List<String> imgtestCommand = <String>[
_goldctl,
Expand All @@ -253,10 +244,6 @@ class SkiaGoldClient {
/// The `imgtest` command collects and uploads test results to the Skia Gold
/// backend, the `init` argument initializes the current tryjob.
Future<void> _tryjobInit() async {
if (_isInitialized) {
return;
}

final File keys = File(_keysPath);
final File failures = File(_failuresPath);

Expand Down Expand Up @@ -300,7 +287,6 @@ class SkiaGoldClient {
..writeln('stderr: ${result.stderr}');
throw Exception(buf.toString());
}
_isInitialized = true;
}

/// Executes the `imgtest add` command in the `goldctl` tool for tryjobs.
Expand All @@ -319,7 +305,7 @@ class SkiaGoldClient {
int pixelDeltaThreshold,
double differentPixelsRate,
) async {
await _tryjobInit();
await _callOnce(_tryjobInit);

final List<String> tryjobCommand = <String>[
_goldctl,
Expand Down Expand Up @@ -495,5 +481,12 @@ class SkiaGoldClient {
}
}

Future<void>? _oneResult;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can make this a global, it needs to be per SkiaGoldClient. We have separate gold clients per suite now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Nice catch! I've been contemplating making it per client instead of global but didn't find a good reason to do that. Totally forgot that we run multiple suites at the same time now.

Future<void> _callOnce(Future<void> Function() callback) async {
// If a call has already been made, return the result of that call.
_oneResult ??= callback();
return _oneResult;
}

/// Used to make HttpRequests during testing.
class SkiaGoldHttpOverrides extends HttpOverrides { }