Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 05154cf

Browse files
HixieBuchimi
authored andcommitted
Remove redundant usages of zones in skia_client.dart (flutter#149366)
The SkiaGoldHttpOverrides don't have any effect since we never build our own HttpClient, it's always passed in. This is part 18 of a broken down version of the flutter#140101 refactor. This particular change is more risky than other changes in this series. While by inspection and some instrumentation testing I'm reasonably sure that my assumptions here are correct, it would behoove us to make sure Skia Gold testing still works post-commit after this lands. To this end, I've included a change to the "inconsequential" test. It should fail the tests. I recommend we land this _with this failure_ to make sure it also fails post-commit, then immediately flag the image as passing and rerun the relevant shard.
1 parent b107b13 commit 05154cf

File tree

3 files changed

+34
-39
lines changed

3 files changed

+34
-39
lines changed

packages/flutter/test/widgets/basic_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ void main() {
750750
// golden file can be approved at any time.
751751
await tester.pumpWidget(RepaintBoundary(
752752
child: Container(
753-
color: const Color(0xFFF40125),
753+
color: const Color(0xFF161145),
754754
),
755755
));
756756

packages/flutter_goldens/lib/flutter_goldens.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool _isMainBranch(String? branch) {
3535

3636
/// Main method that can be used in a `flutter_test_config.dart` file to set
3737
/// [goldenFileComparator] to an instance of [FlutterGoldenFileComparator] that
38-
/// works for the current test. _Which_ FlutterGoldenFileComparator is
38+
/// works for the current test. _Which_ [FlutterGoldenFileComparator] is
3939
/// instantiated is based on the current testing environment.
4040
///
4141
/// When set, the `namePrefix` is prepended to the names of all gold images.
@@ -45,6 +45,12 @@ bool _isMainBranch(String? branch) {
4545
/// tests using `flutter test`. This should not be called when running a test
4646
/// using `flutter run`, as in that environment, the [goldenFileComparator] is a
4747
/// [TrivialComparator].
48+
///
49+
/// An [HttpClient] is created when this method is called. That client is used
50+
/// to communicate with the Skia Gold servers. Any [HttpOverrides] set in this
51+
/// will affect whether this is effective or not. For example, if the current
52+
/// override provides a mock client that always fails, then all calls to gold
53+
/// comparison functions will fail.
4854
Future<void> testExecutable(FutureOr<void> Function() testMain, {String? namePrefix}) async {
4955
assert(
5056
goldenFileComparator is LocalFileComparator,

packages/flutter_goldens/lib/skia_client.dart

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -420,32 +420,28 @@ class SkiaGoldClient {
420420
Future<String?> getExpectationForTest(String testName) async {
421421
late String? expectation;
422422
final String traceID = getTraceID(testName);
423-
await io.HttpOverrides.runWithHttpOverrides<Future<void>>(() async {
424-
final Uri requestForExpectations = Uri.parse(
425-
'https://flutter-gold.skia.org/json/v2/latestpositivedigest/$traceID'
426-
);
427-
late String rawResponse;
428-
try {
429-
final io.HttpClientRequest request = await httpClient.getUrl(requestForExpectations);
430-
final io.HttpClientResponse response = await request.close();
431-
rawResponse = await utf8.decodeStream(response);
432-
final dynamic jsonResponse = json.decode(rawResponse);
433-
if (jsonResponse is! Map<String, dynamic>) {
434-
throw const FormatException('Skia gold expectations do not match expected format.');
435-
}
436-
expectation = jsonResponse['digest'] as String?;
437-
} on FormatException catch (error) {
438-
log(
439-
'Formatting error detected requesting expectations from Flutter Gold.\n'
440-
'error: $error\n'
441-
'url: $requestForExpectations\n'
442-
'response: $rawResponse'
443-
);
444-
rethrow;
445-
}
446-
},
447-
SkiaGoldHttpOverrides(),
423+
final Uri requestForExpectations = Uri.parse(
424+
'https://flutter-gold.skia.org/json/v2/latestpositivedigest/$traceID'
448425
);
426+
late String rawResponse;
427+
try {
428+
final io.HttpClientRequest request = await httpClient.getUrl(requestForExpectations);
429+
final io.HttpClientResponse response = await request.close();
430+
rawResponse = await utf8.decodeStream(response);
431+
final dynamic jsonResponse = json.decode(rawResponse);
432+
if (jsonResponse is! Map<String, dynamic>) {
433+
throw const FormatException('Skia gold expectations do not match expected format.');
434+
}
435+
expectation = jsonResponse['digest'] as String?;
436+
} on FormatException catch (error) {
437+
log(
438+
'Formatting error detected requesting expectations from Flutter Gold.\n'
439+
'error: $error\n'
440+
'url: $requestForExpectations\n'
441+
'response: $rawResponse'
442+
);
443+
rethrow;
444+
}
449445
return expectation;
450446
}
451447

@@ -455,16 +451,12 @@ class SkiaGoldClient {
455451
/// The provided image hash represents an expectation from Flutter Gold.
456452
Future<List<int>>getImageBytes(String imageHash) async {
457453
final List<int> imageBytes = <int>[];
458-
await io.HttpOverrides.runWithHttpOverrides<Future<void>>(() async {
459-
final Uri requestForImage = Uri.parse(
460-
'https://flutter-gold.skia.org/img/images/$imageHash.png',
461-
);
462-
final io.HttpClientRequest request = await httpClient.getUrl(requestForImage);
463-
final io.HttpClientResponse response = await request.close();
464-
await response.forEach((List<int> bytes) => imageBytes.addAll(bytes));
465-
},
466-
SkiaGoldHttpOverrides(),
454+
final Uri requestForImage = Uri.parse(
455+
'https://flutter-gold.skia.org/img/images/$imageHash.png',
467456
);
457+
final io.HttpClientRequest request = await httpClient.getUrl(requestForImage);
458+
final io.HttpClientResponse response = await request.close();
459+
await response.forEach((List<int> bytes) => imageBytes.addAll(bytes));
468460
return imageBytes;
469461
}
470462

@@ -594,6 +586,3 @@ class SkiaGoldClient {
594586
return md5Sum;
595587
}
596588
}
597-
598-
/// Used to make HttpRequests during testing.
599-
class SkiaGoldHttpOverrides extends io.HttpOverrides { }

0 commit comments

Comments
 (0)