Skip to content

Commit

Permalink
[flutter_tools] add build system test for concurrent failures (flutte…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams authored Feb 3, 2021
1 parent 4c54558 commit 7a06656
Showing 1 changed file with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<void> startB = Completer<void>();
final Completer<void> startC = Completer<void>();
final Completer<void> finishB = Completer<void>();

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(<Target>[b, c]);

final Future<BuildResult> 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(<String>['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'),
);
}

Expand Down

0 comments on commit 7a06656

Please sign in to comment.