From 7a066564f77e36917125cf9d42956b9aaec78342 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 2 Feb 2021 16:00:17 -0800 Subject: [PATCH] [flutter_tools] add build system test for concurrent failures (#75251) --- .../build_system/build_system_test.dart | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart b/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart index def49d672e..0681cdb35d 100644 --- a/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/build_system_test.dart @@ -4,6 +4,8 @@ // @dart = 2.8 +import 'dart:async'; + import 'package:file/memory.dart'; import 'package:file_testing/file_testing.dart'; import 'package:flutter_tools/src/artifacts.dart'; @@ -645,13 +647,49 @@ void main() { expect(thirdResult.outputFiles, isEmpty); }); + testWithoutContext('Build completes all dependencies before failing', () async { + final MemoryFileSystem fileSystem = MemoryFileSystem.test(); + final BuildSystem buildSystem = setUpBuildSystem(fileSystem, FakePlatform( + operatingSystem: 'linux', + numberOfProcessors: 10, // Ensure the tool will process tasks concurrently. + )); + final Completer startB = Completer(); + final Completer startC = Completer(); + final Completer finishB = Completer(); + + final TestTarget a = TestTarget((Environment environment) { + throw StateError('Should not run'); + })..name = 'A'; + final TestTarget b = TestTarget((Environment environment) async { + startB.complete(); + await finishB.future; + throw Exception('1'); + })..name = 'B'; + final TestTarget c = TestTarget((Environment environment) { + startC.complete(); + throw Exception('2'); + })..name = 'C'; + a.dependencies.addAll([b, c]); + + final Future pendingResult = buildSystem.build(a, environment); + await startB.future; + await startC.future; + + finishB.complete(); + + final BuildResult result = await pendingResult; + + expect(result.success, false); + expect(result.exceptions.keys, containsAll(['B', 'C'])); + }); + } -BuildSystem setUpBuildSystem(FileSystem fileSystem) { +BuildSystem setUpBuildSystem(FileSystem fileSystem, [FakePlatform platform]) { return FlutterBuildSystem( fileSystem: fileSystem, logger: BufferLogger.test(), - platform: FakePlatform(operatingSystem: 'linux'), + platform: platform ?? FakePlatform(operatingSystem: 'linux'), ); }