Clean up some flutter_tools tests and roll dependencies (#33163)

* Clean up some flutter_tools tests

* Remove arbitrary retry that happens even for fundamental errors, and generally clean up _DevFSHttpWriter.

* Update dependencies (requires fixes; see next commit)

* Fixes for new dependencies.
This commit is contained in:
Ian Hickson
2019-05-22 09:31:37 -07:00
committed by GitHub
parent cb576181e9
commit e5f81e1048
46 changed files with 189 additions and 173 deletions

View File

@@ -171,6 +171,7 @@ void main() {
FileSystem: () => MemoryFileSystem(),
IOSWorkflow: () => MockIosWorkFlow(),
Platform: _kNoColorTerminalPlatform,
OperatingSystemUtils: () => MockOperatingSystemUtils(),
};
testUsingContext('Error on non-existing file', () {
final PrebuiltIOSApp iosApp =
@@ -493,3 +494,5 @@ const String badPlistData = '''
const String plistData = '''
{"CFBundleIdentifier": "fooBundleId"}
''';
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils { }

View File

@@ -95,7 +95,7 @@ void main() {
}
for (String testOs in testPlatforms) {
testUsingContext('AnsiSpinner works for $testOs', () async {
testUsingContext('AnsiSpinner works for $testOs (1)', () async {
bool done = false;
FakeAsync().run((FakeAsync time) {
final AnsiSpinner ansiSpinner = AnsiSpinner(
@@ -131,21 +131,18 @@ void main() {
Stdio: () => mockStdio,
});
testUsingContext('AnsiSpinner works for $testOs', () async {
testUsingContext('AnsiSpinner works for $testOs (2)', () async {
bool done = false;
// We pad the time here so that we have a little slack in terms of the first part of this test
// taking longer to run than we'd like, since we are forced to start the timer before the actual
// stopwatch that we're trying to test. This is an unfortunate possible race condition. If this
// turns out to be flaky, we will need to find another solution.
final Future<void> tenMillisecondsLater = Future<void>.delayed(const Duration(milliseconds: 15));
await FakeAsync().run((FakeAsync time) async {
mockStopwatch = FakeStopwatch();
FakeAsync().run((FakeAsync time) {
final AnsiSpinner ansiSpinner = AnsiSpinner(
timeout: const Duration(milliseconds: 10),
timeout: const Duration(seconds: 2),
)..start();
mockStopwatch.elapsed = const Duration(seconds: 1);
doWhileAsync(time, () => ansiSpinner.ticks < 10); // one second
expect(ansiSpinner.seemsSlow, isFalse);
expect(outputStdout().join('\n'), isNot(contains('This is taking an unexpectedly long time.')));
await tenMillisecondsLater;
mockStopwatch.elapsed = const Duration(seconds: 3);
doWhileAsync(time, () => ansiSpinner.ticks < 30); // three seconds
expect(ansiSpinner.seemsSlow, isTrue);
// Check the 2nd line to verify there's a newline before the warning
@@ -158,6 +155,7 @@ void main() {
}, overrides: <Type, Generator>{
Platform: () => FakePlatform(operatingSystem: testOs),
Stdio: () => mockStdio,
Stopwatch: () => mockStopwatch,
});
testUsingContext('Stdout startProgress on colored terminal for $testOs', () async {

View File

@@ -26,6 +26,10 @@ void main() {
await tools.main(<String>['devices', '--bug-report']);
expect(exitCode, 0);
verify(os.zip(any, argThat(hasPath(matches(r'bugreport_01\.zip')))));
}, overrides: <Type, Generator>{
OperatingSystemUtils: () => MockOperatingSystemUtils(),
});
});
}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils { }

View File

@@ -7,8 +7,8 @@ import 'dart:convert';
import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/vmservice.dart';
import 'package:json_rpc_2/json_rpc_2.dart' as rpc;

View File

@@ -386,16 +386,16 @@ abstract class FlutterTestDriver {
final Future<T> future = callback();
future.timeout(timeout ?? defaultTimeout, onTimeout: () {
print(messages.toString());
_debugPrint(messages.toString());
timeoutExpired = true;
print('$task is taking longer than usual...');
_debugPrint('$task is taking longer than usual...');
return null;
});
return future.catchError((dynamic error) {
if (!timeoutExpired) {
timeoutExpired = true;
print(messages.toString());
_debugPrint(messages.toString());
}
throw error;
}).whenComplete(() => subscription.cancel());

View File

@@ -222,15 +222,42 @@ class MockSimControl extends Mock implements SimControl {
}
}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {
class MockOperatingSystemUtils implements OperatingSystemUtils {
@override
ProcessResult makeExecutable(File file) => null;
@override
File which(String execName) => null;
@override
List<File> whichAll(String execName) => <File>[];
@override
File makePipe(String path) => null;
@override
void zip(Directory data, File zipFile) { }
@override
void unzip(File file, Directory targetDirectory) { }
@override
bool verifyZip(File file) => true;
@override
void unpack(File gzippedTarFile, Directory targetDirectory) { }
@override
bool verifyGzip(File gzippedFile) => true;
@override
String get name => 'fake OS name and version';
@override
String get pathVarSeparator => ';';
@override
Future<int> findFreePort({bool ipv6 = false}) async => 12345;
}
class MockIOSSimulatorUtils extends Mock implements IOSSimulatorUtils {}